mirror of https://git.kore.io/kore.git
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:
parent
384bc8fdd6
commit
b0947b73d9
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
#include "assets.h"
|
#include "assets.h"
|
||||||
|
|
||||||
void example_load(int);
|
int example_load(int);
|
||||||
|
|
||||||
int serve_style_css(struct http_request *);
|
int serve_style_css(struct http_request *);
|
||||||
int serve_index(struct http_request *);
|
int serve_index(struct http_request *);
|
||||||
|
@ -47,7 +47,7 @@ char *b64tests[] = {
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
int
|
||||||
example_load(int state)
|
example_load(int state)
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
@ -61,6 +61,8 @@ example_load(int state)
|
||||||
kore_log(LOG_NOTICE, "state %d unknown!", state);
|
kore_log(LOG_NOTICE, "state %d unknown!", state);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (KORE_RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
#define REQ_STATE_ERROR 3
|
#define REQ_STATE_ERROR 3
|
||||||
#define REQ_STATE_DONE 4
|
#define REQ_STATE_DONE 4
|
||||||
|
|
||||||
void init(int);
|
int init(int);
|
||||||
int page(struct http_request *);
|
int page(struct http_request *);
|
||||||
|
|
||||||
static int request_perform_query(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) */
|
/* Called when our module is loaded (see config) */
|
||||||
void
|
int
|
||||||
init(int state)
|
init(int state)
|
||||||
{
|
{
|
||||||
/* Set our connection string. */
|
/* Set our connection string. */
|
||||||
pgsql_conn_string = "host=/var/run/postgresql/ dbname=test";
|
pgsql_conn_string = "host=/var/run/postgresql/ dbname=test";
|
||||||
|
|
||||||
|
return (KORE_RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Page handler entry point (see config) */
|
/* Page handler entry point (see config) */
|
||||||
|
|
|
@ -253,7 +253,7 @@ struct kore_module {
|
||||||
void *handle;
|
void *handle;
|
||||||
char *path;
|
char *path;
|
||||||
char *onload;
|
char *onload;
|
||||||
void (*ocb)(int);
|
int (*ocb)(int);
|
||||||
|
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
|
|
||||||
|
|
13
src/module.c
13
src/module.c
|
@ -69,7 +69,7 @@ kore_module_onload(void)
|
||||||
if (module->ocb == NULL)
|
if (module->ocb == NULL)
|
||||||
continue;
|
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)
|
if (module->mtime == st.st_mtime)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (module->ocb != NULL && cbs == 1)
|
if (module->ocb != NULL && cbs == 1) {
|
||||||
module->ocb(KORE_MODULE_UNLOAD);
|
if (!module->ocb(KORE_MODULE_UNLOAD)) {
|
||||||
|
kore_log(LOG_NOTICE,
|
||||||
|
"not reloading %s", module->path);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module->mtime = st.st_mtime;
|
module->mtime = st.st_mtime;
|
||||||
if (dlclose(module->handle))
|
if (dlclose(module->handle))
|
||||||
|
@ -110,7 +115,7 @@ kore_module_reload(int cbs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cbs)
|
if (cbs)
|
||||||
module->ocb(KORE_MODULE_LOAD);
|
(void)module->ocb(KORE_MODULE_LOAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
kore_log(LOG_NOTICE, "reloaded '%s' module", module->path);
|
kore_log(LOG_NOTICE, "reloaded '%s' module", module->path);
|
||||||
|
|
Loading…
Reference in New Issue