summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-01-05 16:02:14 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2017-01-05 16:02:14 +0100
commitc4febe1f6ca043276a917f6f24e54b0307d64c34 (patch)
treeaa8f282e2fe671cfc1e96201f42b58f409318fad
parentb8bcf15d19e77a6b255c11e8d95fa655a3f7c3eb (diff)
First step for grouping processes
Actually make afb-daemon the process group leader. Change-Id: I01ca7bb027416e2446cfa322b69684da4db852e2 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/main.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 9fbbb072..d2a08422 100644
--- a/src/main.c
+++ b/src/main.c
@@ -47,6 +47,12 @@
#include <afb/afb-binding.h>
+/*
+ if SELF_PGROUP == 0 the launched command is the group leader
+ if SELF_PGROUP != 0 afb-daemon is the group leader
+*/
+#define SELF_PGROUP 1
+
static struct afb_config *config;
static pid_t childpid;
@@ -92,9 +98,11 @@ static void start_list(struct afb_config_list *list,
+--------------------------------------------------------- */
static void exit_handler()
{
- if (childpid > 0)
+ /* TODO: check whether using SIGHUP isn't better */
+ if (SELF_PGROUP)
+ killpg(0, SIGKILL);
+ else if (childpid > 0)
killpg(childpid, SIGKILL);
- /* TODO: check whether using SIGHUP isn't better */
}
/*----------------------------------------------------------
@@ -239,7 +247,8 @@ static void on_sigchld(int signum, siginfo_t *info, void *uctx)
case CLD_KILLED:
case CLD_DUMPED:
childpid = 0;
- killpg(info->si_pid, SIGKILL);
+ if (!SELF_PGROUP)
+ killpg(info->si_pid, SIGKILL);
waitpid(info->si_pid, NULL, 0);
exit(0);
}
@@ -313,6 +322,9 @@ static int execute_command()
if (!config->exec || !config->exec[0])
return 0;
+ if (SELF_PGROUP)
+ setpgid(0, 0);
+
/* install signal handler */
memset(&siga, 0, sizeof siga);
siga.sa_sigaction = on_sigchld;
@@ -326,7 +338,8 @@ static int execute_command()
/* makes arguments */
if (instanciate_command_args() >= 0) {
- setpgid(0, 0);
+ if (!SELF_PGROUP)
+ setpgid(0, 0);
execv(config->exec[0], config->exec);
ERROR("can't launch %s: %m", config->exec[0]);
}