summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-09-17 04:27:16 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-09-17 04:27:16 +0200
commita452abeb09720ae3640de5768a3880ca2ddd05a8 (patch)
treed396b83abaebc492cd03b6138b45f5aa10ef30f7
parentimplemented children policies (diff)
move children to own process group and kill the whole group
-rw-r--r--src/sysexec.c13
1 files 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);