diff options
-rw-r--r-- | src/libsystemd/sd-device/device-enumerator-private.h | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-device/device-enumerator.c | 18 | ||||
-rw-r--r-- | src/libudev/libudev-enumerate.c | 17 | ||||
-rw-r--r-- | src/systemd/sd-device.h | 2 |
4 files changed, 29 insertions, 9 deletions
diff --git a/src/libsystemd/sd-device/device-enumerator-private.h b/src/libsystemd/sd-device/device-enumerator-private.h index 4d0a2d3c79..8d04640dc7 100644 --- a/src/libsystemd/sd-device/device-enumerator-private.h +++ b/src/libsystemd/sd-device/device-enumerator-private.h @@ -26,6 +26,7 @@ int device_enumerator_scan_devices(sd_device_enumerator *enumeartor); int device_enumerator_scan_subsystems(sd_device_enumerator *enumeartor); int device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *device); +int device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator); sd_device *device_enumerator_get_first(sd_device_enumerator *enumerator); sd_device *device_enumerator_get_next(sd_device_enumerator *enumerator); diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index eb637f5a57..49c44bc47b 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -52,7 +52,7 @@ struct sd_device_enumerator { Set *match_sysname; Set *match_tag; sd_device *match_parent; - bool match_is_initialized; + bool match_allow_uninitialized; }; _public_ int sd_device_enumerator_new(sd_device_enumerator **ret) { @@ -250,10 +250,20 @@ _public_ int sd_device_enumerator_add_match_parent(sd_device_enumerator *enumera return 0; } -_public_ int sd_device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator) { +_public_ int sd_device_enumerator_allow_uninitialized(sd_device_enumerator *enumerator) { assert_return(enumerator, -EINVAL); - enumerator->match_is_initialized = true; + enumerator->match_allow_uninitialized = true; + + enumerator->scan_uptodate = false; + + return 0; +} + +int device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator) { + assert_return(enumerator, -EINVAL); + + enumerator->match_allow_uninitialized = false; enumerator->scan_uptodate = false; @@ -527,7 +537,7 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator, * might not store a database, and have no way to find out * for all other types of devices. */ - if (enumerator->match_is_initialized && + if (!enumerator->match_allow_uninitialized && !initialized && (major(devnum) > 0 || ifindex > 0)) continue; diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c index 1498697d7b..255fbe808d 100644 --- a/src/libudev/libudev-enumerate.c +++ b/src/libudev/libudev-enumerate.c @@ -66,7 +66,8 @@ struct udev_enumerate { * Returns: an enumeration context. **/ _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev) { - struct udev_enumerate *udev_enumerate; + _cleanup_free_ struct udev_enumerate *udev_enumerate = NULL; + struct udev_enumerate *ret; int r; assert_return_errno(udev, NULL, EINVAL); @@ -79,7 +80,12 @@ _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev) { r = sd_device_enumerator_new(&udev_enumerate->enumerator); if (r < 0) { - free(udev_enumerate); + errno = -r; + return NULL; + } + + r = sd_device_enumerator_allow_uninitialized(udev_enumerate->enumerator); + if (r < 0) { errno = -r; return NULL; } @@ -89,7 +95,10 @@ _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev) { udev_list_init(udev, &udev_enumerate->devices_list, false); - return udev_enumerate; + ret = udev_enumerate; + udev_enumerate = NULL; + + return ret; } /** @@ -311,7 +320,7 @@ _public_ int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumera _public_ int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate) { assert_return(udev_enumerate, -EINVAL); - return sd_device_enumerator_add_match_is_initialized(udev_enumerate->enumerator); + return device_enumerator_add_match_is_initialized(udev_enumerate->enumerator); } /** diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h index 86f767054c..38cb2a1102 100644 --- a/src/systemd/sd-device.h +++ b/src/systemd/sd-device.h @@ -92,7 +92,7 @@ int sd_device_enumerator_add_match_property(sd_device_enumerator *enumerator, co int sd_device_enumerator_add_match_sysname(sd_device_enumerator *enumerator, const char *sysname); int sd_device_enumerator_add_match_tag(sd_device_enumerator *enumerator, const char *tag); int sd_device_enumerator_add_match_parent(sd_device_enumerator *enumerator, sd_device *parent); -int sd_device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator); +int sd_device_enumerator_allow_uninitialized(sd_device_enumerator *enumerator); _SD_END_DECLARATIONS; |