From f46e13b47c010f16075350e17ca0dbfea46e6e05 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 4 Aug 2010 17:13:18 +0400 Subject: * Consider lua plugins errors as fatal configuration errors --- src/lua/lua_common.c | 17 ++++++++++++++--- src/lua/lua_common.h | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/lua') 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); -- cgit v1.2.3