From: Lennart Poettering Date: Mon, 29 Apr 2019 13:45:19 +0000 (+0200) Subject: switch-root: modernize rm_rf_children() invocation a bit X-Git-Tag: v243-rc1~498^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c0ba6b928676acbc6562c28edf820eaf2b5a1d4f;p=thirdparty%2Fsystemd.git switch-root: modernize rm_rf_children() invocation a bit --- diff --git a/src/basic/rm-rf.c b/src/basic/rm-rf.c index acc0f88cd24..3843fc36fcb 100644 --- a/src/basic/rm-rf.c +++ b/src/basic/rm-rf.c @@ -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)) { diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index dbb4622312a..f721aff7607 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -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;