From 0ca6a67f6820f90ac410eeb8ef6b1f8e58b932d1 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 5 Apr 2019 16:22:28 +0200 Subject: [PATCH] dnsdist: Add 'setSyslogFacility()' --- pdns/dnsdist-console.cc | 1 + pdns/dnsdist-lua.cc | 9 +++++++++ pdns/dnsdist.cc | 2 +- pdns/dnsdistdist/docs/reference/config.rst | 8 ++++++++ pdns/dolog.hh | 7 +++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 6ed2244b83..3d0dd4d039 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -472,6 +472,7 @@ const std::vector 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" }, diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index dea393d3b3..69e5c571f6 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -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>> certFiles, boost::variant>> keyFiles, boost::optional vars) { if (client) return; diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 905ee4d415..fdb0dcf28c 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -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) { diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 62604d792d..ef1f68b4b1 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -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 ~~~~~~~~~~~~~~ diff --git a/pdns/dolog.hh b/pdns/dolog.hh index 0d5bffe0d9..cce1b74769 100644 --- a/pdns/dolog.hh +++ b/pdns/dolog.hh @@ -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 void genlog(int level, const char* s, Args... args) { -- 2.47.2