]> source.dussan.org Git - rspamd.git/commitdiff
* Consider lua plugins errors as fatal configuration errors
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 4 Aug 2010 13:13:18 +0000 (17:13 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 4 Aug 2010 13:13:18 +0000 (17:13 +0400)
src/lua/lua_common.c
src/lua/lua_common.h
src/main.c
src/plugins/lua/forged_recipients.lua

index b0ca3a32b1a60f220146432944c4af44d49c5f58..a880f50e3322f64db06652958c43009cec273646 100644 (file)
@@ -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 */
index ffed03e58c9ecdbc409018ee915b9ab387fd4fa4..7bbf67533ea849db6803cea59084dc918705d6df 100644 (file)
@@ -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);
index 4eb4d2c55050819f3fb09b4cd47f1ae72d7260a1..9db7df75d80c31f3bc42fd9d322c29267c336c55 100644 (file)
@@ -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);
 
index af4ce31250925f1c182f4ff24ea160ebb4d8b77b..1f0ef8635cd20df4f1d4a7caff9b32025a85b078 100644 (file)
@@ -76,5 +76,3 @@ if opts then
                rspamd_config:register_symbol(symbol_rcpt, 1.0, 'check_forged_headers')
        end
 end
-
-