From: Vsevolod Stakhov Date: Fri, 5 Feb 2021 11:42:23 +0000 (+0000) Subject: [Minor] Save lua line for cfg scripts for debugging X-Git-Tag: 3.0~705 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bf0f6af14638bfb41d71cb3de630b56d9f14d603;p=thirdparty%2Frspamd.git [Minor] Save lua line for cfg scripts for debugging --- diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 50649b1060..9ef795d053 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -312,6 +312,7 @@ struct rspamd_action; struct rspamd_config_cfg_lua_script { gint cbref; gint priority; + gchar *lua_src_pos; struct rspamd_config_cfg_lua_script *prev, *next; }; diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 89f93730de..f42ca268ed 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -3170,6 +3170,8 @@ lua_config_add_post_init (lua_State *L) struct rspamd_config *cfg = lua_check_config (L, 1); struct rspamd_config_cfg_lua_script *sc; guint priority = 0; + lua_Debug d; + gchar tmp[256], *p; if (cfg == NULL || lua_type (L, 2) != LUA_TFUNCTION) { return luaL_error (L, "invalid arguments"); @@ -3179,10 +3181,30 @@ lua_config_add_post_init (lua_State *L) priority = lua_tointeger (L , 3); } + if (lua_getstack (L, 1, &d) == 1) { + (void) lua_getinfo (L, "Sl", &d); + if ((p = strrchr (d.short_src, '/')) == NULL) { + p = d.short_src; + } + else { + p++; + } + + if (strlen (p) > 200) { + rspamd_snprintf (tmp, sizeof (tmp), "%10s...]:%d", p, + d.currentline); + } + else { + rspamd_snprintf (tmp, sizeof (tmp), "%s:%d", p, + d.currentline); + } + } + sc = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*sc)); lua_pushvalue (L, 2); sc->cbref = luaL_ref (L, LUA_REGISTRYINDEX); sc->priority = priority; + sc->lua_src_pos = rspamd_mempool_strdup (cfg->cfg_pool, tmp); DL_APPEND (cfg->post_init_scripts, sc); DL_SORT (cfg->post_init_scripts, rspamd_post_init_sc_sort); @@ -3195,14 +3217,36 @@ lua_config_add_config_unload (lua_State *L) LUA_TRACE_POINT; struct rspamd_config *cfg = lua_check_config (L, 1); struct rspamd_config_cfg_lua_script *sc; + lua_Debug d; + gchar tmp[256], *p; if (cfg == NULL || lua_type (L, 2) != LUA_TFUNCTION) { return luaL_error (L, "invalid arguments"); } + if (lua_getstack (L, 1, &d) == 1) { + (void) lua_getinfo (L, "Sl", &d); + if ((p = strrchr (d.short_src, '/')) == NULL) { + p = d.short_src; + } + else { + p++; + } + + if (strlen (p) > 20) { + rspamd_snprintf (tmp, sizeof (tmp), "%10s...]:%d", p, + d.currentline); + } + else { + rspamd_snprintf (tmp, sizeof (tmp), "%s:%d", p, + d.currentline); + } + } + sc = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*sc)); lua_pushvalue (L, 2); sc->cbref = luaL_ref (L, LUA_REGISTRYINDEX); + sc->lua_src_pos = rspamd_mempool_strdup (cfg->cfg_pool, tmp); DL_APPEND (cfg->config_unload_scripts, sc); return 0;