diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-04-11 13:17:13 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-04-12 15:03:43 +0200 |
commit | 3a89cb84a62314c3c4807016dbff4359d6988d79 (patch) | |
tree | 38c5a1b9bfcd14c64fabad9b111551e51b57d30c | |
parent | 623a00020f116d8e9c70608a9e4f7cc978342441 (diff) | |
download | systemd-3a89cb84a62314c3c4807016dbff4359d6988d79.tar.gz |
core: Propagate exit status via notify socket when running in VM
When running in a container, we can propagate the exit status of
pid1 as usual via the process exit status. This is not possible
when running in a VM. Instead, let's send EXIT_STATUS=%i via the
notify socket if one is configured. The user running the VM can then
pick up the exit status from the notify socket after the VM has shut
down.
-rw-r--r-- | src/core/main.c | 4 | ||||
-rw-r--r-- | src/shutdown/shutdown.c | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/core/main.c b/src/core/main.c index 9588c625b2..e49f6ab094 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -3105,6 +3105,10 @@ finish: error_message = "Failed to execute shutdown binary"; } + /* 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. */ + (void) sd_notifyf(0, "EXIT_STATUS=%i", retval); + watchdog_free_device(); arg_watchdog_device = mfree(arg_watchdog_device); diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index a8248901ce..b1dac20c69 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -14,6 +14,8 @@ #include <sys/stat.h> #include <unistd.h> +#include "sd-daemon.h" + #include "alloc-util.h" #include "async.h" #include "binfmt-util.h" @@ -570,6 +572,10 @@ int main(int argc, char *argv[]) { if (!in_container) sync_with_progress(); + /* 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. */ + (void) sd_notifyf(0, "EXIT_STATUS=%i", arg_exit_code); + if (streq(arg_verb, "exit")) { if (in_container) { log_info("Exiting container."); |