]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: make FOREACH_DIRENT_ALL define the iterator variable
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 7 Dec 2021 14:02:55 +0000 (15:02 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 15 Dec 2021 15:19:13 +0000 (16:19 +0100)
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.

31 files changed:
src/basic/cgroup-util.c
src/basic/dirent-util.h
src/basic/fs-util.c
src/basic/unit-file.c
src/core/manager.c
src/delta/delta.c
src/import/import-common.c
src/import/pull-common.c
src/journal/journald-server.c
src/libsystemd/sd-device/device-enumerator.c
src/libsystemd/sd-device/sd-device.c
src/libsystemd/sd-journal/journal-vacuum.c
src/libsystemd/sd-journal/sd-journal.c
src/libsystemd/sd-login/sd-login.c
src/login/logind-dbus.c
src/nspawn/nspawn-patch-uid.c
src/resolve/resolved-manager.c
src/shared/blockdev-util.c
src/shared/chown-recursive.c
src/shared/clean-ipc.c
src/shared/copy.c
src/shared/discover-image.c
src/shared/killall.c
src/shared/rm-rf.c
src/tmpfiles/tmpfiles.c
src/udev/udev-builtin-net_id.c
src/udev/udev-builtin-path_id.c
src/udev/udev-node.c
src/udev/udev-rules.c
src/udev/udev-watch.c
src/udev/udevadm-info.c

index b8268bc65c1888a3bb13fc9cc06dea531475b995..a626ecf2e2f2edf90166667a2ea19a61732529d8 100644 (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);
 
index a6272f891f5582d1da2303f67badec28cd70394f..2dc5dae1e1783c4634722ae2da572db6ee8fbf2e 100644 (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;                               \
index a135632ceee433e625c35a14ef81fdabea47254f..552986f546664a63f76da1b37105b646ba1921ec 100644 (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);
index 89bfeceae4f52bed47891cbff23e00a35704ca9b..30c632dfcef10a7df7344f9322d5b67c7ea821fb 100644 (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) {
index c5c6e628685c8c300af31733da8e74546faff66e..9368a1dfa18655774b35dfc9f99ab6b83688b265 100644 (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;
 }
 
index 8f154f7680d656dc2b91a7ebb646d0e4f77d48c0..3f1b206e6cc48f5be1b2f9eeeb02005384be1c91 100644 (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;
index c36105221f6cf0a39c33d63f0dcf6451b845af16..4eda9087c5a88bc7ad2a121504be856d876d14e8 100644 (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);
 
index d0d0c85adc5ed17e2800a5d7ea4c1dbdc97449fb..028bae82a86a99c27e44b28cfa15f41320deea10 100644 (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;
index c04801d9fcab06b954a09bf8b856ea9dcb1172c4..a244d9c5e7e18b04e5e092c466f282a22e9a52be 100644 (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);
index 3ae80ab94281ce84b195ff65ab78307fd8b04e84..4f1719b3ed29b6c71088462007b6a680420e0d5c 100644 (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;
 
index e594d5fbe4e1babe38f079fe38dfdd986d591612..c348bd8f0f372253f19319af48e64d5c70330157 100644 (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;
         }
index 889caa19056232743bd030faab82327a0bd6c309..8296448ed5db6caf35278aa43514a68d37c27e3a 100644 (file)
@@ -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);
index b3f14cc5483e35377b37f45183687b720848239f..efaa2bf501dac9b9bf1178aaa36b5878698f7f25 100644 (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);
 }
index 4a35e6142579a9e96413c193b5d8632c6316b722..00129ff77dacb9d679893d7e47a69bdd73344981 100644 (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;
index 331dcd2a05d7c9e26aee4dd4a416b315860d91ba..cc5214c2ebcdab7c27a95a31055d4f930064df62 100644 (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);
 }
index f47f82736104706b584a6becc4243d842259d1ff..1535d19bbb62eb018028b638ebab26fc6afaf559 100644 (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;
 
index 6b32ee4cf07b6faada3d56ae60bb018e37064752..615431ebb7e161f3fac4e8e8c561d8a70a636897 100644 (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);
 
index db50505c9ae7f0d2b7d9e1395f6815a3f0182076..a0c60be26e95ed398882410f16cd4d0083ee12ea 100644 (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;
index 50848715e34621b8282b13dbfd26fb1162e64e8e..7c9a3050b4c739ef91899076fd4c789f3fc426d9 100644 (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);
index 497b0884d49f63ae8a7ac1a77d214ef044e13c33..bbb343f3d35794813c960aa6146334cdd320924e 100644 (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");
index bb3ac8a3f85301fed4296d51ebf2895b27921501..1ace40424e5ef3153054d10517008d3af4cdf65f 100644 (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;
 
index 9c07cda8eeadc50665630c0733b1231720cec9e6..268d9102142ba67c0d7850d7f15cc31099510152 100644 (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)
index 869955a58f6c1fa47978c03d411ff8b3ea1e9484..343c2dc42c08b3d59ca06a7cf171779dce8ad007 100644 (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()))
index 81ee5c37baef30aa12cfb5cc74bec99edf487ab0..fd54b2ccaf9225e7dcda301e327c5cdc9d4ce48d 100644 (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);
index 4f1ce1f73fc62876ada9a5c7688f5ed38ecd45b2..fcab51c2081d0943864853fb4dd1d681309dd92a 100644 (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. */
index 4d165917509006f92a9079e95e535f606e0e1310..c1f9f232aebabffefd8267c64db71d0ace6a855d 100644 (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;
index 6fdd3eceea3176bab212ad2cf912cc5b4b84298f..ae92e452059e3ba8a5980ef1aa5b1c4f284c61d9 100644 (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
index 760c3a4448c20cea8ab18371b0456cd170fb8bf6..1824ccef6a505177bbf95d6d88a8c1df77061ee7 100644 (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)
index 693c743c574a322ece339bb90015a6ef967c9d31..1a384d6b38451787d5c1f6b24721d00460984ac9 100644 (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;
 
index 87c4f09928b08693e86ac342cdc305ddd0f91570..a8b7d2d2d14e872d6328e9b67af2ec6e2a87d067 100644 (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;
 
index 84f7794e86fb7b9ae5a0b0978d4d35b8b5da23f1..133be80b7017e949905b4dd64c41d5285927f1fb 100644 (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;