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 b5958f7d7d7568cd59c8e1d60d644e657b3cc1ce
parent c2c4e55149683be379433efe2339868811dab0be
Author: Joris Vink <joris@coders.se>
Date:   Thu, 18 Oct 2018 17:18:41 +0200

Add kore_parent_daemonized().

This is called for single binaries after the parent
process has called daemon().

Also fix kore_parent_configure() for !single binaries.

Diffstat:
include/kore/kore.h | 1+
src/kore.c | 27+++++++++++++++++++--------
src/utils.c | 4+++-
3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/include/kore/kore.h b/include/kore/kore.h @@ -807,6 +807,7 @@ void kore_keymgr_run(void); void kore_keymgr_cleanup(int); void kore_worker_configure(void); +void kore_parent_daemonized(void); void kore_parent_configure(int, char **); #if defined(__cplusplus) diff --git a/src/kore.c b/src/kore.c @@ -55,9 +55,9 @@ extern char *__progname; static void usage(void); static void version(void); -static void kore_server_start(void); static void kore_write_kore_pid(void); static void kore_server_sslstart(void); +static void kore_server_start(int, char *[]); static void usage(void) @@ -119,7 +119,9 @@ version(void) int main(int argc, char *argv[]) { +#if defined(KORE_SINGLE_BINARY) struct kore_runtime_call *rcall; +#endif int ch, flags; flags = 0; @@ -196,11 +198,13 @@ main(int argc, char *argv[]) kore_module_load(NULL, NULL, KORE_MODULE_NATIVE); kore_parse_config(); +#if defined(KORE_SINGLE_BINARY) rcall = kore_runtime_getcall("kore_parent_configure"); if (rcall != NULL) { kore_runtime_configure(rcall, argc, argv); kore_free(rcall); } +#endif kore_platform_init(); @@ -216,7 +220,7 @@ main(int argc, char *argv[]) #endif kore_signal_setup(); - kore_server_start(); + kore_server_start(argc, argv); kore_log(LOG_NOTICE, "server shutting down"); kore_worker_shutdown(); @@ -547,16 +551,23 @@ kore_server_sslstart(void) } static void -kore_server_start(void) +kore_server_start(int argc, char *argv[]) { u_int32_t tmp; int quit; -#if !defined(KORE_SINGLE_BINARY) struct kore_runtime_call *rcall; -#endif - if (foreground == 0 && daemon(1, 1) == -1) - fatal("cannot daemon(): %s", errno_s); + if (foreground == 0) { + if (daemon(1, 0) == -1) + fatal("cannot daemon(): %s", errno_s); +#if defined(KORE_SINGLE_BINARY) + rcall = kore_runtime_getcall("kore_parent_daemonized"); + if (rcall != NULL) { + kore_runtime_execute(rcall); + kore_free(rcall); + } +#endif + } kore_pid = getpid(); kore_write_kore_pid(); @@ -577,7 +588,7 @@ kore_server_start(void) #if !defined(KORE_SINGLE_BINARY) rcall = kore_runtime_getcall("kore_parent_configure"); if (rcall != NULL) { - kore_runtime_execute(rcall); + kore_runtime_configure(rcall, argc, argv); kore_free(rcall); } #endif diff --git a/src/utils.c b/src/utils.c @@ -623,7 +623,9 @@ fatalx(const char *fmt, ...) { va_list args; - kore_msg_send(KORE_MSG_PARENT, KORE_MSG_SHUTDOWN, NULL, 0); + /* In case people call fatalx() from the parent context. */ + if (worker != NULL) + kore_msg_send(KORE_MSG_PARENT, KORE_MSG_SHUTDOWN, NULL, 0); va_start(args, fmt); fatal_log(fmt, args);