diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-04-05 10:17:22 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-04-11 16:25:48 +0200 |
commit | 09c24f76dce5f606056d916207676f2a93157deb (patch) | |
tree | 7dcb0181410a9e12140b69dd3359f94a779d7657 /src/libsystemd/sd-device/device-enumerator.c | |
parent | timedate: update to use new-style sd-bus macros (diff) | |
download | systemd-09c24f76dce5f606056d916207676f2a93157deb.tar.xz systemd-09c24f76dce5f606056d916207676f2a93157deb.zip |
sd-device: simplify device_enumerator_scan_devices_and_subsystems() a bit
We can use enumerator_scan_devices_all() to shorten the code, and drop
some of the error handling complexities.
Diffstat (limited to '')
-rw-r--r-- | src/libsystemd/sd-device/device-enumerator.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index 14794fb3af..61645f44d8 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -638,7 +638,12 @@ static bool match_subsystem(sd_device_enumerator *enumerator, const char *subsys return false; } -static int enumerator_scan_dir(sd_device_enumerator *enumerator, const char *basedir, const char *subdir, const char *subsystem) { +static int enumerator_scan_dir( + sd_device_enumerator *enumerator, + const char *basedir, + const char *subdir, + const char *subsystem) { + _cleanup_closedir_ DIR *dir = NULL; char *path; int r = 0; @@ -997,7 +1002,7 @@ _public_ sd_device *sd_device_enumerator_get_subsystem_next(sd_device_enumerator } int device_enumerator_scan_devices_and_subsystems(sd_device_enumerator *enumerator) { - int r = 0, k; + int r; assert(enumerator); @@ -1007,22 +1012,14 @@ int device_enumerator_scan_devices_and_subsystems(sd_device_enumerator *enumerat device_enumerator_unref_devices(enumerator); - if (!set_isempty(enumerator->match_tag)) { - k = enumerator_scan_devices_tags(enumerator); - if (k < 0) - r = k; - } else if (enumerator->match_parent) { - k = enumerator_scan_devices_children(enumerator); - if (k < 0) - r = k; - } else { - k = enumerator_scan_dir(enumerator, "class", NULL, NULL); - if (k < 0) - r = log_debug_errno(k, "sd-device-enumerator: Failed to scan /sys/class: %m"); + if (!set_isempty(enumerator->match_tag)) + r = enumerator_scan_devices_tags(enumerator); + else if (enumerator->match_parent) + r = enumerator_scan_devices_children(enumerator); + else { + int k; - k = enumerator_scan_dir(enumerator, "bus", "devices", NULL); - if (k < 0) - r = log_debug_errno(k, "sd-device-enumerator: Failed to scan /sys/bus: %m"); + r = enumerator_scan_devices_all(enumerator); if (match_subsystem(enumerator, "module")) { k = enumerator_scan_dir_and_add_devices(enumerator, "module", NULL, NULL); |