summaryrefslogtreecommitdiff
path: root/udev/lib
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2008-10-02 11:54:33 +0200
committerKay Sievers <kay.sievers@vrfy.org>2008-10-02 11:54:33 +0200
commit13ddea815496b32bd0ae0a648cdc50af28d69bb1 (patch)
treeb8737fbc7b0afa6d6dd2db474c7380f88497f40d /udev/lib
parentd6b148cde2a8ca6dc32af2e1d95824ac3be926db (diff)
libudev: enumerate - add_device() -> add_syspath()
Diffstat (limited to 'udev/lib')
-rw-r--r--udev/lib/exported_symbols2
-rw-r--r--udev/lib/libudev-enumerate.c37
-rw-r--r--udev/lib/libudev.c3
-rw-r--r--udev/lib/libudev.h2
-rw-r--r--udev/lib/test-libudev.c8
5 files changed, 32 insertions, 20 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);