]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add 'setSyslogFacility()' 7677/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 5 Apr 2019 14:22:28 +0000 (16:22 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 5 Apr 2019 14:22:28 +0000 (16:22 +0200)
pdns/dnsdist-console.cc
pdns/dnsdist-lua.cc
pdns/dnsdist.cc
pdns/dnsdistdist/docs/reference/config.rst
pdns/dolog.hh

index 6ed2244b8399f4a3272f004e9546ee55806c8008..3d0dd4d039f02ff307296a819116b7bf63f5a9c8 100644 (file)
@@ -472,6 +472,7 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "setServerPolicyLua", true, "name, function", "set server selection policy to one named 'name' and provided by 'function'" },
   { "setServFailWhenNoServer", true, "bool", "if set, return a ServFail when no servers are available, instead of the default behaviour of dropping the query" },
   { "setStaleCacheEntriesTTL", true, "n", "allows using cache entries expired for at most n seconds when there is no backend available to answer for a query" },
+  { "setSyslogFacility", true, "facility", "set the syslog logging facility to 'facility'. Defaults to LOG_DAEMON" },
   { "setTCPDownstreamCleanupInterval", true, "interval", "minimum interval in seconds between two cleanups of the idle TCP downstream connections" },
   { "setTCPUseSinglePipe", true, "bool", "whether the incoming TCP connections should be put into a single queue instead of using per-thread queues. Defaults to false" },
   { "setTCPRecvTimeout", true, "n", "set the read timeout on TCP connections from the client, in seconds" },
index dea393d3b318a7c0fc9451c05142038b3b0409fd..69e5c571f67178cb8e6242c0d19a180e517382b9 100644 (file)
@@ -1609,6 +1609,15 @@ void setupLuaConfig(bool client)
       g_secPollInterval = newInterval;
   });
 
+  g_lua.writeFunction("setSyslogFacility", [](int facility) {
+    setLuaSideEffect();
+    if (g_configurationDone) {
+      g_outputBuffer="setSyslogFacility cannot be used at runtime!\n";
+      return;
+    }
+    setSyslogFacility(facility);
+  });
+
   g_lua.writeFunction("addTLSLocal", [client](const std::string& addr, boost::variant<std::string, std::vector<std::pair<int,std::string>>> certFiles, boost::variant<std::string, std::vector<std::pair<int,std::string>>> keyFiles, boost::optional<localbind_t> vars) {
         if (client)
           return;
index 905ee4d4151e48638f3621f62ad02328bb02df83..fdb0dcf28c4a4f35b1aecff8910e07705b1ef0b3 100644 (file)
@@ -2226,7 +2226,7 @@ try
 
   signal(SIGPIPE, SIG_IGN);
   signal(SIGCHLD, SIG_IGN);
-  openlog("dnsdist", LOG_PID, LOG_DAEMON);
+  openlog("dnsdist", LOG_PID|LOG_NDELAY, LOG_DAEMON);
 
 #ifdef HAVE_LIBSODIUM
   if (sodium_init() == -1) {
index 62604d792db5f1450979f662579baa0138986189..ef1f68b4b1ccb89766b216ff96a2dab34975bc44 100644 (file)
@@ -42,6 +42,14 @@ Global configuration
 
   :param str path: The directory to load configuration files from. Each file must end in ``.conf``.
 
+.. function:: setSyslogFacility(facility)
+
+  .. versionadded:: 1.4.0
+
+  Set the syslog logging facility to ``facility``.
+
+  :param int facility: The new facility as a numeric value. Defaults to LOG_DAEMON.
+
 Listen Sockets
 ~~~~~~~~~~~~~~
 
index 0d5bffe0d93040f5be3cf539bfcefe592f40a984..cce1b74769347ac2d40cfb7d73dec83e69ba29a4 100644 (file)
@@ -70,6 +70,13 @@ void dolog(std::ostream& os, const char* s, T value, Args... args)
 extern bool g_verbose;
 extern bool g_syslog;
 
+inline void setSyslogFacility(int facility)
+{
+  /* we always call openlog() right away at startup */
+  closelog();
+  openlog("dnsdist", LOG_PID|LOG_NDELAY, facility);
+}
+
 template<typename... Args>
 void genlog(int level, const char* s, Args... args)
 {