From e51103181b5519f33db773e68a83561bc16c1c39 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 21 Aug 2022 20:10:23 +0100 Subject: [PATCH] prefork-interp: fix exit status and signal handling Signed-off-by: Ian Jackson --- cprogs/prefork-interp.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cprogs/prefork-interp.c b/cprogs/prefork-interp.c index fe02827..3a999ef 100644 --- a/cprogs/prefork-interp.c +++ b/cprogs/prefork-interp.c @@ -448,7 +448,7 @@ static void propagate_exit_status(int status, const char *what) { int r; if (WIFEXITED(status)) { - _exit(status); + _exit(WEXITSTATUS(status)); } if (WIFSIGNALED(status)) { @@ -458,22 +458,25 @@ static void propagate_exit_status(int status, const char *what) { if (! WCOREDUMP(status) && (sig == SIGINT || + sig == SIGTERM || sig == SIGHUP || sig == SIGPIPE || sig == SIGKILL)) { struct sigaction sa; FILLZERO(sa); sa.sa_handler = SIG_DFL; - r = sigaction(sig, &sa, 0); - if (r) diee("failed to reset signal handler while propagating %s", - signame); - - sigset_t sset; - sigemptyset(&sset); - sigaddset(&sset, sig); - r = sigprocmask(SIG_UNBLOCK, &sset, 0); - if (r) diee("failed to reset signal block while propagating %s", - signame); + if (sig != SIGKILL) { + r = sigaction(sig, &sa, 0); + if (r) diee("failed to reset signal handler while propagating %s", + signame); + + sigset_t sset; + sigemptyset(&sset); + sigaddset(&sset, sig); + r = sigprocmask(SIG_UNBLOCK, &sset, 0); + if (r) diee("failed to reset signal block while propagating %s", + signame); + } raise(sig); die("unexpectedly kept running after raising (to propagate) %s", @@ -743,7 +746,8 @@ static const char *read_greeting(void) { char got_magic[sizeof(header_magic)]; if (protocol_read_maybe(&got_magic, sizeof(got_magic)) < 0) - return "initial monitor process quit"; + return "initial monitor process quit" + " (maybe script didn't call preform_initialisation_complete?)"; if (memcmp(got_magic, header_magic, sizeof(header_magic))) die("got unexpected protocol magic 0x%02x%02x%02x%02x", -- 2.30.2