diff options
Diffstat (limited to '')
-rw-r--r-- | src/shutdown/shutdown.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index b709078..d998bc5 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -333,6 +333,28 @@ static void init_watchdog(void) { } } +static void notify_supervisor(void) { + /* Notify VMM/container manager of the desired mode of reboot and the boot parameter */ + _cleanup_free_ char *reboot_parameter = NULL; + int r; + + r = read_reboot_parameter(&reboot_parameter); + if (r < 0 && r != -ENOENT) + log_debug_errno(r, "Failed to read reboot parameter, ignoring: %m"); + + if (reboot_parameter) + (void) sd_notifyf(/* unset_environment= */ false, + "EXIT_STATUS=%i\n" + "X_SYSTEMD_SHUTDOWN=%s\n" + "X_SYSTEMD_REBOOT_PARAMETER=%s", + arg_exit_code, arg_verb, reboot_parameter); + else + (void) sd_notifyf(/* unset_environment= */ false, + "EXIT_STATUS=%i\n" + "X_SYSTEMD_SHUTDOWN=%s", + arg_exit_code, arg_verb); +} + int main(int argc, char *argv[]) { static const char* const dirs[] = { SYSTEM_SHUTDOWN_PATH, @@ -387,13 +409,6 @@ int main(int argc, char *argv[]) { goto error; } - /* This is primarily useful when running systemd in a VM, as it provides the user running the VM with - * a mechanism to pick up systemd's exit status in the VM. Note that we execute this as early as - * possible since otherwise we might shut down the VM before the AF_VSOCK buffers have been flushed. - * While this doesn't guarantee the message will arrive, in practice we do enough work after this - * that the message should always arrive on the host */ - (void) sd_notifyf(0, "EXIT_STATUS=%i", arg_exit_code); - (void) cg_get_root_path(&cgroup); bool in_container = detect_container() > 0; @@ -546,7 +561,10 @@ int main(int argc, char *argv[]) { } /* We're done with the watchdog. Note that the watchdog is explicitly not stopped here. It remains - * active to guard against any issues during the rest of the shutdown sequence. */ + * active to guard against any issues during the rest of the shutdown sequence. Note that we + * explicitly close the device with disarm=false here, before releasing the rest of the watchdog + * data. */ + watchdog_close(/* disarm= */ false); watchdog_free_device(); arguments[0] = NULL; /* Filled in by execute_directories(), when needed */ @@ -589,6 +607,8 @@ int main(int argc, char *argv[]) { if (!in_container) sync_with_progress(); + notify_supervisor(); + if (streq(arg_verb, "exit")) { if (in_container) { log_info("Exiting container."); |