summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorFabiano Fidencio <fidencio@profusion.mobi>2010-10-14 00:52:26 +0200
committerLennart Poettering <lennart@poettering.net>2010-10-14 00:52:26 +0200
commitb9080b03a98252ccccb332d0c892403b8b841916 (patch)
treef9c9ac7778fbb401065e9bb7383358eecc1a1d90 /src/main.c
parente61cd18666de1c26d41b4f189c8fac8a0bf8ee61 (diff)
manager: hookup execution of systemd-shutdown helper
(Modified by Lennart Poettering)
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 15bd2e4d15..88ba09d43e 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
@@ -1127,6 +1128,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 +1224,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();