]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Initialize lua debugging earlier
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 2 Apr 2019 08:12:17 +0000 (09:12 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 2 Apr 2019 08:12:17 +0000 (09:12 +0100)
lualib/lua_util.lua
src/libserver/cfg_rcl.c

index a6a99f2b64d81c6c8fbb21882f25f7e7643d927c..4f185ecab70177d0b1470f12731d33a723b006a2 100644 (file)
@@ -830,10 +830,11 @@ local debug_modules = {}
 local debug_aliases = {}
 local log_level = 384 -- debug + forced (1 << 7 | 1 << 8)
 
-if type(rspamd_config) == 'userdata' then
+
+exports.init_debug_logging = function(config)
   local logger = require "rspamd_logger"
   -- Fill debug modules from the config
-  local logging = rspamd_config:get_all_opt('logging')
+  local logging = config:get_all_opt('logging')
   if logging then
     local log_level_str = logging.level
     if log_level_str then
@@ -846,7 +847,7 @@ if type(rspamd_config) == 'userdata' then
       if logging.debug_modules then
         for _,m in ipairs(logging.debug_modules) do
           debug_modules[m] = true
-          logger.infox(rspamd_config, 'enable debug for Lua module %s', m)
+          logger.infox(config, 'enable debug for Lua module %s', m)
         end
       end
 
@@ -854,7 +855,7 @@ if type(rspamd_config) == 'userdata' then
         for alias,mod in pairs(debug_aliases) do
           if debug_modules[mod] then
             debug_modules[alias] = true
-            logger.infox(rspamd_config, 'enable debug for Lua module %s (%s aliased)',
+            logger.infox(config, 'enable debug for Lua module %s (%s aliased)',
                 alias, mod)
           end
         end
index ed99ef8b6de5a6e547afa07fc0032c06eaf0e86c..a9f957183503ef8bec58dfb77045db5aa98a03a4 100644 (file)
@@ -3796,6 +3796,41 @@ rspamd_config_read (struct rspamd_config *cfg,
                                } else {
                                        logger_fin (cfg->cfg_pool, logger_ud);
                                }
+
+                               /* Init lua logging */
+                               lua_State *L = cfg->lua_state;
+                               gint err_idx;
+                               struct rspamd_config **pcfg;
+
+                               lua_pushcfunction (L, &rspamd_lua_traceback);
+                               err_idx = lua_gettop (L);
+
+                               /* Obtain function */
+                               if (!rspamd_lua_require_function (L, "lua_util",
+                                               "init_debug_logging")) {
+                                       msg_err_config ("cannot require lua_util.init_debug_logging");
+                                       lua_settop (L, err_idx - 1);
+
+                                       return FALSE;
+                               }
+
+                               pcfg = lua_newuserdata (L, sizeof (*pcfg));
+                               *pcfg = cfg;
+                               rspamd_lua_setclass (L, "rspamd{config}", -1);
+
+                               if (lua_pcall (L, 1, 0, err_idx) != 0) {
+                                       GString *tb;
+
+                                       tb = lua_touserdata (L, -1);
+                                       msg_err_config ("cannot call lua init_debug_logging script: %s",
+                                                       tb->str);
+                                       g_string_free (tb, TRUE);
+                                       lua_settop (L, err_idx - 1);
+
+                                       return FALSE;
+                               }
+
+                               lua_settop (L, err_idx - 1);
                        }
 
                        HASH_DEL (top, logger_section);