diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2011-02-20 21:09:07 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2011-02-20 21:09:07 +0100 |
commit | 5622dde36deb414ab372a2d767584eaca73aec46 (patch) | |
tree | f78d2d07f0a75c116b7db6f8d72c9ba65f674ec2 /src | |
parent | 80f7378c5d8aebabcad7d0448df1263e37b3acd2 (diff) |
systemctl: shutdown(8) - call kexec if kexec kernel is loaded
Diffstat (limited to 'src')
-rw-r--r-- | src/systemctl.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/systemctl.c b/src/systemctl.c index 4a8b9a196f..eacc63e94d 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -4668,6 +4668,18 @@ static int parse_time_spec(const char *t, usec_t *_u) { return 0; } +static bool kexec_loaded(void) { + bool loaded = false; + char *s; + + if (read_one_line_file("/sys/kernel/kexec_loaded", &s) >= 0) { + if (s[0] == '1') + loaded = true; + free(s); + } + return loaded; +} + static int shutdown_parse_argv(int argc, char *argv[]) { enum { @@ -4705,7 +4717,10 @@ static int shutdown_parse_argv(int argc, char *argv[]) { break; case 'r': - arg_action = ACTION_REBOOT; + if (kexec_loaded()) + arg_action = ACTION_KEXEC; + else + arg_action = ACTION_REBOOT; break; case 'h': @@ -4898,7 +4913,10 @@ static int parse_argv(int argc, char *argv[]) { arg_action = ACTION_POWEROFF; return halt_parse_argv(argc, argv); } else if (strstr(program_invocation_short_name, "reboot")) { - arg_action = ACTION_REBOOT; + if (kexec_loaded()) + arg_action = ACTION_KEXEC; + else + arg_action = ACTION_REBOOT; return halt_parse_argv(argc, argv); } else if (strstr(program_invocation_short_name, "shutdown")) { arg_action = ACTION_POWEROFF; @@ -5498,6 +5516,7 @@ int main(int argc, char*argv[]) { case ACTION_HALT: case ACTION_POWEROFF: case ACTION_REBOOT: + case ACTION_KEXEC: r = halt_main(bus); break; |