X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fmain.c;h=9a51a9187ffe03a2c1b5c01d6b96a6a671180273;hb=9279749b84cc87c7830280b7895a48bed03c9429;hp=15bd2e4d1562bf14ad2089811e4845ae3ab05b41;hpb=52661efd21608dc7e0ac26b714a9254ed6180ddb;p=elogind.git diff --git a/src/main.c b/src/main.c index 15bd2e4d1..9a51a9187 100644 --- a/src/main.c +++ b/src/main.c @@ -889,6 +889,7 @@ int main(int argc, char *argv[]) { int r, retval = EXIT_FAILURE; FDSet *fds = NULL; bool reexecute = false; + const char *shutdown_verb = NULL; if (getpid() != 1 && strstr(program_invocation_short_name, "init")) { /* This is compatbility support for SysV, where @@ -972,6 +973,11 @@ int main(int argc, char *argv[]) { "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", arg_running_as == MANAGER_SYSTEM); + /* Unset some environment variables passed in from the kernel + * that don't really make sense for us. */ + unsetenv("HOME"); + unsetenv("TERM"); + /* Move out of the way, so that we won't block unmounts */ assert_se(chdir("/") == 0); @@ -1127,6 +1133,23 @@ int main(int argc, char *argv[]) { log_notice("Reexecuting."); goto finish; + case MANAGER_REBOOT: + case MANAGER_POWEROFF: + case MANAGER_HALT: + case MANAGER_KEXEC: { + static const char * const table[_MANAGER_EXIT_CODE_MAX] = { + [MANAGER_REBOOT] = "reboot", + [MANAGER_POWEROFF] = "poweroff", + [MANAGER_HALT] = "halt", + [MANAGER_KEXEC] = "kexec" + }; + + assert_se(shutdown_verb = table[m->exit_code]); + + log_notice("Shutting down."); + goto finish; + } + default: assert_not_reached("Unknown exit code."); } @@ -1206,6 +1229,17 @@ finish: if (fds) fdset_free(fds); + if (shutdown_verb) { + const char * command_line[] = { + SYSTEMD_SHUTDOWN_BINARY_PATH, + shutdown_verb, + NULL + }; + + execv(SYSTEMD_SHUTDOWN_BINARY_PATH, (char **) command_line); + log_error("Failed to execute shutdown binary, freezing: %m"); + } + if (getpid() == 1) freeze();