diff options
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/cfg_file.h | 21 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 17 |
2 files changed, 26 insertions, 12 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index ed5e1325b..8af34a63e 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -296,9 +296,14 @@ enum rspamd_action_flags { struct rspamd_action; -struct rspamd_config_post_load_script { +struct rspamd_config_cfg_lua_script { gint cbref; - struct rspamd_config_post_load_script *prev, *next; + struct rspamd_config_cfg_lua_script *prev, *next; +}; + +struct rspamd_config_post_init_script { + gint cbref; + struct rspamd_config_post_init_script *prev, *next; }; struct rspamd_lang_detector; @@ -447,9 +452,7 @@ struct rspamd_config { GList *classify_headers; /**< list of headers using for statistics */ struct module_s **compiled_modules; /**< list of compiled C modules */ - struct worker_s **compiled_workers; /**< list of compiled C modules */ - struct rspamd_config_post_load_script *finish_callbacks; /**< list of callbacks called on worker's termination */ - struct rspamd_log_format *log_format; /**< parsed log format */ + struct worker_s **compiled_workers; /**< list of compiled C modules */struct rspamd_log_format *log_format; /**< parsed log format */ gchar *log_format_str; /**< raw log format string */ struct rspamd_external_libs_ctx *libs_ctx; /**< context for external libraries */ @@ -460,7 +463,9 @@ struct rspamd_config { GHashTable *trusted_keys; /**< list of trusted public keys */ - struct rspamd_config_post_load_script *on_load; /**< list of scripts executed on config load */ + struct rspamd_config_cfg_lua_script *on_load_scripts; /**< list of scripts executed on workers load */ + struct rspamd_config_cfg_lua_script *post_init_scripts; /**< list of scripts executed on workers load */ + struct rspamd_config_cfg_lua_script *on_term_scripts; /**< list of callbacks called on worker's termination */ gchar *ssl_ca_path; /**< path to CA certs */ gchar *ssl_ciphers; /**< set of preferred ciphers */ @@ -529,13 +534,15 @@ enum rspamd_post_load_options { RSPAMD_CONFIG_INIT_VALIDATE = 1 << 3, RSPAMD_CONFIG_INIT_NO_TLD = 1 << 4, RSPAMD_CONFIG_INIT_PRELOAD_MAPS = 1 << 5, + RSPAMD_CONFIG_INIT_POST_LOAD_LUA = 1 << 6, }; #define RSPAMD_CONFIG_LOAD_ALL (RSPAMD_CONFIG_INIT_URL| \ RSPAMD_CONFIG_INIT_LIBS| \ RSPAMD_CONFIG_INIT_SYMCACHE| \ RSPAMD_CONFIG_INIT_VALIDATE| \ - RSPAMD_CONFIG_INIT_PRELOAD_MAPS) + RSPAMD_CONFIG_INIT_PRELOAD_MAPS| \ + RSPAMD_CONFIG_INIT_POST_LOAD_LUA) /** * Do post load actions for config diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 0f38cc389..3761d0861 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -245,18 +245,21 @@ rspamd_config_new (enum rspamd_config_init_flags flags) void rspamd_config_free (struct rspamd_config *cfg) { - struct rspamd_config_post_load_script *sc, *sctmp; + struct rspamd_config_cfg_lua_script *sc, *sctmp; struct rspamd_config_settings_elt *set, *stmp; struct rspamd_worker_log_pipe *lp, *ltmp; - DL_FOREACH_SAFE (cfg->finish_callbacks, sc, sctmp) { + /* Scripts part */ + DL_FOREACH_SAFE (cfg->on_term_scripts, sc, sctmp) { luaL_unref (cfg->lua_state, LUA_REGISTRYINDEX, sc->cbref); - g_free (sc); } - DL_FOREACH_SAFE (cfg->on_load, sc, sctmp) { + DL_FOREACH_SAFE (cfg->on_load_scripts, sc, sctmp) { + luaL_unref (cfg->lua_state, LUA_REGISTRYINDEX, sc->cbref); + } + + DL_FOREACH_SAFE (cfg->post_init_scripts, sc, sctmp) { luaL_unref (cfg->lua_state, LUA_REGISTRYINDEX, sc->cbref); - g_free (sc); } DL_FOREACH_SAFE (cfg->setting_ids, set, stmp) { @@ -870,6 +873,10 @@ rspamd_config_post_load (struct rspamd_config *cfg, rspamd_map_preload (cfg); } + if (opts & RSPAMD_CONFIG_INIT_POST_LOAD_LUA) { + rspamd_lua_run_config_post_init (cfg->lua_state, cfg); + } + return ret; } |