aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-08-04 17:13:18 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-08-04 17:13:18 +0400
commitf46e13b47c010f16075350e17ca0dbfea46e6e05 (patch)
treeeb674e5ca79be353afea4d65a20e3ac7d03af98a /src/lua
parent4680a3fb136ade8bb3a38f0a7837fa0cfe5466c3 (diff)
downloadrspamd-f46e13b47c010f16075350e17ca0dbfea46e6e05.tar.gz
rspamd-f46e13b47c010f16075350e17ca0dbfea46e6e05.zip
* Consider lua plugins errors as fatal configuration errors
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_common.c17
-rw-r--r--src/lua/lua_common.h2
2 files changed, 15 insertions, 4 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);