From a452abeb09720ae3640de5768a3880ca2ddd05a8 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 17 Sep 2015 04:27:16 +0200 Subject: move children to own process group and kill the whole group --- src/sysexec.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/sysexec.c b/src/sysexec.c index ae9a40c..782b10d 100644 --- a/src/sysexec.c +++ b/src/sysexec.c @@ -258,7 +258,9 @@ void child_list_kill_oldest(child_list_t* list) if(!list || !list->first_) return; - kill(list->first_->pid_, SIGKILL); + pid_t pgid = getpgid(list->first_->pid_); + log_printf(DEBUG, "sending KILL signal to child %d with process group id %d", list->first_->pid_, pgid); + kill(pgid * -1, SIGKILL); } int rh_exec(const char* script, char* const argv[], char* const evp[], child_list_t* child_lst, options_t* opt) @@ -297,14 +299,19 @@ int rh_exec_child(child_list_element_t* child) return -1; } - pid_t pid; - pid = fork(); + pid_t pid = fork(); if(pid == -1) { log_printf(ERROR, "executing script '%s' failed: fork() error: %s", child->script_, strerror(errno)); return -1; } if(!pid) { + pid_t pgid = setsid(); + if(pgid == -1) { + log_printf(ERROR, "executing script '%s' failed: setsid() error: %s", child->script_, strerror(errno)); + exit(-1); + } + int fd; for (fd=getdtablesize();fd>=0;--fd) // close all file descriptors if(fd != pipefd[1]) close(fd); -- cgit v1.2.3