From 66c6f2e8ca7973e0f124ced3d703f30027f1316f 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 (cherry picked from commit 2cf70298c17ace48a112023f68cab2e385240a1a) --- 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 2a31ec8b0c..7d3991d1f4 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