Merge pull request #27212 from DaanDeMeyer/notify-exit

core: Propagate exit status via notify socket when running in VM
This commit is contained in:
Mike Yuan
2023-04-13 01:12:03 +08:00
committed by GitHub
4 changed files with 21 additions and 0 deletions
+7
View File
@@ -170,6 +170,13 @@
<literal>BUSERROR=org.freedesktop.DBus.Error.TimedOut</literal></para></listitem>
</varlistentry>
<varlistentry>
<term>EXIT_STATUS=…</term>
<listitem><para>If a service exits, the return value of its <function>main()</function> function.
</para></listitem>
</varlistentry>
<varlistentry>
<term>MAINPID=…</term>
+7
View File
@@ -3096,6 +3096,9 @@ finish:
__lsan_do_leak_check();
#endif
if (r < 0)
(void) sd_notifyf(0, "ERRNO=%i", -r);
/* Try to invoke the shutdown binary unless we already failed.
* If we failed above, we want to freeze after finishing cleanup. */
if (arg_runtime_scope == RUNTIME_SCOPE_SYSTEM &&
@@ -3105,6 +3108,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);
+1
View File
@@ -21,6 +21,7 @@
r = impl; \
if (r < 0) \
(void) sd_notifyf(0, "ERRNO=%i", -r); \
(void) sd_notifyf(0, "EXIT_STATUS=%i", ret); \
ask_password_agent_close(); \
polkit_agent_close(); \
pager_close(); \
+6
View 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.");