From: Lennart Poettering Date: Fri, 17 May 2019 08:17:06 +0000 (+0200) Subject: main-func: send main exit code to parent via sd_notify() on exit X-Git-Tag: v245-rc1~314^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14218%2Fhead;p=thirdparty%2Fsystemd.git main-func: send main exit code to parent via sd_notify() on exit So far we silently convert negative return values from run() as EXIT_FAILURE, which is how UNIX expects it. In many cases it would be very useful for the caller to retrieve the actual error number we exit with. Let's generically return that via sd_notify()'s ERRNO= attribute. This means callers can set $NOTIFY_SOCKET and get the actual error number delivered at their doorstep just like that. --- diff --git a/src/shared/main-func.h b/src/shared/main-func.h index 6c26cb9fb56..cf23ad450c5 100644 --- a/src/shared/main-func.h +++ b/src/shared/main-func.h @@ -3,6 +3,8 @@ #include +#include "sd-daemon.h" + #include "pager.h" #include "selinux-util.h" #include "spawn-ask-password-agent.h" @@ -16,6 +18,8 @@ save_argc_argv(argc, argv); \ intro; \ r = impl; \ + if (r < 0) \ + (void) sd_notifyf(0, "ERRNO=%i", -r); \ ask_password_agent_close(); \ polkit_agent_close(); \ pager_close(); \