kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 9e12b2c6ddff30f3559e1fe613cacb7930416740
parent 3dfad1b7d63c53bae017fc449093e1a25f25354f
Author: Joris Vink <joris@coders.se>
Date:   Fri, 25 May 2018 20:49:02 +0200

Use sigaction() for signals.

Don't duplicate signal setup code between parent and worker processes.

Diffstat:
include/kore/kore.h | 1+
src/kore.c | 38++++++++++++++++++++++++++++----------
src/worker.c | 11+----------
3 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/include/kore/kore.h b/include/kore/kore.h @@ -488,6 +488,7 @@ extern struct kore_domain *primary_dom; extern struct kore_pool nb_pool; void kore_signal(int); +void kore_signal_setup(void); void kore_worker_wait(int); void kore_worker_init(void); void kore_worker_shutdown(void); diff --git a/src/kore.c b/src/kore.c @@ -217,16 +217,7 @@ main(int argc, char *argv[]) } #endif - sig_recv = 0; - signal(SIGHUP, kore_signal); - signal(SIGQUIT, kore_signal); - signal(SIGTERM, kore_signal); - - if (foreground) - signal(SIGINT, kore_signal); - else - signal(SIGINT, SIG_IGN); - + kore_signal_setup(); kore_server_start(); kore_log(LOG_NOTICE, "server shutting down"); @@ -389,6 +380,33 @@ kore_sockopt(int fd, int what, int opt) } void +kore_signal_setup(void) +{ + struct sigaction sa; + + sig_recv = 0; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = kore_signal; + + if (sigfillset(&sa.sa_mask) == -1) + fatal("sigfillset: %s", errno_s); + + if (sigaction(SIGHUP, &sa, NULL) == -1) + fatal("sigaction: %s", errno_s); + if (sigaction(SIGQUIT, &sa, NULL) == -1) + fatal("sigaction: %s", errno_s); + if (sigaction(SIGTERM, &sa, NULL) == -1) + fatal("sigaction: %s", errno_s); + + if (foreground) { + if (sigaction(SIGINT, &sa, NULL) == -1) + fatal("sigaction: %s", errno_s); + } else { + (void)signal(SIGINT, SIG_IGN); + } +} + +void kore_listener_cleanup(void) { struct listener *l; diff --git a/src/worker.c b/src/worker.c @@ -300,16 +300,7 @@ kore_worker_entry(struct kore_worker *kw) kore_pid = kw->pid; - sig_recv = 0; - signal(SIGHUP, kore_signal); - signal(SIGQUIT, kore_signal); - signal(SIGTERM, kore_signal); - signal(SIGPIPE, SIG_IGN); - - if (foreground) - signal(SIGINT, kore_signal); - else - signal(SIGINT, SIG_IGN); + kore_signal_setup(); #if !defined(KORE_NO_TLS) if (kw->id == KORE_WORKER_KEYMGR) {