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 8812d6989a0d837c562dec4cffb6261691caa6b8
parent 9c4e7c888fb9a1b3db2e4edf1037cb3bc0140d69
Author: Joris Vink <joris@coders.se>
Date:   Thu, 31 Jul 2014 13:27:04 +0200

Allow Kore to be started in foreground mode (-f)

Sending SIGINT or Ctrl-c will reap all workers and
exit again. Useful for development.

Diffstat:
src/kore.c | 40+++++++++++++++++++++++++++++++---------
src/worker.c | 7++++++-
2 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/src/kore.c b/src/kore.c @@ -28,6 +28,7 @@ u_int8_t nlisteners; struct passwd *pw = NULL; pid_t kore_pid = -1; u_int16_t cpu_count = 1; +int foreground = 0; int kore_debug = 0; int skip_chroot = 0; u_int8_t worker_count = 0; @@ -48,7 +49,7 @@ static void kore_server_sslstart(void); static void usage(void) { - fprintf(stderr, "Usage: kore [-c config] [-dnv]\n"); + fprintf(stderr, "Usage: kore [-c config] [-dfnv]\n"); exit(1); } @@ -74,7 +75,7 @@ main(int argc, char *argv[]) int ch; struct listener *l; - while ((ch = getopt(argc, argv, "c:dnv")) != -1) { + while ((ch = getopt(argc, argv, "c:dfnv")) != -1) { switch (ch) { case 'c': config_file = optarg; @@ -86,6 +87,9 @@ main(int argc, char *argv[]) printf("kore not compiled with debug support\n"); #endif break; + case 'f': + foreground = 1; + break; case 'n': skip_chroot = 1; break; @@ -121,6 +125,11 @@ main(int argc, char *argv[]) signal(SIGHUP, kore_signal); signal(SIGQUIT, kore_signal); + if (foreground) + signal(SIGINT, kore_signal); + else + signal(SIGINT, SIG_IGN); + kore_server_start(); kore_log(LOG_NOTICE, "server shutting down"); @@ -246,20 +255,23 @@ kore_signal(int sig) static void kore_server_sslstart(void) { +#if !defined(KORE_BENCHMARK) kore_debug("kore_server_sslstart()"); SSL_library_init(); SSL_load_error_strings(); +#endif } static void kore_server_start(void) { + int quit; u_int64_t now, last_cb_run; kore_mem_free(runas_user); - if (daemon(1, 1) == -1) + if (foreground == 0 && daemon(1, 1) == -1) fatal("cannot daemon(): %s", errno_s); kore_pid = getpid(); @@ -276,18 +288,28 @@ kore_server_start(void) kore_platform_proctitle("kore [parent]"); kore_worker_init(); + quit = 0; now = kore_time_ms(); last_cb_run = now; - for (;;) { + while (quit != 1) { if (sig_recv != 0) { - if (sig_recv == SIGHUP || sig_recv == SIGQUIT) { + switch (sig_recv) { + case SIGHUP: kore_worker_dispatch_signal(sig_recv); - if (sig_recv == SIGHUP) - kore_module_reload(0); - if (sig_recv == SIGQUIT) - break; + kore_module_reload(0); + break; + case SIGINT: + case SIGQUIT: + quit = 1; + kore_worker_dispatch_signal(sig_recv); + continue; + default: + kore_log(LOG_NOTICE, + "no action taken for signal %d", sig_recv); + break; } + sig_recv = 0; } diff --git a/src/worker.c b/src/worker.c @@ -221,6 +221,11 @@ kore_worker_entry(struct kore_worker *kw) signal(SIGQUIT, kore_signal); signal(SIGPIPE, SIG_IGN); + if (foreground) + signal(SIGINT, kore_signal); + else + signal(SIGINT, SIG_IGN); + net_init(); http_init(); kore_connection_init(); @@ -249,7 +254,7 @@ kore_worker_entry(struct kore_worker *kw) if (sig_recv != 0) { if (sig_recv == SIGHUP) kore_module_reload(1); - else if (sig_recv == SIGQUIT) + else if (sig_recv == SIGQUIT || sig_recv == SIGINT) quit = 1; sig_recv = 0; }