From 8702378c745980db947bb8d93f3fb2502f142055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 25 Oct 2020 16:06:16 +0100 Subject: [PATCH] module/script: restore signal handlers and mask in child process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the issue where `killpg()` didn’t manage to kill the sub-process tree. --- modules/script.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/script.c b/modules/script.c index 25323eb..5c04e70 100644 --- a/modules/script.c +++ b/modules/script.c @@ -377,6 +377,20 @@ run(struct module *mod) if (pid == 0) { /* Child */ + /* Restore signal handlers */ + + sigset_t mask; + sigemptyset(&mask); + + const struct sigaction sa = {.sa_handler = SIG_DFL}; + if (sigaction(SIGINT, &sa, NULL) < 0 || + sigaction(SIGTERM, &sa, NULL) < 0 || + sigaction(SIGCHLD, &sa, NULL) < 0 || + sigprocmask(SIG_SETMASK, &mask, NULL) < 0) + { + goto fail; + } + setpgid(0, 0); /* Close pipe read ends */