forked from mirrors/kore
allow onload to be given in the config file.
onload specifies what function in your module to call when the module has been loaded or reloaded.
This commit is contained in:
parent
ec5ac40706
commit
cf6a6550f0
|
@ -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);
|
||||
|
|
17
src/config.c
17
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)
|
||||
{
|
||||
|
|
17
src/module.c
17
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue