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.
This commit is contained in:
sin 2014-07-06 21:08:19 +01:00
parent d9aaa0f501
commit ce59961f19
1 changed files with 12 additions and 2 deletions

View File

@ -7,12 +7,22 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "util.h" #include "util.h"
static void
sigterm(int sig)
{
if (sig == SIGTERM) {
kill(0, SIGTERM);
_exit(EXIT_SUCCESS);
}
}
static void static void
usage(void) usage(void)
{ {
@ -48,6 +58,8 @@ main(int argc, char *argv[])
if (fifo && delay > 0) if (fifo && delay > 0)
usage(); usage();
signal(SIGTERM, sigterm);
if (fifo) { if (fifo) {
fd = open(fifo, O_RDWR | O_NONBLOCK); fd = open(fifo, O_RDWR | O_NONBLOCK);
if (fd < 0) if (fd < 0)
@ -74,8 +86,6 @@ main(int argc, char *argv[])
eprintf("fork:"); eprintf("fork:");
switch (pid) { switch (pid) {
case 0: case 0:
if (setsid() < 0)
eprintf("setsid:");
execvp(argv[0], argv); execvp(argv[0], argv);
savederrno = errno; savederrno = errno;
weprintf("execvp %s:", argv[0]); weprintf("execvp %s:", argv[0]);