diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-10 17:44:06 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-10 17:44:06 +0100 |
commit | 9c571fcf673e2cd2247b921769059c2399696234 (patch) | |
tree | 513d686b13d632cfc58774fce778f5a15706a357 /src/lua/lua_common.c | |
parent | 6e31344466e2558a99cd46bb29abaa37e1faffc6 (diff) | |
download | rspamd-9c571fcf673e2cd2247b921769059c2399696234.tar.gz rspamd-9c571fcf673e2cd2247b921769059c2399696234.zip |
[Minor] Fix modules loading logic
Diffstat (limited to 'src/lua/lua_common.c')
-rw-r--r-- | src/lua/lua_common.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index d68e8e952..a6766f93f 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -1053,12 +1053,24 @@ rspamd_plugins_table_push_elt (lua_State *L, const gchar *field_name, const gchar *new_elt) { lua_getglobal (L, rspamd_modules_state_global); - lua_pushstring (L, field_name); - lua_gettable (L, -2); - lua_pushstring (L, new_elt); - lua_newtable (L); - lua_settable (L, -3); - lua_pop (L, 2); /* Global + element */ + + if (lua_istable (L, -1)) { + lua_pushstring (L, field_name); + lua_gettable (L, -2); + + if (lua_istable (L, -1)) { + lua_pushstring (L, new_elt); + lua_newtable (L); + lua_settable (L, -3); + lua_pop (L, 2); /* Global + element */ + } + else { + lua_pop (L, 2); /* Global + element */ + } + } + else { + lua_pop (L, 1); + } } gboolean @@ -1070,6 +1082,11 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load) lua_State *L = cfg->lua_state; gint err_idx; + pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *)); + rspamd_lua_setclass (L, "rspamd{config}", -1); + *pcfg = cfg; + lua_setglobal (L, "rspamd_config"); + cur = g_list_first (cfg->script_modules); while (cur) { @@ -1132,12 +1149,6 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load) munmap (data, fsize); g_free (lua_fname); - /* Initialize config structure */ - pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *)); - rspamd_lua_setclass (L, "rspamd{config}", -1); - *pcfg = cfg; - lua_setglobal (L, "rspamd_config"); - if (lua_pcall (L, 0, 0, err_idx) != 0) { msg_err_config ("init of %s failed: %s", module->path, |