diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-02 11:54:33 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-02 11:54:33 +0200 |
commit | 13ddea815496b32bd0ae0a648cdc50af28d69bb1 (patch) | |
tree | b8737fbc7b0afa6d6dd2db474c7380f88497f40d | |
parent | d6b148cde2a8ca6dc32af2e1d95824ac3be926db (diff) |
libudev: enumerate - add_device() -> add_syspath()
-rw-r--r-- | udev/lib/exported_symbols | 2 | ||||
-rw-r--r-- | udev/lib/libudev-enumerate.c | 37 | ||||
-rw-r--r-- | udev/lib/libudev.c | 3 | ||||
-rw-r--r-- | udev/lib/libudev.h | 2 | ||||
-rw-r--r-- | udev/lib/test-libudev.c | 8 | ||||
-rw-r--r-- | udev/udevadm-trigger.c | 12 |
6 files changed, 34 insertions, 30 deletions
diff --git a/udev/lib/exported_symbols b/udev/lib/exported_symbols index 81abb58d64..ffd8d66acd 100644 --- a/udev/lib/exported_symbols +++ b/udev/lib/exported_symbols @@ -42,7 +42,7 @@ udev_enumerate_add_match_attr udev_enumerate_add_nomatch_attr udev_enumerate_scan_devices udev_enumerate_scan_subsystems -udev_enumerate_add_device +udev_enumerate_add_syspath udev_monitor_new_from_socket udev_monitor_new_from_netlink udev_monitor_enable_receiving diff --git a/udev/lib/libudev-enumerate.c b/udev/lib/libudev-enumerate.c index 7d2d592c92..9fb154418d 100644 --- a/udev/lib/libudev-enumerate.c +++ b/udev/lib/libudev-enumerate.c @@ -30,6 +30,8 @@ #include "libudev.h" #include "libudev-private.h" +static int devices_sort(struct udev_enumerate *udev_enumerate); + struct udev_enumerate { struct udev *udev; int refcount; @@ -38,6 +40,7 @@ struct udev_enumerate { struct list_node subsystem_match_list; struct list_node subsystem_nomatch_list; struct list_node devices_list; + int devices_sorted; }; /** @@ -98,6 +101,8 @@ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *ude { if (udev_enumerate == NULL) return NULL; + if (!udev_enumerate->devices_sorted) + devices_sort(udev_enumerate); return list_get_entry(&udev_enumerate->devices_list); } @@ -313,23 +318,35 @@ static int devices_delay(struct udev *udev, const char *syspath) return 0; } -int udev_enumerate_add_device(struct udev_enumerate *udev_enumerate, struct udev_device *udev_device) +/* sort delayed devices to the end of the list */ +static int devices_sort(struct udev_enumerate *udev_enumerate) { - struct udev *udev = udev_enumerate_get_udev(udev_enumerate); struct udev_list_entry *list_entry; + udev_list_entry_foreach(list_entry, list_get_entry(&udev_enumerate->devices_list)) { + if (devices_delay(udev_enumerate->udev, udev_list_entry_get_name(list_entry))) + list_entry_move_to_end(list_entry); + } + udev_enumerate->devices_sorted = 1; + return 0; +} + +int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath) +{ + struct udev *udev = udev_enumerate_get_udev(udev_enumerate); + struct udev_device *udev_device; + if (udev_enumerate == NULL) return -EINVAL; - if (udev_device == NULL) + if (syspath == NULL) return 0; - list_entry_add(udev, - &udev_enumerate->devices_list, + /* resolve to real syspath */ + udev_device = udev_device_new_from_syspath(udev_enumerate->udev, syspath); + if (udev_device == NULL) + return -EINVAL; + list_entry_add(udev, &udev_enumerate->devices_list, udev_device_get_syspath(udev_device), NULL, 1, 1); - /* sort delayed devices to the end of the list */ - udev_list_entry_foreach(list_entry, list_get_entry(&udev_enumerate->devices_list)) { - if (devices_delay(udev, udev_list_entry_get_name(list_entry))) - list_entry_move_to_end(list_entry); - } + udev_device_unref(udev_device); return 0; } diff --git a/udev/lib/libudev.c b/udev/lib/libudev.c index 12220e7a78..c2c5025b9e 100644 --- a/udev/lib/libudev.c +++ b/udev/lib/libudev.c @@ -377,8 +377,7 @@ void udev_unref(struct udev *udev) * @udev: udev library context * @log_fn: function to be called for logging messages * - * The built-in logging, which writes to stderr if the - * LIBUDEV_DEBUG environment variable is set, can be + * The built-in logging, which writes to stderr, it can be * overridden by a custom function, to plug log messages * into the users logging functionality. * diff --git a/udev/lib/libudev.h b/udev/lib/libudev.h index cc6939c02f..fec05d4476 100644 --- a/udev/lib/libudev.h +++ b/udev/lib/libudev.h @@ -102,7 +102,7 @@ extern int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumer extern int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); extern int udev_enumerate_add_match_attr(struct udev_enumerate *udev_enumerate, const char *attr, const char *value); extern int udev_enumerate_add_nomatch_attr(struct udev_enumerate *udev_enumerate, const char *attr, const char *value); -extern int udev_enumerate_add_device(struct udev_enumerate *udev_enumerate, struct udev_device *udev_device); +extern int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath); extern int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate); extern int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate); extern struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate); diff --git a/udev/lib/test-libudev.c b/udev/lib/test-libudev.c index 7291e8c89a..5d19d5dd75 100644 --- a/udev/lib/test-libudev.c +++ b/udev/lib/test-libudev.c @@ -73,23 +73,19 @@ static void print_device(struct udev_device *device) printf("devnum: %u:%u\n", major(devnum), minor(devnum)); count = 0; - list_entry = udev_device_get_devlinks_list_entry(device); - while (list_entry != NULL) { + udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) { printf("link: '%s'\n", udev_list_entry_get_name(list_entry)); count++; - list_entry = udev_list_entry_get_next(list_entry); } if (count > 0) printf("found %i links\n", count); count = 0; - list_entry = udev_device_get_properties_list_entry(device); - while (list_entry != NULL) { + udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device)) { printf("property: '%s=%s'\n", udev_list_entry_get_name(list_entry), udev_list_entry_get_value(list_entry)); count++; - list_entry = udev_list_entry_get_next(list_entry); } if (count > 0) printf("found %i properties\n", count); diff --git a/udev/udevadm-trigger.c b/udev/udevadm-trigger.c index 2c4954761e..8d25f92399 100644 --- a/udev/udevadm-trigger.c +++ b/udev/udevadm-trigger.c @@ -71,16 +71,8 @@ static int scan_failed(struct udev_enumerate *udev_enumerate) udev_queue = udev_queue_new(udev); if (udev_queue == NULL) return -1; - udev_list_entry_foreach(list_entry, udev_queue_get_failed_list_entry(udev_queue)) { - struct udev_device *device; - - device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry)); - if (device == NULL) - continue; - info(udev, "add '%s'\n", udev_device_get_syspath(device)); - udev_enumerate_add_device(udev_enumerate, device); - udev_device_unref(device); - } + udev_list_entry_foreach(list_entry, udev_queue_get_failed_list_entry(udev_queue)) + udev_enumerate_add_syspath(udev_enumerate, udev_list_entry_get_name(list_entry)); return 0; } |