tree-wide: make FOREACH_DIRENT_ALL define the iterator variable

The variable is not useful outside of the loop (it'll always be null
after the loop is finished), so we can declare it inline in the loop.
This saves one variable declaration and reduces the chances that somebody
tries to use the variable outside of the loop.

For consistency, 'de' is used everywhere for the var name.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-12-15 16:19:13 +01:00
parent 372e8592c6
commit c7f0d9e5ac
31 changed files with 71 additions and 116 deletions
-2
View File
@@ -199,8 +199,6 @@ int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d) {
}
int cg_read_subgroup(DIR *d, char **fn) {
struct dirent *de;
assert(d);
assert(fn);
+1 -1
View File
@@ -26,7 +26,7 @@ struct dirent *readdir_no_dot(DIR *dirp);
else
#define FOREACH_DIRENT_ALL(de, d, on_error) \
for (de = readdir_ensure_type(d);; de = readdir_ensure_type(d)) \
for (struct dirent *(de) = readdir_ensure_type(d);; (de) = readdir_ensure_type(d)) \
if (!de) { \
if (errno > 0) { \
on_error; \
-1
View File
@@ -533,7 +533,6 @@ int mkfifoat_atomic(int dirfd, const char *path, mode_t mode) {
int get_files_in_directory(const char *path, char ***list) {
_cleanup_strv_free_ char **l = NULL;
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
size_t n = 0;
assert(path);
-1
View File
@@ -276,7 +276,6 @@ int unit_file_build_name_map(
STRV_FOREACH(dir, (char**) lp->search_path) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
d = opendir(*dir);
if (!d) {
+1 -3
View File
@@ -287,7 +287,6 @@ static void manager_print_jobs_in_progress(Manager *m) {
static int have_ask_password(void) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *de;
dir = opendir("/run/systemd/ask-password");
if (!dir) {
@@ -297,10 +296,9 @@ static int have_ask_password(void) {
return -errno;
}
FOREACH_DIRENT_ALL(de, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno)
if (startswith(de->d_name, "ask."))
return true;
}
return false;
}
-1
View File
@@ -290,7 +290,6 @@ static int enumerate_dir(
const char *path, bool dropins) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
_cleanup_strv_free_ char **files = NULL, **dirs = NULL;
size_t n_files = 0, n_dirs = 0;
char **t;
+6 -6
View File
@@ -159,7 +159,7 @@ int import_fork_tar_c(const char *path, pid_t *ret) {
int import_mangle_os_tree(const char *path) {
_cleanup_free_ char *child = NULL, *t = NULL, *joined = NULL;
_cleanup_closedir_ DIR *d = NULL, *cd = NULL;
struct dirent *de;
struct dirent *dent;
struct stat st;
int r;
@@ -183,8 +183,8 @@ int import_mangle_os_tree(const char *path) {
return log_error_errno(r, "Failed to open directory '%s': %m", path);
errno = 0;
de = readdir_no_dot(d);
if (!de) {
dent = readdir_no_dot(d);
if (!dent) {
if (errno != 0)
return log_error_errno(errno, "Failed to iterate through directory '%s': %m", path);
@@ -192,13 +192,13 @@ int import_mangle_os_tree(const char *path) {
return 0;
}
child = strdup(de->d_name);
child = strdup(dent->d_name);
if (!child)
return log_oom();
errno = 0;
de = readdir_no_dot(d);
if (de) {
dent = readdir_no_dot(d);
if (dent) {
if (errno != 0)
return log_error_errno(errno, "Failed to iterate through directory '%s': %m", path);
-1
View File
@@ -59,7 +59,6 @@ int pull_find_old_etags(
}
_cleanup_strv_free_ char **ans = NULL;
struct dirent *de;
FOREACH_DIRENT_ALL(de, d, return -errno) {
_cleanup_free_ char *u = NULL;
-1
View File
@@ -90,7 +90,6 @@ static int determine_path_usage(
uint64_t *ret_free) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
struct statvfs ss;
assert(s);
+16 -20
View File
@@ -350,7 +350,6 @@ static bool match_sysname(sd_device_enumerator *enumerator, const char *sysname)
static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator, const char *basedir, const char *subdir1, const char *subdir2) {
_cleanup_closedir_ DIR *dir = NULL;
char *path;
struct dirent *dent;
int r = 0;
assert(enumerator);
@@ -369,18 +368,18 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
/* this is necessarily racey, so ignore missing directories */
return (errno == ENOENT && (subdir1 || subdir2)) ? 0 : -errno;
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
char syspath[strlen(path) + 1 + strlen(dent->d_name) + 1];
char syspath[strlen(path) + 1 + strlen(de->d_name) + 1];
int initialized, k;
if (dent->d_name[0] == '.')
if (de->d_name[0] == '.')
continue;
if (!match_sysname(enumerator, dent->d_name))
if (!match_sysname(enumerator, de->d_name))
continue;
(void) sprintf(syspath, "%s%s", path, dent->d_name);
(void) sprintf(syspath, "%s%s", path, de->d_name);
k = sd_device_new_from_syspath(&device, syspath);
if (k < 0) {
@@ -461,7 +460,6 @@ static bool match_subsystem(sd_device_enumerator *enumerator, const char *subsys
static int enumerator_scan_dir(sd_device_enumerator *enumerator, const char *basedir, const char *subdir, const char *subsystem) {
_cleanup_closedir_ DIR *dir = NULL;
char *path;
struct dirent *dent;
int r = 0;
path = strjoina("/sys/", basedir);
@@ -472,16 +470,16 @@ static int enumerator_scan_dir(sd_device_enumerator *enumerator, const char *bas
log_debug("sd-device-enumerator: Scanning %s", path);
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno) {
int k;
if (dent->d_name[0] == '.')
if (de->d_name[0] == '.')
continue;
if (!match_subsystem(enumerator, subsystem ? : dent->d_name))
if (!match_subsystem(enumerator, subsystem ? : de->d_name))
continue;
k = enumerator_scan_dir_and_add_devices(enumerator, basedir, dent->d_name, subdir);
k = enumerator_scan_dir_and_add_devices(enumerator, basedir, de->d_name, subdir);
if (k < 0)
r = k;
}
@@ -492,7 +490,6 @@ static int enumerator_scan_dir(sd_device_enumerator *enumerator, const char *bas
static int enumerator_scan_devices_tag(sd_device_enumerator *enumerator, const char *tag) {
_cleanup_closedir_ DIR *dir = NULL;
char *path;
struct dirent *dent;
int r = 0;
assert(enumerator);
@@ -509,15 +506,15 @@ static int enumerator_scan_devices_tag(sd_device_enumerator *enumerator, const c
/* TODO: filter away subsystems? */
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
const char *subsystem, *sysname;
int k;
if (dent->d_name[0] == '.')
if (de->d_name[0] == '.')
continue;
k = sd_device_new_from_device_id(&device, dent->d_name);
k = sd_device_new_from_device_id(&device, de->d_name);
if (k < 0) {
if (k != -ENODEV)
/* this is necessarily racy, so ignore missing devices */
@@ -625,24 +622,23 @@ static int parent_add_child(sd_device_enumerator *enumerator, const char *path)
static int parent_crawl_children(sd_device_enumerator *enumerator, const char *path, unsigned maxdepth) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
int r = 0;
dir = opendir(path);
if (!dir)
return log_debug_errno(errno, "sd-device-enumerator: Failed to open parent directory %s: %m", path);
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno) {
_cleanup_free_ char *child = NULL;
int k;
if (dent->d_name[0] == '.')
if (de->d_name[0] == '.')
continue;
if (dent->d_type != DT_DIR)
if (de->d_type != DT_DIR)
continue;
child = path_join(path, dent->d_name);
child = path_join(path, de->d_name);
if (!child)
return -ENOMEM;
+8 -9
View File
@@ -1747,7 +1747,6 @@ _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) {
_cleanup_free_ char *path_dir = NULL;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
const char *syspath;
int r;
@@ -1779,33 +1778,33 @@ static int device_sysattrs_read_all_internal(sd_device *device, const char *subd
if (!dir)
return -errno;
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
FOREACH_DIRENT_ALL(de, dir, return -errno) {
_cleanup_free_ char *path = NULL, *p = NULL;
struct stat statbuf;
if (dot_or_dot_dot(dent->d_name))
if (dot_or_dot_dot(de->d_name))
continue;
/* only handle symlinks, regular files, and directories */
if (!IN_SET(dent->d_type, DT_LNK, DT_REG, DT_DIR))
if (!IN_SET(de->d_type, DT_LNK, DT_REG, DT_DIR))
continue;
if (subdir) {
p = path_join(subdir, dent->d_name);
p = path_join(subdir, de->d_name);
if (!p)
return -ENOMEM;
}
if (dent->d_type == DT_DIR) {
if (de->d_type == DT_DIR) {
/* read subdirectory */
r = device_sysattrs_read_all_internal(device, p ?: dent->d_name);
r = device_sysattrs_read_all_internal(device, p ?: de->d_name);
if (r < 0)
return r;
continue;
}
path = path_join(syspath, p ?: dent->d_name);
path = path_join(syspath, p ?: de->d_name);
if (!path)
return -ENOMEM;
@@ -1815,7 +1814,7 @@ static int device_sysattrs_read_all_internal(sd_device *device, const char *subd
if (!(statbuf.st_mode & S_IRUSR))
continue;
r = set_put_strdup(&device->sysattrs, p ?: dent->d_name);
r = set_put_strdup(&device->sysattrs, p ?: de->d_name);
if (r < 0)
return r;
}
@@ -127,7 +127,6 @@ int journal_directory_vacuum(
_cleanup_closedir_ DIR *d = NULL;
struct vacuum_info *list = NULL;
usec_t retention_limit = 0;
struct dirent *de;
int r;
assert(directory);
-4
View File
@@ -1560,14 +1560,11 @@ static int directory_open(sd_journal *j, const char *path, DIR **ret) {
static int add_directory(sd_journal *j, const char *prefix, const char *dirname);
static void directory_enumerate(sd_journal *j, Directory *m, DIR *d) {
struct dirent *de;
assert(j);
assert(m);
assert(d);
FOREACH_DIRENT_ALL(de, d, goto fail) {
if (dirent_is_journal_file(de))
(void) add_file_by_name(j, m->path, de->d_name);
@@ -1576,7 +1573,6 @@ static void directory_enumerate(sd_journal *j, Directory *m, DIR *d) {
}
return;
fail:
log_debug_errno(errno, "Failed to enumerate directory %s, ignoring: %m", m->path);
}
-1
View File
@@ -774,7 +774,6 @@ _public_ int sd_get_sessions(char ***sessions) {
_public_ int sd_get_uids(uid_t **users) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int r = 0;
unsigned n = 0;
_cleanup_free_ uid_t *l = NULL;
+1 -4
View File
@@ -1370,9 +1370,7 @@ static int flush_devices(Manager *m) {
if (!d) {
if (errno != ENOENT)
log_warning_errno(errno, "Failed to open /etc/udev/rules.d: %m");
} else {
struct dirent *de;
} else
FOREACH_DIRENT_ALL(de, d, break) {
if (!dirent_is_file(de))
continue;
@@ -1386,7 +1384,6 @@ static int flush_devices(Manager *m) {
if (unlinkat(dirfd(d), de->d_name, 0) < 0)
log_warning_errno(errno, "Failed to unlink %s: %m", de->d_name);
}
}
return trigger_device(m, NULL);
}
-2
View File
@@ -313,8 +313,6 @@ static int recurse_fd(int fd, bool donate_fd, const struct stat *st, uid_t shift
goto read_only;
if (S_ISDIR(st->st_mode)) {
struct dirent *de;
if (!donate_fd) {
int copy;
-1
View File
@@ -1536,7 +1536,6 @@ void manager_reset_server_features(Manager *m) {
void manager_cleanup_saved_user(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
assert(m);
-1
View File
@@ -103,7 +103,6 @@ int block_get_originating(dev_t dt, dev_t *ret) {
_cleanup_free_ char *t = NULL;
char p[SYS_BLOCK_PATH_MAX("/slaves")];
_cleanup_free_ char *first_found = NULL;
struct dirent *de;
const char *q;
dev_t devt;
int r;
-1
View File
@@ -52,7 +52,6 @@ static int chown_recursive_internal(
_cleanup_closedir_ DIR *d = NULL;
bool changed = false;
struct dirent *de;
int r;
assert(fd >= 0);
-2
View File
@@ -219,7 +219,6 @@ static int clean_sysvipc_msg(uid_t delete_uid, gid_t delete_gid, bool rm) {
}
static int clean_posix_shm_internal(const char *dirname, DIR *dir, uid_t uid, gid_t gid, bool rm) {
struct dirent *de;
int ret = 0, r;
assert(dir);
@@ -315,7 +314,6 @@ static int clean_posix_shm(uid_t uid, gid_t gid, bool rm) {
static int clean_posix_mq(uid_t uid, gid_t gid, bool rm) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *de;
int ret = 0;
dir = opendir("/dev/mqueue");
-1
View File
@@ -789,7 +789,6 @@ static int fd_copy_directory(
_cleanup_close_ int fdf = -1, fdt = -1;
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
bool exists, created;
int r;
-1
View File
@@ -543,7 +543,6 @@ int image_discover(
NULSTR_FOREACH(path, image_search_path[class]) {
_cleanup_free_ char *resolved = NULL;
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
r = chase_symlinks_and_opendir(path, root, CHASE_PREFIX_ROOT, &resolved, &d);
if (r == -ENOENT)
+3 -4
View File
@@ -188,7 +188,6 @@ static int wait_for_children(Set *pids, sigset_t *mask, usec_t timeout) {
static int killall(int sig, Set *pids, bool send_sighup) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *d;
int n_killed = 0;
/* Send the specified signal to all remaining processes, if not excluded by ignore_proc().
@@ -198,14 +197,14 @@ static int killall(int sig, Set *pids, bool send_sighup) {
if (!dir)
return log_warning_errno(errno, "opendir(/proc) failed: %m");
FOREACH_DIRENT_ALL(d, dir, break) {
FOREACH_DIRENT_ALL(de, dir, break) {
pid_t pid;
int r;
if (!IN_SET(d->d_type, DT_DIR, DT_UNKNOWN))
if (!IN_SET(de->d_type, DT_DIR, DT_UNKNOWN))
continue;
if (parse_pid(d->d_name, &pid) < 0)
if (parse_pid(de->d_name, &pid) < 0)
continue;
if (ignore_proc(pid, sig == SIGKILL && !in_initrd()))
-1
View File
@@ -203,7 +203,6 @@ int rm_rf_children(
const struct stat *root_dev) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
int ret = 0, r;
assert(fd >= 0);
+15 -17
View File
@@ -590,14 +590,13 @@ static int dir_cleanup(
AgeBy age_by_dir) {
bool deleted = false;
struct dirent *dent;
int r = 0;
FOREACH_DIRENT_ALL(dent, d, break) {
FOREACH_DIRENT_ALL(de, d, break) {
_cleanup_free_ char *sub_path = NULL;
nsec_t atime_nsec, mtime_nsec, ctime_nsec, btime_nsec;
if (dot_or_dot_dot(dent->d_name))
if (dot_or_dot_dot(de->d_name))
continue;
/* If statx() is supported, use it. It's preferable over fstatat() since it tells us
@@ -614,7 +613,7 @@ static int dir_cleanup(
STRUCT_STATX_DEFINE(sx);
r = statx_fallback(
dirfd(d), dent->d_name,
dirfd(d), de->d_name,
AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT,
STATX_TYPE|STATX_MODE|STATX_UID|STATX_ATIME|STATX_MTIME|STATX_CTIME|STATX_BTIME,
&sx);
@@ -623,14 +622,14 @@ static int dir_cleanup(
if (r < 0) {
/* FUSE, NFS mounts, SELinux might return EACCES */
r = log_full_errno(errno == EACCES ? LOG_DEBUG : LOG_ERR, errno,
"statx(%s/%s) failed: %m", p, dent->d_name);
"statx(%s/%s) failed: %m", p, de->d_name);
continue;
}
if (FLAGS_SET(sx.stx_attributes_mask, STATX_ATTR_MOUNT_ROOT)) {
/* Yay, we have the mount point API, use it */
if (FLAGS_SET(sx.stx_attributes, STATX_ATTR_MOUNT_ROOT)) {
log_debug("Ignoring \"%s/%s\": different mount points.", p, dent->d_name);
log_debug("Ignoring \"%s/%s\": different mount points.", p, de->d_name);
continue;
}
} else {
@@ -638,7 +637,7 @@ static int dir_cleanup(
* back to traditional stx_dev checking. */
if (sx.stx_dev_major != rootdev_major ||
sx.stx_dev_minor != rootdev_minor) {
log_debug("Ignoring \"%s/%s\": different filesystem.", p, dent->d_name);
log_debug("Ignoring \"%s/%s\": different filesystem.", p, de->d_name);
continue;
}
@@ -648,11 +647,11 @@ static int dir_cleanup(
if (S_ISDIR(sx.stx_mode)) {
int q;
q = fd_is_mount_point(dirfd(d), dent->d_name, 0);
q = fd_is_mount_point(dirfd(d), de->d_name, 0);
if (q < 0)
log_debug_errno(q, "Failed to determine whether \"%s/%s\" is a mount point, ignoring: %m", p, dent->d_name);
log_debug_errno(q, "Failed to determine whether \"%s/%s\" is a mount point, ignoring: %m", p, de->d_name);
else if (q > 0) {
log_debug("Ignoring \"%s/%s\": different mount of the same filesystem.", p, dent->d_name);
log_debug("Ignoring \"%s/%s\": different mount of the same filesystem.", p, de->d_name);
continue;
}
}
@@ -663,7 +662,7 @@ static int dir_cleanup(
ctime_nsec = FLAGS_SET(sx.stx_mask, STATX_CTIME) ? load_statx_timestamp_nsec(&sx.stx_ctime) : 0;
btime_nsec = FLAGS_SET(sx.stx_mask, STATX_BTIME) ? load_statx_timestamp_nsec(&sx.stx_btime) : 0;
sub_path = path_join(p, dent->d_name);
sub_path = path_join(p, de->d_name);
if (!sub_path) {
r = log_oom();
goto finish;
@@ -684,7 +683,7 @@ static int dir_cleanup(
_cleanup_closedir_ DIR *sub_dir = NULL;
if (mountpoint &&
streq(dent->d_name, "lost+found") &&
streq(de->d_name, "lost+found") &&
sx.stx_uid == 0) {
log_debug("Ignoring directory \"%s\".", sub_path);
continue;
@@ -695,7 +694,7 @@ static int dir_cleanup(
else {
int q;
sub_dir = xopendirat_nomod(dirfd(d), dent->d_name);
sub_dir = xopendirat_nomod(dirfd(d), de->d_name);
if (!sub_dir) {
if (errno != ENOENT)
r = log_warning_errno(errno, "Opening directory \"%s\" failed, ignoring: %m", sub_path);
@@ -737,7 +736,7 @@ static int dir_cleanup(
continue;
log_debug("Removing directory \"%s\".", sub_path);
if (unlinkat(dirfd(d), dent->d_name, AT_REMOVEDIR) < 0)
if (unlinkat(dirfd(d), de->d_name, AT_REMOVEDIR) < 0)
if (!IN_SET(errno, ENOENT, ENOTEMPTY))
r = log_warning_errno(errno, "Failed to remove directory \"%s\", ignoring: %m", sub_path);
@@ -752,7 +751,7 @@ static int dir_cleanup(
if (mountpoint &&
S_ISREG(sx.stx_mode) &&
sx.stx_uid == 0 &&
STR_IN_SET(dent->d_name,
STR_IN_SET(de->d_name,
".journal",
"aquota.user",
"aquota.group")) {
@@ -783,7 +782,7 @@ static int dir_cleanup(
continue;
log_debug("Removing \"%s\".", sub_path);
if (unlinkat(dirfd(d), dent->d_name, 0) < 0)
if (unlinkat(dirfd(d), de->d_name, 0) < 0)
if (errno != ENOENT)
r = log_warning_errno(errno, "Failed to remove \"%s\", ignoring: %m", sub_path);
@@ -1920,7 +1919,6 @@ static int item_do(Item *i, int fd, const char *path, fdaction_t action) {
if (S_ISDIR(st.st_mode)) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
/* The passed 'fd' was opened with O_PATH. We need to convert it into a 'regular' fd before
* reading the directory content. */
+7 -10
View File
@@ -97,7 +97,6 @@ static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, cha
_cleanup_(sd_device_unrefp) sd_device *physfn_pcidev = NULL;
const char *physfn_syspath, *syspath;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
int r;
assert(pcidev);
@@ -123,15 +122,15 @@ static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, cha
if (!dir)
return -errno;
FOREACH_DIRENT_ALL(dent, dir, break) {
FOREACH_DIRENT_ALL(de, dir, break) {
_cleanup_free_ char *virtfn_link_file = NULL, *virtfn_pci_syspath = NULL;
const char *n;
n = startswith(dent->d_name, "virtfn");
n = startswith(de->d_name, "virtfn");
if (!n)
continue;
virtfn_link_file = path_join(physfn_syspath, dent->d_name);
virtfn_link_file = path_join(physfn_syspath, de->d_name);
if (!virtfn_link_file)
return -ENOMEM;
@@ -390,8 +389,6 @@ static int dev_pci_slot(sd_device *dev, const LinkInfo *info, NetNames *names) {
hotplug_slot_dev = names->pcidev;
while (hotplug_slot_dev) {
struct dirent *dent;
r = parse_hotplug_slot_from_function_id(hotplug_slot_dev, slots, &hotplug_slot);
if (r < 0)
return 0;
@@ -404,20 +401,20 @@ static int dev_pci_slot(sd_device *dev, const LinkInfo *info, NetNames *names) {
if (r < 0)
return log_device_debug_errno(hotplug_slot_dev, r, "Failed to get sysname: %m");
FOREACH_DIRENT_ALL(dent, dir, break) {
FOREACH_DIRENT_ALL(de, dir, break) {
_cleanup_free_ char *address = NULL;
char str[PATH_MAX];
uint32_t i;
if (dot_or_dot_dot(dent->d_name))
if (dot_or_dot_dot(de->d_name))
continue;
r = safe_atou32(dent->d_name, &i);
r = safe_atou32(de->d_name, &i);
if (r < 0 || i <= 0)
continue;
/* match slot address with device by stripping the function */
if (snprintf_ok(str, sizeof str, "%s/%s/address", slots, dent->d_name) &&
if (snprintf_ok(str, sizeof str, "%s/%s/address", slots, de->d_name) &&
read_one_line_file(str, &address) >= 0 &&
startswith(sysname, address)) {
hotplug_slot = i;
+5 -6
View File
@@ -309,7 +309,6 @@ static sd_device *handle_scsi_default(sd_device *parent, char **path) {
int host, bus, target, lun;
const char *name, *base, *pos;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
int basenum = -1;
assert(parent);
@@ -352,16 +351,16 @@ static sd_device *handle_scsi_default(sd_device *parent, char **path) {
if (!dir)
return NULL;
FOREACH_DIRENT_ALL(dent, dir, break) {
FOREACH_DIRENT_ALL(de, dir, break) {
unsigned i;
if (dent->d_name[0] == '.')
if (de->d_name[0] == '.')
continue;
if (!IN_SET(dent->d_type, DT_DIR, DT_LNK))
if (!IN_SET(de->d_type, DT_DIR, DT_LNK))
continue;
if (!startswith(dent->d_name, "host"))
if (!startswith(de->d_name, "host"))
continue;
if (safe_atou_full(&dent->d_name[4], 10, &i) < 0)
if (safe_atou_full(&de->d_name[4], 10, &i) < 0)
continue;
/*
* find the smallest number; the host really needs to export its
+5 -6
View File
@@ -111,7 +111,6 @@ static int node_symlink(sd_device *dev, const char *node, const char *slink) {
static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir, char **ret) {
_cleanup_closedir_ DIR *dir = NULL;
_cleanup_free_ char *target = NULL;
struct dirent *dent;
int r, priority = 0;
const char *id;
@@ -153,18 +152,18 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir,
if (r < 0)
return r;
FOREACH_DIRENT_ALL(dent, dir, break) {
FOREACH_DIRENT_ALL(de, dir, break) {
_cleanup_free_ char *path = NULL, *buf = NULL;
int tmp_prio;
if (dent->d_name[0] == '.')
if (de->d_name[0] == '.')
continue;
/* skip ourself */
if (streq(dent->d_name, id))
if (streq(de->d_name, id))
continue;
path = path_join(stackdir, dent->d_name);
path = path_join(stackdir, de->d_name);
if (!path)
return -ENOMEM;
@@ -197,7 +196,7 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir,
/* Old format. The devnode and priority must be obtained from uevent and
* udev database files. */
if (sd_device_new_from_device_id(&tmp_dev, dent->d_name) < 0)
if (sd_device_new_from_device_id(&tmp_dev, de->d_name) < 0)
continue;
if (device_get_devlink_priority(tmp_dev, &tmp_prio) < 0)
+3 -4
View File
@@ -1494,7 +1494,6 @@ static int import_parent_into_properties(sd_device *dev, const char *filter) {
static int attr_subst_subdir(char attr[static UDEV_PATH_SIZE]) {
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
char buf[UDEV_PATH_SIZE], *p;
const char *tail;
size_t len, size;
@@ -1516,11 +1515,11 @@ static int attr_subst_subdir(char attr[static UDEV_PATH_SIZE]) {
if (!dir)
return -errno;
FOREACH_DIRENT_ALL(dent, dir, break) {
if (dent->d_name[0] == '.')
FOREACH_DIRENT_ALL(de, dir, break) {
if (de->d_name[0] == '.')
continue;
strscpyl(p, size, dent->d_name, tail, NULL);
strscpyl(p, size, de->d_name, tail, NULL);
if (faccessat(dirfd(dir), p, F_OK, 0) < 0)
continue;
-1
View File
@@ -20,7 +20,6 @@
#define MIN_RANDOM_DELAY ( 10 * USEC_PER_MSEC)
int udev_watch_restore(int inotify_fd) {
struct dirent *ent;
DIR *dir;
int r;
-2
View File
@@ -224,8 +224,6 @@ static int export_devices(void) {
}
static void cleanup_dir(DIR *dir, mode_t mask, int depth) {
struct dirent *dent;
if (depth <= 0)
return;