From 2cf70298c17ace48a112023f68cab2e385240a1a Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 14 Apr 2025 16:35:27 +0200 Subject: [PATCH] rec: add a Lua function to get the config dir and name --- pdns/recursordist/docs/lua-scripting/functions.rst | 6 ++++++ pdns/recursordist/lua-recursor4.cc | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/pdns/recursordist/docs/lua-scripting/functions.rst b/pdns/recursordist/docs/lua-scripting/functions.rst index 628ff91805..b2566e0bb0 100644 --- a/pdns/recursordist/docs/lua-scripting/functions.rst +++ b/pdns/recursordist/docs/lua-scripting/functions.rst @@ -65,3 +65,9 @@ These are some functions that don't really have a place in one of the other cate Note that setting both limits to zero can produce very large strings. It is wise to set at least one of the limits. Additionally, setting ``maxSize`` to zero can lead to less efficient memory management while producing the dump. +.. function:: getConfigDirAndName() -> str, str + + .. versionadded:: 5.2.3 + + Get the configuration directory and the instance name. + These two values correspond to the :ref:`setting-yaml-recursor.config_dir` and :ref:`setting-yaml-recursor.config_name` settings. diff --git a/pdns/recursordist/lua-recursor4.cc b/pdns/recursordist/lua-recursor4.cc index b5f83881c5..ef834b0f93 100644 --- a/pdns/recursordist/lua-recursor4.cc +++ b/pdns/recursordist/lua-recursor4.cc @@ -33,6 +33,7 @@ #include "filterpo.hh" #include "rec-snmp.hh" #include "rec-main.hh" +#include "arguments.hh" boost::optional RecursorLua4::DNSQuestion::getDH() const { @@ -515,6 +516,13 @@ void RecursorLua4::postPrepareContext() // NOLINT(readability-function-cognitive thread.detach(); }); + d_lw->writeFunction("getConfigDirAndName", []() -> std::tuple { + std::string dir = ::arg()["config-dir"]; + cleanSlashes(dir); + std::string name = ::arg()["config-name"]; + return {dir, name}; + }); + if (!d_include_path.empty()) { includePath(d_include_path); -- 2.47.2