]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: use device_opendir()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 18 Sep 2022 22:08:59 +0000 (07:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 19 Sep 2022 10:42:36 +0000 (19:42 +0900)
src/libsystemd/sd-device/sd-device.c

index 7a5403be6fcd71a52540e4bb0ec6851d11bc43d7..7e3d5eeae121eede5f77046bd1cb620508ad4391 100644 (file)
@@ -1867,32 +1867,18 @@ _public_ const char *sd_device_get_property_next(sd_device *device, const char *
 }
 
 static int device_sysattrs_read_all_internal(sd_device *device, const char *subdir, Set **stack) {
-        _cleanup_free_ char *path_dir = NULL;
         _cleanup_closedir_ DIR *dir = NULL;
-        const char *syspath;
         int r;
 
         assert(device);
         assert(stack);
 
-        r = sd_device_get_syspath(device, &syspath);
+        r = device_opendir(device, subdir, &dir);
+        if (r == -ENOENT && subdir)
+                return 0; /* Maybe, this is a child device, and is already removed. */
         if (r < 0)
                 return r;
 
-        if (subdir) {
-                path_dir = path_join(syspath, subdir);
-                if (!path_dir)
-                        return -ENOMEM;
-        }
-
-        dir = opendir(path_dir ?: syspath);
-        if (!dir) {
-                if (errno == ENOENT && subdir)
-                        return 0; /* Maybe, this is a child device, and is already removed. */
-
-                return -errno;
-        }
-
         if (subdir) {
                 if (faccessat(dirfd(dir), "uevent", F_OK, 0) >= 0)
                         return 0; /* this is a child device, skipping */