ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit ce59961f192a766349187fabfd332b97d2ae146d
parent d9aaa0f501c2612d825ea6787e03c34b2badd1fb
Author: sin <sin@2f30.org>
Date:   Sun,  6 Jul 2014 21:08:19 +0100

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.

Diffstat:
Mrespawn.c | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/respawn.c b/respawn.c @@ -7,6 +7,7 @@ #include <errno.h> #include <fcntl.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -14,6 +15,15 @@ #include "util.h" static void +sigterm(int sig) +{ + if (sig == SIGTERM) { + kill(0, SIGTERM); + _exit(EXIT_SUCCESS); + } +} + +static void usage(void) { eprintf("usage: respawn [-l fifo] [-d N] cmd [args...]\n"); @@ -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]);