From: Yu Watanabe Date: Wed, 23 Jun 2021 19:29:40 +0000 (+0900) Subject: dirent-util: use readdir_ensure_type() in readdir_no_dot() and FOREACH_DIRENT() X-Git-Tag: v249-rc2~21^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f565b8676fbdab115c068a57952f53a88e50f849;p=thirdparty%2Fsystemd.git dirent-util: use readdir_ensure_type() in readdir_no_dot() and FOREACH_DIRENT() --- diff --git a/src/basic/dirent-util.c b/src/basic/dirent-util.c index 988269896a3..f6213a30535 100644 --- a/src/basic/dirent-util.c +++ b/src/basic/dirent-util.c @@ -7,7 +7,7 @@ #include "path-util.h" #include "string-util.h" -int dirent_ensure_type(DIR *d, struct dirent *de) { +static int dirent_ensure_type(DIR *d, struct dirent *de) { struct stat st; assert(d); @@ -75,7 +75,7 @@ struct dirent *readdir_no_dot(DIR *dirp) { struct dirent *d; for (;;) { - d = readdir(dirp); + d = readdir_ensure_type(dirp); if (d && dot_or_dot_dot(d->d_name)) continue; return d; diff --git a/src/basic/dirent-util.h b/src/basic/dirent-util.h index 20ab216c0c6..c7956e7c1b7 100644 --- a/src/basic/dirent-util.h +++ b/src/basic/dirent-util.h @@ -8,8 +8,6 @@ #include "macro.h" #include "path-util.h" -int dirent_ensure_type(DIR *d, struct dirent *de); - bool dirent_is_file(const struct dirent *de) _pure_; bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) _pure_; @@ -17,7 +15,7 @@ struct dirent *readdir_ensure_type(DIR *d); struct dirent *readdir_no_dot(DIR *dirp); #define FOREACH_DIRENT(de, d, on_error) \ - for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \ + for (de = readdir_ensure_type(d);; de = readdir_ensure_type(d)) \ if (!de) { \ if (errno > 0) { \ on_error; \ @@ -28,7 +26,7 @@ struct dirent *readdir_no_dot(DIR *dirp); else #define FOREACH_DIRENT_ALL(de, d, on_error) \ - for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \ + for (de = readdir_ensure_type(d);; de = readdir_ensure_type(d)) \ if (!de) { \ if (errno > 0) { \ on_error; \ diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 5fe8fbab986..bb50b2cf511 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -581,8 +581,6 @@ int get_files_in_directory(const char *path, char ***list) { return -errno; FOREACH_DIRENT_ALL(de, d, return -errno) { - dirent_ensure_type(d, de); - if (!dirent_is_file(de)) continue; diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index b818078158b..fd6b01cfaad 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -169,8 +169,6 @@ static int add_locales_from_libdir (Set *locales) { FOREACH_DIRENT(entry, dir, return -errno) { char *z; - dirent_ensure_type(dir, entry); - if (entry->d_type != DT_DIR) continue; diff --git a/src/basic/unit-file.c b/src/basic/unit-file.c index f20ae4dbe53..884a0674a9c 100644 --- a/src/basic/unit-file.c +++ b/src/basic/unit-file.c @@ -321,7 +321,6 @@ int unit_file_build_name_map( if (hashmap_contains(ids, de->d_name)) continue; - dirent_ensure_type(d, de); if (de->d_type == DT_LNK) { /* We don't explicitly check for alias loops here. unit_ids_map_get() which * limits the number of hops should be used to access the map. */ diff --git a/src/core/smack-setup.c b/src/core/smack-setup.c index 58ad085dcd6..79c48084734 100644 --- a/src/core/smack-setup.c +++ b/src/core/smack-setup.c @@ -82,7 +82,6 @@ static int write_access2_rules(const char *srcdir) { FOREACH_DIRENT(entry, dir, return 0) { _cleanup_fclose_ FILE *policy = NULL; - dirent_ensure_type(dir, entry); if (!dirent_is_file(entry)) continue; @@ -149,7 +148,6 @@ static int write_cipso2_rules(const char *srcdir) { FOREACH_DIRENT(entry, dir, return 0) { _cleanup_fclose_ FILE *policy = NULL; - dirent_ensure_type(dir, entry); if (!dirent_is_file(entry)) continue; diff --git a/src/delta/delta.c b/src/delta/delta.c index 9ebe435a498..f78c6b9c0d3 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -311,8 +311,6 @@ static int enumerate_dir( } FOREACH_DIRENT_ALL(de, d, return -errno) { - dirent_ensure_type(d, de); - if (dropins && de->d_type == DT_DIR && endswith(de->d_name, ".d")) { if (!GREEDY_REALLOC0(dirs, n_dirs + 2)) return -ENOMEM; diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index b4e010e74c2..f6fff204f65 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -795,8 +795,6 @@ _public_ int sd_get_uids(uid_t **users) { int k; uid_t uid; - dirent_ensure_type(d, de); - if (!dirent_is_file(de)) continue; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 1754c9dc584..19c3f9bd6e2 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1374,7 +1374,6 @@ static int flush_devices(Manager *m) { struct dirent *de; FOREACH_DIRENT_ALL(de, d, break) { - dirent_ensure_type(d, de); if (!dirent_is_file(de)) continue; diff --git a/src/login/logind.c b/src/login/logind.c index b782938a5c9..ec52a57acb5 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -299,7 +299,6 @@ static int manager_enumerate_linger_users(Manager *m) { FOREACH_DIRENT(de, d, return -errno) { int k; - dirent_ensure_type(d, de); if (!dirent_is_file(de)) continue; diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index 1d78ff28c8a..c213c905a1a 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -787,8 +787,6 @@ static int find_loop_device(const char *backing_file, char **loop_dev) { _cleanup_free_ char *sys = NULL, *fname = NULL; int r; - dirent_ensure_type(d, de); - if (de->d_type != DT_DIR) continue; diff --git a/src/portable/portable.c b/src/portable/portable.c index 9e33299ed51..a915800da44 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -311,7 +311,6 @@ static int extract_now( if (hashmap_get(unit_files, de->d_name)) continue; - dirent_ensure_type(d, de); if (!IN_SET(de->d_type, DT_LNK, DT_REG)) continue; @@ -1396,7 +1395,6 @@ int portable_detach( if (set_contains(unit_files, de->d_name)) continue; - dirent_ensure_type(d, de); if (!IN_SET(de->d_type, DT_LNK, DT_REG)) continue; @@ -1569,7 +1567,6 @@ static int portable_get_state_internal( if (set_contains(unit_files, de->d_name)) continue; - dirent_ensure_type(d, de); if (!IN_SET(de->d_type, DT_LNK, DT_REG)) continue; diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index dc334cf1966..e538e2bd87a 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -482,7 +482,6 @@ static int boot_entries_find_unified( _cleanup_free_ char *j = NULL, *osrelease = NULL, *cmdline = NULL; _cleanup_close_ int fd = -1; - dirent_ensure_type(d, de); if (!dirent_is_file(de)) continue; diff --git a/src/shared/install.c b/src/shared/install.c index ba4fa5b136c..5a1427ee023 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -568,8 +568,6 @@ static int remove_marked_symlinks_fd( FOREACH_DIRENT(de, d, return -errno) { - dirent_ensure_type(d, de); - if (de->d_type == DT_DIR) { _cleanup_free_ char *p = NULL; int nfd, q; @@ -738,8 +736,6 @@ static int find_symlinks_in_directory( bool found_path = false, found_dest, b = false; int q; - dirent_ensure_type(dir, de); - if (de->d_type != DT_LNK) continue; @@ -836,8 +832,6 @@ static int find_symlinks( _cleanup_free_ const char *path = NULL; _cleanup_closedir_ DIR *d = NULL; - dirent_ensure_type(config_dir, de); - if (de->d_type != DT_DIR) continue; @@ -3379,8 +3373,6 @@ int unit_file_preset_all( if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY)) continue; - dirent_ensure_type(d, de); - if (!IN_SET(de->d_type, DT_LNK, DT_REG)) continue; @@ -3457,8 +3449,6 @@ int unit_file_get_list( if (hashmap_get(h, de->d_name)) continue; - dirent_ensure_type(d, de); - if (!IN_SET(de->d_type, DT_LNK, DT_REG)) continue; diff --git a/src/shared/numa-util.c b/src/shared/numa-util.c index 7e41d686628..644b0bde5bd 100644 --- a/src/shared/numa-util.c +++ b/src/shared/numa-util.c @@ -139,8 +139,6 @@ static int numa_max_node(void) { int node; const char *n; - (void) dirent_ensure_type(d, de); - if (de->d_type != DT_DIR) continue; diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index ca21eadaba6..576a9a87531 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -126,8 +126,6 @@ static void test_get_process_cmdline(void) { FOREACH_DIRENT(de, d, return) { pid_t pid; - dirent_ensure_type(d, de); - if (de->d_type != DT_DIR) continue;