]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: Propagate exit status via notify socket when running in VM
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 11 Apr 2023 11:17:13 +0000 (13:17 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 12 Apr 2023 13:03:43 +0000 (15:03 +0200)
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.

src/core/main.c
src/shutdown/shutdown.c

index 9588c625b28dfeddb6feb9489cb4c359ce3f97fc..e49f6ab094020e6006df2096daef727a4ae89e17 100644 (file)
@@ -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);
 
index a8248901ce6c9c41fc25fee55c855966973fc70d..b1dac20c692da534794fd64682bbf202febf6e38 100644 (file)
@@ -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.");