[systemd-commits] 3 commits - src/libsystemd src/libudev src/systemd
Tom Gundersen
tomegun at kemper.freedesktop.org
Fri Apr 17 05:57:44 PDT 2015
src/libsystemd/sd-device/device-enumerator-private.h | 2
src/libsystemd/sd-device/device-enumerator.c | 40 +++++++++++++------
src/libsystemd/sd-device/sd-device.c | 18 +++++---
src/libudev/libudev-enumerate.c | 19 ++++++---
src/systemd/sd-device.h | 4 -
5 files changed, 57 insertions(+), 26 deletions(-)
New commits:
commit 08232a020bd2571088d3ee06dda07732c5e963d1
Author: Tom Gundersen <teg at jklm.no>
Date: Fri Apr 17 14:53:02 2015 +0200
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.
diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c
index 49c44bc..d59da7d 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 9dcb1a8..2e30b85 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) {
commit dee5e0b6c29ca22cbf67d28fbee195d70b0dde72
Author: Tom Gundersen <teg at jklm.no>
Date: Fri Apr 17 14:11:00 2015 +0200
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.
diff --git a/src/libsystemd/sd-device/device-enumerator-private.h b/src/libsystemd/sd-device/device-enumerator-private.h
index 4d0a2d3..8d04640 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 eb637f5..49c44bc 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 1498697..255fbe8 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 86f7670..38cb2a1 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;
commit 19c9df44921bd4788bba608e9d0756f4fb1d5f89
Author: Tom Gundersen <teg at jklm.no>
Date: Fri Apr 17 13:50:10 2015 +0200
sd-device: enumerator - don't expose add_device()
This is rarely, if ever, used. Drop it from the new public API and only keep it for
the legacy API.
Suggested by David Herrmann.
diff --git a/src/libsystemd/sd-device/device-enumerator-private.h b/src/libsystemd/sd-device/device-enumerator-private.h
index 515a60d..4d0a2d3 100644
--- a/src/libsystemd/sd-device/device-enumerator-private.h
+++ b/src/libsystemd/sd-device/device-enumerator-private.h
@@ -25,6 +25,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);
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 37d46e5..eb637f5 100644
--- a/src/libsystemd/sd-device/device-enumerator.c
+++ b/src/libsystemd/sd-device/device-enumerator.c
@@ -317,7 +317,7 @@ static int device_compare(const void *_a, const void *_b) {
return strcmp(devpath_a, devpath_b);
}
-_public_ int sd_device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *device) {
+int device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *device) {
int r;
assert_return(enumerator, -EINVAL);
@@ -544,7 +544,7 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
if (!match_sysattr(enumerator, device))
continue;
- k = sd_device_enumerator_add_device(enumerator, device);
+ k = device_enumerator_add_device(enumerator, device);
if (k < 0)
r = k;
}
@@ -670,7 +670,7 @@ static int enumerator_scan_devices_tag(sd_device_enumerator *enumerator, const c
if (!match_sysattr(enumerator, device))
continue;
- k = sd_device_enumerator_add_device(enumerator, device);
+ k = device_enumerator_add_device(enumerator, device);
if (k < 0) {
r = k;
continue;
@@ -727,7 +727,7 @@ static int parent_add_child(sd_device_enumerator *enumerator, const char *path)
if (!match_sysattr(enumerator, device))
return 0;
- r = sd_device_enumerator_add_device(enumerator, device);
+ r = device_enumerator_add_device(enumerator, device);
if (r < 0)
return r;
diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c
index 290c3da..1498697 100644
--- a/src/libudev/libudev-enumerate.c
+++ b/src/libudev/libudev-enumerate.c
@@ -351,7 +351,7 @@ _public_ int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, c
if (r < 0)
return r;
- r = sd_device_enumerator_add_device(udev_enumerate->enumerator, device);
+ r = device_enumerator_add_device(udev_enumerate->enumerator, device);
if (r < 0)
return r;
diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h
index 5fcd35f..86f7670 100644
--- a/src/systemd/sd-device.h
+++ b/src/systemd/sd-device.h
@@ -81,8 +81,6 @@ int sd_device_enumerator_new(sd_device_enumerator **ret);
sd_device_enumerator *sd_device_enumerator_ref(sd_device_enumerator *enumerator);
sd_device_enumerator *sd_device_enumerator_unref(sd_device_enumerator *enumerator);
-int sd_device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *device);
-
sd_device *sd_device_enumerator_get_device_first(sd_device_enumerator *enumerator);
sd_device *sd_device_enumerator_get_device_next(sd_device_enumerator *enumerator);
sd_device *sd_device_enumerator_get_subsystem_first(sd_device_enumerator *enumerator);
More information about the systemd-commits
mailing list