diff --git a/includes/kore.h b/includes/kore.h index d1112f0..3aff42d 100644 --- a/includes/kore.h +++ b/includes/kore.h @@ -135,6 +135,7 @@ extern int server_port; extern char *server_ip; extern char *chroot_path; extern char *runas_user; +extern char *kore_module_onload; extern u_int8_t worker_count; void *kore_malloc(size_t); diff --git a/src/config.c b/src/config.c index fecf908..9d4f65d 100644 --- a/src/config.c +++ b/src/config.c @@ -40,6 +40,7 @@ static int configure_bind(char **); static int configure_load(char **); +static int configure_onload(char **); static int configure_handler(char **); static int configure_domain(char **); static int configure_chroot(char **); @@ -52,6 +53,7 @@ static struct { } config_names[] = { { "bind", configure_bind }, { "load", configure_load }, + { "onload", configure_onload }, { "static", configure_handler }, { "dynamic", configure_handler }, { "domain", configure_domain }, @@ -137,6 +139,21 @@ configure_load(char **argv) return (KORE_RESULT_OK); } +static int +configure_onload(char **argv) +{ + if (argv[1] == NULL) + return (KORE_RESULT_ERROR); + + if (kore_module_onload != NULL) { + kore_log("duplicate onload directive found"); + return (KORE_RESULT_ERROR); + } + + kore_module_onload = kore_strdup(argv[1]); + return (KORE_RESULT_OK); +} + static int configure_domain(char **argv) { diff --git a/src/module.c b/src/module.c index c0fece5..468c817 100644 --- a/src/module.c +++ b/src/module.c @@ -43,6 +43,7 @@ static void *mod_handle = NULL; static char *mod_name = NULL; static time_t mod_last_mtime = 0; +char *kore_module_onload = NULL; struct module_domain { char *domain; @@ -57,6 +58,7 @@ void kore_module_load(char *module_name) { struct stat st; + void (*onload)(void); kore_log("kore_module_load(%s)", module_name); @@ -73,6 +75,13 @@ kore_module_load(char *module_name) TAILQ_INIT(&domains); mod_name = kore_strdup(module_name); + + if (kore_module_onload != NULL) { + onload = dlsym(mod_handle, kore_module_onload); + if (onload == NULL) + fatal("onload '%s' not present", kore_module_onload); + onload(); + } } void @@ -80,6 +89,7 @@ kore_module_reload(void) { struct module_domain *dom; struct kore_module_handle *hdlr; + void (*onload)(void); if (dlclose(mod_handle)) fatal("cannot close existing module: %s", dlerror()); @@ -96,6 +106,13 @@ kore_module_reload(void) } } + if (kore_module_onload != NULL) { + onload = dlsym(mod_handle, kore_module_onload); + if (onload == NULL) + fatal("onload '%s' not present", kore_module_onload); + onload(); + } + kore_log("reloaded '%s' module", mod_name); }