diff options
author | Reverend Homer <mk.43.ecko@gmail.com> | 2016-12-09 12:04:30 +0300 |
---|---|---|
committer | Martin Pitt <martin.pitt@ubuntu.com> | 2016-12-09 10:04:30 +0100 |
commit | 8fb3f0099787a5b48213c4e2aa42d8ff61b0c7f1 (patch) | |
tree | c9bf990e18daac08ec1e744d6be365a9e98d2532 /src/shared | |
parent | 9258a1cae3985ee590f1c698451bd7909aa38d2b (diff) |
tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853)
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/dropin.c | 17 | ||||
-rw-r--r-- | src/shared/fdset.c | 7 |
2 files changed, 5 insertions, 19 deletions
diff --git a/src/shared/dropin.c b/src/shared/dropin.c index 2c1cd84df5..3cbfe13f4c 100644 --- a/src/shared/dropin.c +++ b/src/shared/dropin.c @@ -17,7 +17,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <dirent.h> #include <errno.h> #include <stdarg.h> #include <stdio.h> @@ -25,6 +24,7 @@ #include "alloc-util.h" #include "conf-files.h" +#include "dirent-util.h" #include "dropin.h" #include "escape.h" #include "fd-util.h" @@ -124,6 +124,7 @@ static int iterate_dir( char ***strv) { _cleanup_closedir_ DIR *d = NULL; + struct dirent *de; int r; assert(path); @@ -148,21 +149,9 @@ static int iterate_dir( return log_error_errno(errno, "Failed to open directory %s: %m", path); } - for (;;) { - struct dirent *de; + FOREACH_DIRENT(de, d, return log_error_errno(errno, "Failed to read directory %s: %m", path)) { _cleanup_free_ char *f = NULL; - errno = 0; - de = readdir(d); - if (!de && errno > 0) - return log_error_errno(errno, "Failed to read directory %s: %m", path); - - if (!de) - break; - - if (hidden_or_backup_file(de->d_name)) - continue; - f = strjoin(path, "/", de->d_name); if (!f) return log_oom(); diff --git a/src/shared/fdset.c b/src/shared/fdset.c index 527f27bc67..090f3fdcdd 100644 --- a/src/shared/fdset.c +++ b/src/shared/fdset.c @@ -18,13 +18,13 @@ ***/ #include <alloca.h> -#include <dirent.h> #include <errno.h> #include <fcntl.h> #include <stddef.h> #include "sd-daemon.h" +#include "dirent-util.h" #include "fd-util.h" #include "fdset.h" #include "log.h" @@ -148,12 +148,9 @@ int fdset_new_fill(FDSet **_s) { goto finish; } - while ((de = readdir(d))) { + FOREACH_DIRENT(de, d, return -errno) { int fd = -1; - if (hidden_or_backup_file(de->d_name)) - continue; - r = safe_atoi(de->d_name, &fd); if (r < 0) goto finish; |