]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: use fstatat()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 18 Sep 2022 22:08:13 +0000 (07:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 19 Sep 2022 09:04:13 +0000 (18:04 +0900)
No functional changes, just refactoring.

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

index f2556ca4bcf0888b50fb0066d02501a0307fadcc..f5f36694028c651028ae1a5ef4e9d89dc818ba02 100644 (file)
@@ -1901,7 +1901,7 @@ static int device_sysattrs_read_all_internal(sd_device *device, const char *subd
                 return -errno;
 
         FOREACH_DIRENT_ALL(de, dir, return -errno) {
-                _cleanup_free_ char *path = NULL, *p = NULL;
+                _cleanup_free_ char *p = NULL;
                 struct stat statbuf;
 
                 if (dot_or_dot_dot(de->d_name))
@@ -1926,11 +1926,7 @@ static int device_sysattrs_read_all_internal(sd_device *device, const char *subd
                         continue;
                 }
 
-                path = path_join(syspath, p ?: de->d_name);
-                if (!path)
-                        return -ENOMEM;
-
-                if (lstat(path, &statbuf) != 0)
+                if (fstatat(dirfd(dir), de->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) < 0)
                         continue;
 
                 if ((statbuf.st_mode & (S_IRUSR | S_IWUSR)) == 0)