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)) {
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;