]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: use ERRNO_IS_NEG_DEVICE_ABSENT() for device-id load failures (#41764)
author我超厉害 <524413304@qq.com>
Thu, 14 May 2026 17:51:29 +0000 (01:51 +0800)
committerGitHub <noreply@github.com>
Thu, 14 May 2026 17:51:29 +0000 (02:51 +0900)
Device enumeration may encounter transient errors such as ENXIO when devices
appear or disappear concurrently. These conditions represent expected "device absent"
races and should be treated uniformly across the enumeration logic.

This change replaces the ENODEV-specific check with ERRNO_IS_NEG_DEVICE_ABSENT(),
ensuring that all expected disappearance conditions are handled consistently.
Unexpected errors are still propagated, while expected races are ignored without
aborting the enumeration.

src/libsystemd/sd-device/device-enumerator.c

index d1a48defe906c844e2b8df062413ba008fea169a..6c1e79edd588cf1108dd4e9643f1d5ccc0641a42 100644 (file)
@@ -9,6 +9,7 @@
 #include "device-filter.h"
 #include "device-util.h"
 #include "dirent-util.h"
+#include "errno-util.h"
 #include "fd-util.h"
 #include "log.h"
 #include "path-util.h"
@@ -741,7 +742,7 @@ static int enumerator_scan_dir_and_add_devices(
 
                 k = sd_device_new_from_syspath(&device, syspath);
                 if (k < 0) {
-                        if (k != -ENODEV)
+                        if (!ERRNO_IS_NEG_DEVICE_ABSENT(k))
                                 /* this is necessarily racey, so ignore missing devices */
                                 r = k;
 
@@ -836,7 +837,7 @@ static int enumerator_scan_devices_tag(sd_device_enumerator *enumerator, const c
 
                 k = sd_device_new_from_device_id(&device, de->d_name);
                 if (k < 0) {
-                        if (k != -ENODEV)
+                        if (!ERRNO_IS_NEG_DEVICE_ABSENT(k))
                                 /* this is necessarily racy, so ignore missing devices */
                                 r = k;
 
@@ -882,7 +883,7 @@ static int parent_add_child(sd_device_enumerator *enumerator, const char *path,
         int r;
 
         r = sd_device_new_from_syspath(&device, path);
-        if (r == -ENODEV)
+        if (ERRNO_IS_NEG_DEVICE_ABSENT(r))
                 /* this is necessarily racy, so ignore missing devices */
                 return 0;
         else if (r < 0)