]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dirent-util: use readdir_ensure_type() in readdir_no_dot() and FOREACH_DIRENT() 20004/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Jun 2021 19:29:40 +0000 (04:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Jun 2021 19:29:40 +0000 (04:29 +0900)
16 files changed:
src/basic/dirent-util.c
src/basic/dirent-util.h
src/basic/fs-util.c
src/basic/locale-util.c
src/basic/unit-file.c
src/core/smack-setup.c
src/delta/delta.c
src/libsystemd/sd-login/sd-login.c
src/login/logind-dbus.c
src/login/logind.c
src/mount/mount-tool.c
src/portable/portable.c
src/shared/bootspec.c
src/shared/install.c
src/shared/numa-util.c
src/test/test-process-util.c

index 988269896a33db8a77ac6861bf9cff5d7c861d95..f6213a305354452cbb6175268b46515cbfba2353 100644 (file)
@@ -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;
index 20ab216c0c6defce6eff8a68b47016844465853b..c7956e7c1b7819ca839ccd989947151cbefeabae 100644 (file)
@@ -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;                               \
index 5fe8fbab9860e62b52b285445d0fa1e04d2060a1..bb50b2cf5116d928ea29352d5827630e82654d96 100644 (file)
@@ -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;
 
index b818078158bd2af87b4883f3a1c88989d8046121..fd6b01cfaade6f0441b61222964322e667ede998 100644 (file)
@@ -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;
 
index f20ae4dbe5343b69b3d4223a3ac597abb3a43ad1..884a0674a9c06f0f5da91486716d78ca42b8547f 100644 (file)
@@ -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. */
index 58ad085dcd6f0cc624c6831bd4507552d0f102e4..79c480847340bedac6b4cc058e67db4346386451 100644 (file)
@@ -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;
 
index 9ebe435a498e4ca7d18d46c01149f05504ede824..f78c6b9c0d3ee8c549e966f84804e14ab0cf6d90 100644 (file)
@@ -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;
index b4e010e74c2844bc6be83a82cca0b2eb46df0fdc..f6fff204f65aa971655fddf8d977e4462db5b294 100644 (file)
@@ -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;
 
index 1754c9dc5842498527e612a029a2d11fe896c403..19c3f9bd6e251c9053409e700a7bc7f7d31e5d27 100644 (file)
@@ -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;
 
index b782938a5c920d224e9bfdef463327e571aa0eb9..ec52a57acb59e112247ef8b9065eaf4fd8cdd31c 100644 (file)
@@ -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;
 
index 1d78ff28c8ae51cae88bff19235c8816440b48db..c213c905a1aa627368c94570960ad2556b7264aa 100644 (file)
@@ -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;
 
index 9e33299ed51e3c0ba095ef255e85d3237c8f8cfe..a915800da44d90401684e4e4e1747608bf1c796b 100644 (file)
@@ -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;
 
index dc334cf19664b7efb764596e484ff74897c6ba6e..e538e2bd87a687b1a4952945fb07d5ce159f24d9 100644 (file)
@@ -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;
 
index ba4fa5b136cc81e06b5a77450c69d8ce4e5fbf75..5a1427ee0238923da13dda1281595a1309b08e05 100644 (file)
@@ -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;
 
index 7e41d686628467676da0f14cd25a0be1eff1082c..644b0bde5bda4a254b1f1868ee593f19051aa830 100644 (file)
@@ -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;
 
index ca21eadaba6940f8b58b8a8eecc847bc689c7570..576a9a87531f92c822bced8367af6fdeaf992307 100644 (file)
@@ -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;