summaryrefslogtreecommitdiff
path: root/src/basic/rm-rf.c
diff options
context:
space:
mode:
authorReverend Homer <mk.43.ecko@gmail.com>2016-12-09 12:04:30 +0300
committerMartin Pitt <martin.pitt@ubuntu.com>2016-12-09 10:04:30 +0100
commit8fb3f0099787a5b48213c4e2aa42d8ff61b0c7f1 (patch)
treec9bf990e18daac08ec1e744d6be365a9e98d2532 /src/basic/rm-rf.c
parent9258a1cae3985ee590f1c698451bd7909aa38d2b (diff)
downloadsystemd-8fb3f0099787a5b48213c4e2aa42d8ff61b0c7f1.tar.gz
tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853)
Diffstat (limited to 'src/basic/rm-rf.c')
-rw-r--r--src/basic/rm-rf.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/basic/rm-rf.c b/src/basic/rm-rf.c
index baa70c2c8d..07d42f78dd 100644
--- a/src/basic/rm-rf.c
+++ b/src/basic/rm-rf.c
@@ -17,7 +17,6 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
@@ -28,6 +27,7 @@
#include "btrfs-util.h"
#include "cgroup-util.h"
+#include "dirent-util.h"
#include "fd-util.h"
#include "log.h"
#include "macro.h"
@@ -43,6 +43,7 @@ static bool is_physical_fs(const struct statfs *sfs) {
int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
_cleanup_closedir_ DIR *d = NULL;
+ struct dirent *de;
int ret = 0, r;
struct statfs sfs;
@@ -78,19 +79,10 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
return errno == ENOENT ? 0 : -errno;
}
- for (;;) {
- struct dirent *de;
+ FOREACH_DIRENT_ALL(de, d, return -errno) {
bool is_dir;
struct stat st;
- errno = 0;
- de = readdir(d);
- if (!de) {
- if (errno > 0 && ret == 0)
- ret = -errno;
- return ret;
- }
-
if (streq(de->d_name, ".") || streq(de->d_name, ".."))
continue;
@@ -178,6 +170,7 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
}
}
}
+ return ret;
}
int rm_rf(const char *path, RemoveFlags flags) {