aboutsummaryrefslogtreecommitdiffstats
path: root/src/main-afb-daemon.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2019-02-15 20:49:54 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2019-04-02 09:58:49 +0200
commit901a38c28bf3fe7cc3e58e3fad36190fbae585be (patch)
treefe2f0ed7fd1153a9a5a9006628f8864877763724 /src/main-afb-daemon.c
parent50deefa0f08b88b99748abd57560222744d2f8db (diff)
jobs: Refactor exiting jobs
The new termination function can allow the restart because it doesn't abort the waiting jobs. So after calling 'jobs_exit', all threads stop. The function 'job_start' returns. The threads that are in blocking state, i.e. in a call to 'jobs_enter' or 'jobs_call' are stopped. An error status -1 with errno=EINTR is returned in that case. But before returning, that function calls the exit handler if any. Change-Id: I85a4b1976b09b18804eb681af940531ae5ace6c3 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/main-afb-daemon.c')
-rw-r--r--src/main-afb-daemon.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/main-afb-daemon.c b/src/main-afb-daemon.c
index 4ef4b280..c2a53513 100644
--- a/src/main-afb-daemon.c
+++ b/src/main-afb-daemon.c
@@ -399,6 +399,17 @@ static struct afb_hsrv *start_http_server()
| execute_command
+--------------------------------------------------------- */
+static void wait_child_and_exit()
+{
+ pid_t pidchld = childpid;
+
+ childpid = 0;
+ if (!SELF_PGROUP)
+ killpg(pidchld, SIGKILL);
+ waitpid(pidchld, NULL, 0);
+ exit(0);
+}
+
static void on_sigchld(int signum, siginfo_t *info, void *uctx)
{
if (info->si_pid == childpid) {
@@ -406,11 +417,9 @@ static void on_sigchld(int signum, siginfo_t *info, void *uctx)
case CLD_EXITED:
case CLD_KILLED:
case CLD_DUMPED:
- childpid = 0;
- if (!SELF_PGROUP)
- killpg(info->si_pid, SIGKILL);
- waitpid(info->si_pid, NULL, 0);
- exit(0);
+ jobs_exit(wait_child_and_exit);
+ default:
+ break;
}
}
}