X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flibudev%2Flibudev-enumerate.c;h=48ffe83d364359204fdb575714a45dd077a3410f;hp=2c1f7ab4ace4d3cfc7cf5618afef6bb340742f8b;hb=051dfe8708e394a64e8ef6c281228763481ad32c;hpb=d5a89d7dc17a5ba5cf4fc71f82963c5c94a31c3d diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 2c1f7ab4a..48ffe83d3 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -122,7 +122,7 @@ _public_ struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_e * Drop a reference of an enumeration context. If the refcount reaches zero, * all resources of the enumeration context will be released. * - * Returns: the passed enumeration context if it has still an active reference, or #NULL otherwise. + * Returns: #NULL **/ _public_ struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate) { @@ -132,7 +132,7 @@ _public_ struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev return NULL; udev_enumerate->refcount--; if (udev_enumerate->refcount > 0) - return udev_enumerate; + return NULL; udev_list_cleanup(&udev_enumerate->sysattr_match_list); udev_list_cleanup(&udev_enumerate->sysattr_nomatch_list); udev_list_cleanup(&udev_enumerate->subsystem_match_list); @@ -270,12 +270,13 @@ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enume return NULL; if (!udev_enumerate->devices_uptodate) { unsigned int i; + int move_later = -1; unsigned int max; - struct syspath *prev = NULL, *move_later = NULL; + struct syspath *prev = NULL; size_t move_later_prefix = 0; udev_list_cleanup(&udev_enumerate->devices_list); - qsort(udev_enumerate->devices, udev_enumerate->devices_cur, sizeof(struct syspath), syspath_cmp); + qsort_safe(udev_enumerate->devices, udev_enumerate->devices_cur, sizeof(struct syspath), syspath_cmp); max = udev_enumerate->devices_cur; for (i = 0; i < max; i++) { @@ -299,27 +300,29 @@ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enume /* skip to be delayed devices, and move the to * the point where the prefix changes. We can * only move one item at a time. */ - if (!move_later) { + if (move_later == -1) { move_later_prefix = devices_delay_later(udev_enumerate->udev, entry->syspath); if (move_later_prefix > 0) { - move_later = entry; + move_later = i; continue; } } - if (move_later && - strncmp(entry->syspath, move_later->syspath, move_later_prefix) != 0) { + if ((move_later >= 0) && + !strneq(entry->syspath, udev_enumerate->devices[move_later].syspath, move_later_prefix)) { - udev_list_entry_add(&udev_enumerate->devices_list, move_later->syspath, NULL); - move_later = NULL; + udev_list_entry_add(&udev_enumerate->devices_list, + udev_enumerate->devices[move_later].syspath, NULL); + move_later = -1; } udev_list_entry_add(&udev_enumerate->devices_list, entry->syspath, NULL); } - if (move_later) - udev_list_entry_add(&udev_enumerate->devices_list, move_later->syspath, NULL); + if (move_later >= 0) + udev_list_entry_add(&udev_enumerate->devices_list, + udev_enumerate->devices[move_later].syspath, NULL); /* add and cleanup delayed devices from end of list */ for (i = max; i < udev_enumerate->devices_cur; i++) { @@ -718,10 +721,14 @@ static bool match_subsystem(struct udev_enumerate *udev_enumerate, const char *s { struct udev_list_entry *list_entry; + if (!subsystem) + return false; + udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->subsystem_nomatch_list)) { if (fnmatch(udev_list_entry_get_name(list_entry), subsystem, 0) == 0) return false; } + if (udev_list_get_entry(&udev_enumerate->subsystem_match_list) != NULL) { udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->subsystem_match_list)) { if (fnmatch(udev_list_entry_get_name(list_entry), subsystem, 0) == 0) @@ -729,6 +736,7 @@ static bool match_subsystem(struct udev_enumerate *udev_enumerate, const char *s } return false; } + return true; } @@ -826,23 +834,27 @@ nomatch: static int parent_add_child(struct udev_enumerate *enumerate, const char *path) { struct udev_device *dev; + int r = 0; dev = udev_device_new_from_syspath(enumerate->udev, path); if (dev == NULL) return -ENODEV; if (!match_subsystem(enumerate, udev_device_get_subsystem(dev))) - return 0; + goto nomatch; if (!match_sysname(enumerate, udev_device_get_sysname(dev))) - return 0; + goto nomatch; if (!match_property(enumerate, dev)) - return 0; + goto nomatch; if (!match_sysattr(enumerate, dev)) - return 0; + goto nomatch; syspath_add(enumerate, udev_device_get_syspath(dev)); + r = 1; + +nomatch: udev_device_unref(dev); - return 1; + return r; } static int parent_crawl_children(struct udev_enumerate *enumerate, const char *path, int maxdepth)