From 61c2a3c1e4ef7291130c8f6ea45d0b72e4b86d22 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 2 Apr 2019 09:12:17 +0100 Subject: [PATCH] [Fix] Initialize lua debugging earlier --- lualib/lua_util.lua | 9 +++++---- src/libserver/cfg_rcl.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index a6a99f2b6..4f185ecab 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -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 diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index ed99ef8b6..a9f957183 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -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); -- 2.39.5