From: Vsevolod Stakhov Date: Thu, 31 May 2018 14:52:18 +0000 (+0100) Subject: [Fix] Fix plugins intialisation in configwizard X-Git-Tag: 1.7.6~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ae5051edd25d8b3ef46e50e08c4148a27b3aa8a;p=thirdparty%2Frspamd.git [Fix] Fix plugins intialisation in configwizard --- diff --git a/lualib/rspamadm/configwizard.lua b/lualib/rspamadm/configwizard.lua index a71c6f2365..10134c5756 100644 --- a/lualib/rspamadm/configwizard.lua +++ b/lualib/rspamadm/configwizard.lua @@ -625,6 +625,11 @@ return { os.exit(1) end + if not rspamd_config:init_modules() then + rspamd_logger.errx('cannot init modules when parsing %s', opts['config']) + os.exit(1) + end + if #args > 0 then interactive_start = false diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index f54411e887..37d122402c 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -696,13 +696,20 @@ LUA_FUNCTION_DEF (config, experimental_enabled); LUA_FUNCTION_DEF (config, load_ucl); /*** - * @method rspamd_config:parce_rcl([skip_sections]) + * @method rspamd_config:parse_rcl([skip_sections]) * Parses RCL using loaded ucl file * @param {table|string} sections to skip * @return true or false + error message */ LUA_FUNCTION_DEF (config, parse_rcl); +/*** + * @method rspamd_config:init_modules() + * Initialize lua and internal modules + * @return true or false + */ +LUA_FUNCTION_DEF (config, init_modules); + static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, get_module_opt), LUA_INTERFACE_DEF (config, get_mempool), @@ -763,6 +770,7 @@ static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, experimental_enabled), LUA_INTERFACE_DEF (config, load_ucl), LUA_INTERFACE_DEF (config, parse_rcl), + LUA_INTERFACE_DEF (config, init_modules), {"__tostring", rspamd_lua_class_tostring}, {"__newindex", lua_config_newindex}, {NULL, NULL} @@ -3387,6 +3395,22 @@ lua_config_parse_rcl (lua_State *L) return 1; } +static gint +lua_config_init_modules (lua_State *L) +{ + struct rspamd_config *cfg = lua_check_config (L, 1); + + if (cfg != NULL) { + rspamd_lua_post_load_config (cfg); + lua_pushboolean (L, rspamd_init_filters (cfg, FALSE)); + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 1; +} + static gint lua_monitored_alive (lua_State *L) { diff --git a/src/rspamadm/configdump.c b/src/rspamadm/configdump.c index bd776e586f..cd9f6d378d 100644 --- a/src/rspamadm/configdump.c +++ b/src/rspamadm/configdump.c @@ -278,6 +278,7 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd (void) g_quark_from_static_string ((*pworker)->name); pworker++; } + cfg->cache = rspamd_symbols_cache_new (cfg); cfg->compiled_modules = modules; cfg->compiled_workers = workers; diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index a804d0059d..eff27c1e94 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -33,6 +33,10 @@ GHashTable *ucl_vars = NULL; struct rspamd_main *rspamd_main = NULL; lua_State *L = NULL; +/* Defined in modules.c */ +extern module_t *modules[]; +extern worker_t *workers[]; + static void rspamadm_help (gint argc, gchar **argv, const struct rspamadm_command *); static const char* rspamadm_help_help (gboolean full_help, const struct rspamadm_command *); @@ -291,6 +295,7 @@ main (gint argc, gchar **argv, gchar **env) const struct rspamadm_command *cmd; GPtrArray *all_commands = g_ptr_array_new (); /* Discovered during check */ gint i, nargc, targc; + worker_t **pworker; ucl_vars = g_hash_table_new_full (rspamd_strcase_hash, rspamd_strcase_equal, g_free, g_free); @@ -325,6 +330,16 @@ main (gint argc, gchar **argv, gchar **env) rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_LIBS|RSPAMD_CONFIG_INIT_URL|RSPAMD_CONFIG_INIT_NO_TLD); + pworker = &workers[0]; + while (*pworker) { + /* Init string quarks */ + (void) g_quark_from_static_string ((*pworker)->name); + pworker++; + } + + cfg->compiled_modules = modules; + cfg->compiled_workers = workers; + gperf_profiler_init (cfg, "rspamadm"); setproctitle ("rspamdadm");