diff options
author | Tom Gundersen <teg@jklm.no> | 2015-04-17 14:53:02 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-04-17 14:55:40 +0200 |
commit | 08232a020bd2571088d3ee06dda07732c5e963d1 (patch) | |
tree | 374954858fddeaf31cf23b84f453a52b117ced51 | |
parent | dee5e0b6c29ca22cbf67d28fbee195d70b0dde72 (diff) |
sd-device: uniformly handle missing devices
sd_device_new_from_* now returns -ENODEV when the device does not exist, and the enumerator
silently drops these errors as missing devices is exepected.
-rw-r--r-- | src/libsystemd/sd-device/device-enumerator.c | 14 | ||||
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 18 |
2 files changed, 22 insertions, 10 deletions
diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index 49c44bc47b..d59da7d88f 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -504,8 +504,10 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator, k = sd_device_new_from_syspath(&device, syspath); if (k < 0) { - log_debug_errno(k, "device-enumerator: failed to create device from syspath %s: %m", syspath); - r = k; + if (k != -ENODEV) + /* this is necessarily racey, so ignore missing devices */ + r = k; + continue; } @@ -649,7 +651,10 @@ static int enumerator_scan_devices_tag(sd_device_enumerator *enumerator, const c k = sd_device_new_from_device_id(&device, dent->d_name); if (k < 0) { - r = k; + if (k != -ENODEV) + /* this is necessarily racy, so ignore missing devices */ + r = k; + continue; } @@ -712,7 +717,8 @@ static int parent_add_child(sd_device_enumerator *enumerator, const char *path) int r; r = sd_device_new_from_syspath(&device, path); - if (r == -ENOENT) + if (r == -ENODEV) + /* this is necessarily racy, so ignore missing devices */ return 0; else if (r < 0) return r; diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 9dcb1a892b..2e30b85ad2 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -158,15 +158,21 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { if (verify) { r = readlink_and_canonicalize(_syspath, &syspath); - if (r == -EINVAL) { + if (r == -ENOENT) + /* the device does not exist (any more?) */ + return -ENODEV; + else if (r == -EINVAL) { /* not a symlink */ syspath = canonicalize_file_name(_syspath); if (!syspath) { + if (errno == ENOENT) + /* the device does not exist (any more?) */ + return -ENODEV; + log_debug("sd-device: could not canonicalize '%s': %m", _syspath); return -errno; } - /* ignore errors due to the link not being a symlink */ - } else if (r < 0 && r != -EINVAL) { + } else if (r < 0) { log_debug("sd-device: could not get target of '%s': %s", _syspath, strerror(-r)); return r; } @@ -301,7 +307,7 @@ _public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *s return sd_device_new_from_syspath(ret, syspath); } - return -ENOENT; + return -ENODEV; } int device_set_devtype(sd_device *device, const char *_devtype) { @@ -627,7 +633,7 @@ _public_ int sd_device_new_from_device_id(sd_device **ret, const char *id) { if (r < 0) return r; - /* this si racey, so we might end up with the wrong device */ + /* this is racey, so we might end up with the wrong device */ if (ifr.ifr_ifindex != ifindex) return -ENODEV; @@ -700,7 +706,7 @@ static int device_new_from_child(sd_device **ret, sd_device *child) { return 0; } - return -ENOENT; + return -ENODEV; } _public_ int sd_device_get_parent(sd_device *child, sd_device **ret) { |