commit dbd74c455194b473506ac163c9764564a36a0fd3
parent 8ba29104ebe2b42be3edd2c9175caf89a8e58e3c
Author: Joris Vink <joris@coders.se>
Date: Sun, 29 Jun 2014 21:15:23 +0200
Don't call module onloads until after everything is initialized.
This means the onload functions for a module are now called
after a worker has started and never from the parent ever again.
Diffstat:
4 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/includes/kore.h b/includes/kore.h
@@ -413,7 +413,8 @@ void *kore_mem_find(void *, size_t, void *, u_int32_t);
void kore_domain_init(void);
int kore_domain_new(char *);
void kore_module_init(void);
-void kore_module_reload(void);
+void kore_module_reload(int);
+void kore_module_onload(void);
int kore_module_loaded(void);
void kore_domain_closelogs(void);
void *kore_module_getsym(char *);
diff --git a/src/kore.c b/src/kore.c
@@ -257,7 +257,7 @@ kore_server_start(void)
if (sig_recv == SIGHUP || sig_recv == SIGQUIT) {
kore_worker_dispatch_signal(sig_recv);
if (sig_recv == SIGHUP)
- kore_module_reload();
+ kore_module_reload(0);
if (sig_recv == SIGQUIT)
break;
}
diff --git a/src/module.c b/src/module.c
@@ -55,7 +55,6 @@ kore_module_load(char *path, char *onload)
module->ocb = dlsym(module->handle, onload);
if (module->ocb == NULL)
fatal("%s: onload '%s' not present", path, onload);
- module->ocb(KORE_MODULE_LOAD);
}
if (kore_cb_name != NULL && kore_cb == NULL)
@@ -65,7 +64,20 @@ kore_module_load(char *path, char *onload)
}
void
-kore_module_reload(void)
+kore_module_onload(void)
+{
+ struct kore_module *module;
+
+ TAILQ_FOREACH(module, &modules, list) {
+ if (module->ocb == NULL)
+ continue;
+
+ module->ocb(KORE_MODULE_LOAD);
+ }
+}
+
+void
+kore_module_reload(int cbs)
{
struct stat st;
struct kore_domain *dom;
@@ -84,7 +96,7 @@ kore_module_reload(void)
if (module->mtime == st.st_mtime)
continue;
- if (module->ocb != NULL)
+ if (module->ocb != NULL && cbs == 1)
module->ocb(KORE_MODULE_UNLOAD);
module->mtime = st.st_mtime;
@@ -102,7 +114,8 @@ kore_module_reload(void)
module->path, module->onload);
}
- module->ocb(KORE_MODULE_LOAD);
+ if (cbs)
+ module->ocb(KORE_MODULE_LOAD);
}
if (kore_cb_name != NULL && kore_cb == NULL)
diff --git a/src/worker.c b/src/worker.c
@@ -239,11 +239,12 @@ kore_worker_entry(struct kore_worker *kw)
worker->accept_treshold = worker_max_connections / 10;
kore_log(LOG_NOTICE, "worker %d started (cpu#%d)", kw->id, kw->cpu);
+ kore_module_onload();
for (;;) {
if (sig_recv != 0) {
if (sig_recv == SIGHUP)
- kore_module_reload();
+ kore_module_reload(1);
else if (sig_recv == SIGQUIT)
quit = 1;
sig_recv = 0;