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
#include "libudev.h"
#include "libudev-private.h"
+static int devices_sort(struct udev_enumerate *udev_enumerate);
+
struct udev_enumerate {
struct udev *udev;
int refcount;
struct list_node subsystem_match_list;
struct list_node subsystem_nomatch_list;
struct list_node devices_list;
+ int devices_sorted;
};
/**
{
if (udev_enumerate == NULL)
return NULL;
+ if (!udev_enumerate->devices_sorted)
+ devices_sort(udev_enumerate);
return list_get_entry(&udev_enumerate->devices_list);
}
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;
}
* @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.
*
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);
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);
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;
}