From b0947b73d9b52646a48e47251b7be910d9fe74f9 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Thu, 7 May 2015 13:03:10 +0200 Subject: [PATCH] Let modules decide if they want to be reloaded. At times it seems relevant that worker their modules should not be reloaded when receiving a SIGHUP. Developers can now control this by returning anything else but KORE_RESULT_OK from their initialization methods. The parent module will always be reloaded. --- examples/generic/src/example.c | 6 ++++-- examples/pgsql/src/pgsql.c | 6 ++++-- includes/kore.h | 2 +- src/module.c | 13 +++++++++---- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/examples/generic/src/example.c b/examples/generic/src/example.c index 4530382..8116a4f 100644 --- a/examples/generic/src/example.c +++ b/examples/generic/src/example.c @@ -19,7 +19,7 @@ #include "assets.h" -void example_load(int); +int example_load(int); int serve_style_css(struct http_request *); int serve_index(struct http_request *); @@ -47,7 +47,7 @@ char *b64tests[] = { NULL }; -void +int example_load(int state) { switch (state) { @@ -61,6 +61,8 @@ example_load(int state) kore_log(LOG_NOTICE, "state %d unknown!", state); break; } + + return (KORE_RESULT_OK); } int diff --git a/examples/pgsql/src/pgsql.c b/examples/pgsql/src/pgsql.c index 026eaf0..49f1078 100644 --- a/examples/pgsql/src/pgsql.c +++ b/examples/pgsql/src/pgsql.c @@ -42,7 +42,7 @@ #define REQ_STATE_ERROR 3 #define REQ_STATE_DONE 4 -void init(int); +int init(int); int page(struct http_request *); static int request_perform_query(struct http_request *); @@ -66,11 +66,13 @@ struct rstate { }; /* Called when our module is loaded (see config) */ -void +int init(int state) { /* Set our connection string. */ pgsql_conn_string = "host=/var/run/postgresql/ dbname=test"; + + return (KORE_RESULT_OK); } /* Page handler entry point (see config) */ diff --git a/includes/kore.h b/includes/kore.h index 8775565..c819f09 100644 --- a/includes/kore.h +++ b/includes/kore.h @@ -253,7 +253,7 @@ struct kore_module { void *handle; char *path; char *onload; - void (*ocb)(int); + int (*ocb)(int); time_t mtime; diff --git a/src/module.c b/src/module.c index 3e72212..54ad49c 100644 --- a/src/module.c +++ b/src/module.c @@ -69,7 +69,7 @@ kore_module_onload(void) if (module->ocb == NULL) continue; - module->ocb(KORE_MODULE_LOAD); + (void)module->ocb(KORE_MODULE_LOAD); } } @@ -91,8 +91,13 @@ kore_module_reload(int cbs) if (module->mtime == st.st_mtime) continue; - if (module->ocb != NULL && cbs == 1) - module->ocb(KORE_MODULE_UNLOAD); + if (module->ocb != NULL && cbs == 1) { + if (!module->ocb(KORE_MODULE_UNLOAD)) { + kore_log(LOG_NOTICE, + "not reloading %s", module->path); + continue; + } + } module->mtime = st.st_mtime; if (dlclose(module->handle)) @@ -110,7 +115,7 @@ kore_module_reload(int cbs) } if (cbs) - module->ocb(KORE_MODULE_LOAD); + (void)module->ocb(KORE_MODULE_LOAD); } kore_log(LOG_NOTICE, "reloaded '%s' module", module->path);