kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 01cc981632e8521f0f51d694f957980ecd06e27a
parent d8ff8e2c18169e961a794a6f0f3194f1cfb324ab
Author: Joris Vink <joris@coders.se>
Date:   Fri, 17 Jan 2020 21:48:55 +0100

Improve waiting on workers to exit take 2.

Keep track of what workers are running and account for those when things
exit. Somewhat reverts the entire last commit, that was the wrong approach.

Diffstat:
include/kore/kore.h | 1+
src/worker.c | 24+++++++++++++-----------
2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/include/kore/kore.h b/include/kore/kore.h @@ -447,6 +447,7 @@ struct kore_alog_header { struct kore_worker { u_int16_t id; u_int16_t cpu; + int running; #if defined(__linux__) int tracing; #endif diff --git a/src/worker.c b/src/worker.c @@ -177,6 +177,7 @@ kore_worker_spawn(u_int16_t idx, u_int16_t id, u_int16_t cpu) kw->cpu = cpu; kw->has_lock = 0; kw->active_hdlr = NULL; + kw->running = 1; if (socketpair(AF_UNIX, SOCK_STREAM, 0, kw->pipe) == -1) fatal("socketpair(): %s", errno_s); @@ -221,25 +222,24 @@ kore_worker_shutdown(void) for (;;) { for (idx = 0; idx < worker_count; idx++) { kw = WORKER(idx); + if (kw->running == 0) + continue; + if (kw->pid != 0) { pid = waitpid(kw->pid, &status, 0); - if (pid == -1) { - if (errno == ECHILD) - kw->pid = 0; + if (pid == -1) continue; - } #if defined(__linux__) kore_seccomp_trace(kw->pid, status); #endif - if (WIFEXITED(status)) { - kw->pid = 0; + kw->pid = 0; + kw->running = 0; - if (!kore_quiet) { - kore_log(LOG_NOTICE, - "worker %d exited", kw->id); - } + if (!kore_quiet) { + kore_log(LOG_NOTICE, + "worker %d exited", kw->id); } } } @@ -247,8 +247,10 @@ kore_worker_shutdown(void) done = 0; for (idx = 0; idx < worker_count; idx++) { kw = WORKER(idx); - if (kw->pid == 0) + if (kw->running == 0) { done++; + continue; + } } if (done == worker_count)