From ce59961f192a766349187fabfd332b97d2ae146d Mon Sep 17 00:00:00 2001 From: sin Date: Sun, 6 Jul 2014 21:08:19 +0100 Subject: [PATCH] respawn: kill child process upon SIGTERM We might revisit this and be more strict i.e. kill the child process even if it is in a new process session/group. For now this is probably a good enough balance. This patch changes the existing semantics of respawn, the child process is now part of the same process session as respawn. --- respawn.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/respawn.c b/respawn.c index 2d03298..4ca657f 100644 --- a/respawn.c +++ b/respawn.c @@ -7,12 +7,22 @@ #include #include +#include #include #include #include #include "util.h" +static void +sigterm(int sig) +{ + if (sig == SIGTERM) { + kill(0, SIGTERM); + _exit(EXIT_SUCCESS); + } +} + static void usage(void) { @@ -48,6 +58,8 @@ main(int argc, char *argv[]) if (fifo && delay > 0) usage(); + signal(SIGTERM, sigterm); + if (fifo) { fd = open(fifo, O_RDWR | O_NONBLOCK); if (fd < 0) @@ -74,8 +86,6 @@ main(int argc, char *argv[]) eprintf("fork:"); switch (pid) { case 0: - if (setsid() < 0) - eprintf("setsid:"); execvp(argv[0], argv); savederrno = errno; weprintf("execvp %s:", argv[0]);