]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: add a Lua function to get the config dir and name 15906/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 14 Apr 2025 14:35:27 +0000 (16:35 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 24 Jul 2025 07:52:30 +0000 (09:52 +0200)
(cherry picked from commit 2cf70298c17ace48a112023f68cab2e385240a1a)

pdns/recursordist/docs/lua-scripting/functions.rst
pdns/recursordist/lua-recursor4.cc

index 628ff91805592166556de027dbdda3d1f6adcd24..b2566e0bb0b05efc9d319fb265e798414f4ca033 100644 (file)
@@ -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.
index 2a31ec8b0c040a2342e037022f6ec4378186c6ed..7d3991d1f4590a0a1a9fdc1eff5fc4857fb63b0a 100644 (file)
@@ -33,6 +33,7 @@
 #include "filterpo.hh"
 #include "rec-snmp.hh"
 #include "rec-main.hh"
+#include "arguments.hh"
 
 boost::optional<dnsheader> 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, std::string> {
+      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);