]> err.no Git - systemd/commitdiff
libudev: enumerate - add_device() -> add_syspath()
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 2 Oct 2008 09:54:33 +0000 (11:54 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Thu, 2 Oct 2008 09:54:33 +0000 (11:54 +0200)
udev/lib/exported_symbols
udev/lib/libudev-enumerate.c
udev/lib/libudev.c
udev/lib/libudev.h
udev/lib/test-libudev.c
udev/udevadm-trigger.c

index 81abb58d647e68e6157f809de6343fc6ee596cde..ffd8d66acdd5d708a6fdb9a12d39a21e0445e592 100644 (file)
@@ -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
index 7d2d592c92d1b6345591938a25d3ea4ada31d99b..9fb154418d45741650be9d9a66e9235611b81356 100644 (file)
@@ -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;
 }
 
index 12220e7a782aad29efdf9624cdd62c6bd4f47f19..c2c5025b9eb0d170e7e6536771a967862bccadc3 100644 (file)
@@ -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.
  *
index cc6939c02f4308b1f278ddb306122ae48d35ee08..fec05d4476d3c9c6e258d46283c662e63aa712d6 100644 (file)
@@ -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);
index 7291e8c89a58160cc3436796e21e5652151f2efe..5d19d5dd75b0110779a072085028d97ea183d914 100644 (file)
@@ -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);
index 2c4954761ee9f940c045c0859d106e137235e332..8d25f923995bfa66733c4bddc41cc2e05c935cf1 100644 (file)
@@ -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;
 }