commit b0947b73d9b52646a48e47251b7be910d9fe74f9
parent 384bc8fdd6a8a49a4764060617839311a1175243
Author: Joris Vink <joris@coders.se>
Date: Thu, 7 May 2015 13:03:10 +0200
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.
Diffstat:
4 files changed, 18 insertions(+), 9 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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);