From: Yu Watanabe Date: Sun, 18 Sep 2022 22:23:30 +0000 (+0900) Subject: sd-device: use faccessat() X-Git-Tag: v252-rc1~142^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5b304c70529ad979548ff761473da63a480cd59f;p=thirdparty%2Fsystemd.git sd-device: use faccessat() No functional changes, just refactoring. --- diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index f5f36694028..96a8ebf6b8e 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1877,28 +1877,29 @@ static int device_sysattrs_read_all_internal(sd_device *device, const char *subd return r; if (subdir) { - _cleanup_free_ char *p = NULL; - - p = path_join(syspath, subdir, "uevent"); - if (!p) - return -ENOMEM; - - if (access(p, F_OK) >= 0) - /* this is a child device, skipping */ - return 0; - if (errno != ENOENT) { - log_device_debug_errno(device, errno, "sd-device: Failed to stat %s, ignoring subdir: %m", p); - return 0; - } - path_dir = path_join(syspath, subdir); if (!path_dir) return -ENOMEM; } dir = opendir(path_dir ?: syspath); - if (!dir) + 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 */ + if (errno != ENOENT) { + log_device_debug_errno(device, errno, + "sd-device: Failed to access %s/uevent, ignoring sub-directory %s: %m", + subdir, subdir); + return 0; + } + } FOREACH_DIRENT_ALL(de, dir, return -errno) { _cleanup_free_ char *p = NULL;