summaryrefslogtreecommitdiff
path: root/src/shared/rm-rf.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-04 14:42:39 +0200
committerSven Eden <yamakuzure@gmx.net>2017-03-14 07:49:53 +0100
commit34da583ada206b2d4b5431a90c67a771c62e604d (patch)
treee1d9c5547174b7bc9e019f2747cc88fff8aa9487 /src/shared/rm-rf.c
parente777ddfd71f3b2d3217ffe74f287388832915d0b (diff)
rm-rf: never cross mount points
Diffstat (limited to 'src/shared/rm-rf.c')
-rw-r--r--src/shared/rm-rf.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c
index 99d12b11c..eeb2e3919 100644
--- a/src/shared/rm-rf.c
+++ b/src/shared/rm-rf.c
@@ -89,7 +89,7 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
if (is_dir) {
int subdir_fd;
- /* if root_dev is set, remove subdirectories only, if device is same as dir */
+ /* if root_dev is set, remove subdirectories only if device is same */
if (root_dev && st.st_dev != root_dev->st_dev)
continue;
@@ -100,6 +100,20 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
continue;
}
+ /* Stop at mount points */
+ r = fd_is_mount_point(subdir_fd);
+ if (r < 0) {
+ if (ret == 0 && r != -ENOENT)
+ ret = r;
+
+ safe_close(subdir_fd);
+ continue;
+ }
+ if (r) {
+ safe_close(subdir_fd);
+ continue;
+ }
+
/* We pass REMOVE_PHYSICAL here, to avoid
* doing the fstatfs() to check the file
* system type again for each directory */
@@ -162,7 +176,6 @@ int rm_rf(const char *path, RemoveFlags flags) {
r = rm_rf_children(fd, flags, NULL);
if (flags & REMOVE_ROOT) {
-
if (rmdir(path) < 0 && errno != ENOENT) {
if (r == 0)
r = -errno;