]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: generate e better error code when trying to allocate sd_device for non-dir
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Apr 2022 09:42:30 +0000 (11:42 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 13 Apr 2022 12:41:03 +0000 (14:41 +0200)
Currently, for sysfs paths outside of /sys/devices/ we do better
checking if something is a suitable path: we check if it's actually a
directory, and if not return ENODEV.

Let's make the codepath for nodes *inside* of /sys/device/ similar:
let's also return ENODEV if the path supplied is not a directory.

Previously, we'd return ENOTDIR in that case, which is quite confusing I
think.

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

index 0435beca16e1ae28b3beb04b142b3d12735d0f5b..8c1b1194cdafc19730a3b9acfdf706bf1f007ce5 100644 (file)
@@ -196,6 +196,10 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
                                          * Hence, use log_trace_errno() here. */
                                         return log_trace_errno(SYNTHETIC_ERRNO(ENODEV),
                                                                "sd-device: the uevent file \"%s/uevent\" does not exist.", syspath);
+                                if (errno == ENOTDIR)
+                                        /* Not actually a directory. */
+                                        return log_debug_errno(SYNTHETIC_ERRNO(ENODEV),
+                                                               "sd-device: the syspath \"%s\" is not a directory.", syspath);
 
                                 return log_debug_errno(errno, "sd-device: cannot find uevent file for %s: %m", syspath);
                         }