diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-16 13:51:29 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-16 13:51:29 +0200 |
commit | f183b6ed766a18835d53dc1e36a4e98756ebd0b7 (patch) | |
tree | bc2ce0292461fbe96ebd92542dfa5b94dcc412a6 /udev/lib | |
parent | 6a95b1e7d6290293061e551eac679aee9ea21611 (diff) |
libudev: add global property list
Diffstat (limited to 'udev/lib')
-rw-r--r-- | udev/lib/libudev-private.h | 2 | ||||
-rw-r--r-- | udev/lib/libudev.c | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/udev/lib/libudev-private.h b/udev/lib/libudev-private.h index e9f2c9893b..60d995aa78 100644 --- a/udev/lib/libudev-private.h +++ b/udev/lib/libudev-private.h @@ -50,6 +50,8 @@ void udev_log(struct udev *udev, extern struct udev_device *device_new(struct udev *udev); extern const char *udev_get_rules_path(struct udev *udev); extern int udev_get_run(struct udev *udev); +extern struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value); +extern struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev); /* libudev-device */ extern int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath); diff --git a/udev/lib/libudev.c b/udev/lib/libudev.c index 3f7d0e547e..c698be6e46 100644 --- a/udev/lib/libudev.c +++ b/udev/lib/libudev.c @@ -38,6 +38,7 @@ struct udev { char *sys_path; char *dev_path; char *rules_path; + struct udev_list_node properties_list; int log_priority; int run; }; @@ -102,6 +103,7 @@ struct udev *udev_new(void) udev->refcount = 1; udev->log_fn = log_stderr; udev->log_priority = LOG_ERR; + udev_list_init(&udev->properties_list); udev->run = 1; udev->dev_path = strdup(UDEV_PREFIX "/dev"); udev->sys_path = strdup("/sys"); @@ -117,6 +119,7 @@ struct udev *udev_new(void) free(udev->sys_path); udev->sys_path = strdup(env); util_remove_trailing_chars(udev->sys_path, '/'); + udev_add_property(udev, "SYSFS_PATH", udev->sys_path); } env = getenv("UDEV_RUN"); @@ -219,11 +222,12 @@ struct udev *udev_new(void) free(udev->dev_path); udev->dev_path = strdup(env); util_remove_trailing_chars(udev->dev_path, '/'); + udev_add_property(udev, "UDEV_ROOT", udev->dev_path); } env = getenv("UDEV_LOG"); if (env != NULL) - udev->log_priority = util_log_priority(env); + udev_set_log_priority(udev, util_log_priority(env)); if (udev->dev_path == NULL || udev->sys_path == NULL) goto err; @@ -274,6 +278,7 @@ void udev_unref(struct udev *udev) udev->refcount--; if (udev->refcount > 0) return; + udev_list_cleanup(udev, &udev->properties_list); free(udev->dev_path); free(udev->sys_path); free(udev->rules_path); @@ -307,7 +312,11 @@ int udev_get_log_priority(struct udev *udev) void udev_set_log_priority(struct udev *udev, int priority) { + char num[32]; + udev->log_priority = priority; + snprintf(num, sizeof(num), "%u", udev->log_priority); + udev_add_property(udev, "UDEV_LOG", num); } const char *udev_get_rules_path(struct udev *udev) @@ -353,3 +362,22 @@ const char *udev_get_dev_path(struct udev *udev) return NULL; return udev->dev_path; } + +struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, const char *value) +{ + if (value == NULL) { + struct udev_list_entry *list_entry; + + list_entry = udev_get_properties_list_entry(udev); + list_entry = udev_list_entry_get_by_name(list_entry, key); + if (list_entry != NULL) + udev_list_entry_remove(list_entry); + return NULL; + } + return udev_list_entry_add(udev, &udev->properties_list, key, value, 1, 0); +} + +struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev) +{ + return udev_list_get_entry(&udev->properties_list); +} |