diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index 1d41b9f8e4..c2b700aad1 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -360,7 +360,6 @@ int main(int argc, char *argv[]) { NULL }; _cleanup_free_ char *cgroup = NULL; - char *arguments[3]; int cmd, r; /* Close random fds we might have get passed, just for paranoia, before we open any new fds, for @@ -449,11 +448,11 @@ int main(int argc, char *argv[]) { broadcast_signal(SIGKILL, true, false, arg_timeout); bool need_umount = !in_container, need_swapoff = !in_container, need_loop_detach = !in_container, - need_dm_detach = !in_container, need_md_detach = !in_container, can_initrd, last_try = false; - can_initrd = !in_container && !in_initrd() && access("/run/initramfs/shutdown", X_OK) == 0; + need_dm_detach = !in_container, need_md_detach = !in_container, + can_exitrd = !in_container && !in_initrd() && access("/run/initramfs/shutdown", X_OK) >= 0; /* Unmount all mountpoints, swaps, and loopback devices */ - for (;;) { + for (bool last_try = false;;) { bool changed = false; (void) watchdog_ping(); @@ -530,10 +529,10 @@ int main(int argc, char *argv[]) { break; } - if (!changed && !last_try && !can_initrd) { + if (!changed && !last_try && !can_exitrd) { /* There are things we cannot get rid of. Loop one more time in which we will log * with higher priority to inform the user. Note that we don't need to do this if - * there is an initrd to switch to, because that one is likely to get rid of the + * there is an exitrd to switch to, because that one is likely to get rid of the * remaining mounts. If not, it will log about them. */ last_try = true; continue; @@ -562,14 +561,16 @@ int main(int argc, char *argv[]) { * active to guard against any issues during the rest of the shutdown sequence. */ watchdog_free_device(); - arguments[0] = NULL; /* Filled in by execute_directories(), when needed */ - arguments[1] = (char*) arg_verb; - arguments[2] = NULL; - (void) execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, arguments, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS); + const char *arguments[] = { + NULL, /* Filled in by execute_directories(), when needed */ + arg_verb, + NULL, + }; + (void) execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, (char**) arguments, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS); (void) rlimit_nofile_safe(); - if (can_initrd) { + if (can_exitrd) { r = switch_root_initramfs(); if (r >= 0) { argv[0] = (char*) "/shutdown"; @@ -578,7 +579,7 @@ int main(int argc, char *argv[]) { (void) make_console_stdio(); log_info("Successfully changed into root pivot.\n" - "Returning to initrd..."); + "Entering exitrd..."); execv("/shutdown", argv); log_error_errno(errno, "Failed to execute shutdown binary: %m");