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.
This commit is contained in:
Joris Vink 2015-05-07 13:03:10 +02:00
parent 384bc8fdd6
commit b0947b73d9
4 changed files with 18 additions and 9 deletions

View File

@ -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

View File

@ -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) */

View File

@ -253,7 +253,7 @@ struct kore_module {
void *handle;
char *path;
char *onload;
void (*ocb)(int);
int (*ocb)(int);
time_t mtime;

View File

@ -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);