[hackers] [ubase] respawn: kill child process upon SIGTERM || sin
commit ce59961f192a766349187fabfd332b97d2ae146d
Author: sin <sin_AT_2f30.org>
Date: Sun Jul 6 21:08:19 2014 +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.
diff --git a/respawn.c b/respawn.c
index 2d03298..4ca657f 100644
--- a/respawn.c
+++ b/respawn.c
_AT_@ -7,6 +7,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
_AT_@ -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...]
");
_AT_@ -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)
_AT_@ -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]);
Received on Sun Jul 06 2014 - 22:15:43 CEST
This archive was generated by hypermail 2.3.0
: Sun Jul 06 2014 - 22:24:08 CEST