]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
switch-root: modernize rm_rf_children() invocation a bit
authorLennart Poettering <lennart@poettering.net>
Mon, 29 Apr 2019 13:45:19 +0000 (15:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 29 Apr 2019 14:17:29 +0000 (16:17 +0200)
src/basic/rm-rf.c
src/shared/switch-root.c

index acc0f88cd24a6918e369db701717b5c8db86d18e..3843fc36fcb86b6bf7b8bfca79a3780fc96bc530 100644 (file)
@@ -33,8 +33,8 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
 
         assert(fd >= 0);
 
-        /* This returns the first error we run into, but nevertheless
-         * tries to go on. This closes the passed fd. */
+        /* This returns the first error we run into, but nevertheless tries to go on. This closes the passed
+         * fd, in all cases, including on failure.. */
 
         if (!(flags & REMOVE_PHYSICAL)) {
 
index dbb4622312a079080ab3ae63720ce1cce4517abc..f721aff76071182940f5191f725ca6615463f1af 100644 (file)
@@ -120,10 +120,8 @@ int switch_root(const char *new_root,
 
                 if (fstat(old_root_fd, &rb) < 0)
                         log_warning_errno(errno, "Failed to stat old root directory, leaving: %m");
-                else {
-                        (void) rm_rf_children(old_root_fd, 0, &rb);
-                        old_root_fd = -1;
-                }
+                else
+                        (void) rm_rf_children(TAKE_FD(old_root_fd), 0, &rb); /* takes possession of the dir fd, even on failure */
         }
 
         return 0;