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
committerLennart Poettering <lennart@poettering.net>2015-04-06 10:57:53 +0200
commitf25afeb6ab515cf890eff58c0b53cf35b2be0e05 (patch)
treea5d852813c41728861aee2001d047f94c7892290 /src/shared/rm-rf.c
parentc6878637502b1717a110a9a7e8bba32a8583fcdf (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 99d12b11c6..eeb2e39196 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;