diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-08-04 17:13:18 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-08-04 17:13:18 +0400 |
commit | f46e13b47c010f16075350e17ca0dbfea46e6e05 (patch) | |
tree | eb674e5ca79be353afea4d65a20e3ac7d03af98a | |
parent | 4680a3fb136ade8bb3a38f0a7837fa0cfe5466c3 (diff) | |
download | rspamd-f46e13b47c010f16075350e17ca0dbfea46e6e05.tar.gz rspamd-f46e13b47c010f16075350e17ca0dbfea46e6e05.zip |
* Consider lua plugins errors as fatal configuration errors
-rw-r--r-- | src/lua/lua_common.c | 17 | ||||
-rw-r--r-- | src/lua/lua_common.h | 2 | ||||
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/plugins/lua/forged_recipients.lua | 2 |
4 files changed, 22 insertions, 8 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index b0ca3a32b..a880f50e3 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -236,7 +236,7 @@ init_lua (struct config_file *cfg) -void +gboolean init_lua_filters (struct config_file *cfg) { struct config_file **pcfg; @@ -252,7 +252,7 @@ init_lua_filters (struct config_file *cfg) if (luaL_loadfile (L, module->path) != 0) { msg_info ("load of %s failed: %s", module->path, lua_tostring (L, -1)); cur = g_list_next (cur); - continue; + return FALSE; } /* Initialize config structure */ @@ -261,9 +261,17 @@ init_lua_filters (struct config_file *cfg) *pcfg = cfg; lua_setglobal (L, "rspamd_config"); - /* do the call (1 arguments, 1 result) */ + /* do the call (0 arguments, N result) */ if (lua_pcall (L, 0, LUA_MULTRET, 0) != 0) { msg_info ("init of %s failed: %s", module->path, lua_tostring (L, -1)); + return FALSE; + } + if (lua_gettop (L) != 0) { + if (lua_tonumber (L, -1) == -1) { + msg_info ("%s returned -1 that indicates configuration error", module->path); + return FALSE; + } + lua_pop (L, lua_gettop (L)); } } cur = g_list_next (cur); @@ -279,6 +287,7 @@ init_lua_filters (struct config_file *cfg) /* Code must be loaded from data */ if (luaL_loadstring (L, tmp->data) != 0) { msg_info ("cannot load normalizer code %s", tmp->data); + return FALSE; } } } @@ -287,6 +296,8 @@ init_lua_filters (struct config_file *cfg) } /* Assign state */ cfg->lua_state = L; + + return TRUE; } /* Callback functions */ diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index ffed03e58..7bbf67533 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -31,7 +31,7 @@ int luaopen_textpart (lua_State *L); int luaopen_classifier (lua_State *L); int luaopen_statfile (lua_State * L); void init_lua (struct config_file *cfg); -void init_lua_filters (struct config_file *cfg); +gboolean init_lua_filters (struct config_file *cfg); /* Filters functions */ int lua_call_filter (const char *function, struct worker_task *task); diff --git a/src/main.c b/src/main.c index 4eb4d2c55..9db7df75d 100644 --- a/src/main.c +++ b/src/main.c @@ -858,7 +858,9 @@ main (int argc, char **argv, char **env) } l = g_list_next (l); } - init_lua_filters (rspamd->cfg); + if (! init_lua_filters (rspamd->cfg)) { + res = FALSE; + } if (dump_vars) { dump_cfg_vars (rspamd->cfg); } @@ -919,7 +921,10 @@ main (int argc, char **argv, char **env) l = g_list_next (l); } - init_lua_filters (rspamd->cfg); + if (! init_lua_filters (rspamd->cfg)) { + msg_err ("error loading lua plugins"); + exit (EXIT_FAILURE); + } init_cfg_cache (rspamd->cfg); diff --git a/src/plugins/lua/forged_recipients.lua b/src/plugins/lua/forged_recipients.lua index af4ce3125..1f0ef8635 100644 --- a/src/plugins/lua/forged_recipients.lua +++ b/src/plugins/lua/forged_recipients.lua @@ -76,5 +76,3 @@ if opts then rspamd_config:register_symbol(symbol_rcpt, 1.0, 'check_forged_headers') end end - - |