diff options
author | Tom Gundersen <teg@jklm.no> | 2015-04-17 14:11:00 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-04-17 14:16:16 +0200 |
commit | dee5e0b6c29ca22cbf67d28fbee195d70b0dde72 (patch) | |
tree | 9b168fad51bc28c0e12efcc4847eb5293eddad2e /src/libudev/libudev-enumerate.c | |
parent | 19c9df44921bd4788bba608e9d0756f4fb1d5f89 (diff) |
sd-device: enumerator - match only on initialized devices by default
It is still possible to include uninitialized ones, but now that is opt-in. In most
cases people only want initialized devices. Exception is if you want to work without
udev running.
Suggested by David Herrmann.
Diffstat (limited to 'src/libudev/libudev-enumerate.c')
-rw-r--r-- | src/libudev/libudev-enumerate.c | 17 |
1 files changed, 13 insertions, 4 deletions
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); } /** |