From bbfaaa6f0b6c080cd02d520a298302995f453b88 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Tue, 15 Mar 2016 11:52:46 +0100 Subject: [PATCH] dnsdist: add a --disable-syslog option This prevents double logging in e.g. systemd --- docs/manpages/dnsdist.1.md | 4 ++++ pdns/dnsdist.cc | 7 +++++++ pdns/dolog.hh | 4 +++- pdns/test-dnscrypt_cc.cc | 1 + pdns/test-dnsdist_cc.cc | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/manpages/dnsdist.1.md b/docs/manpages/dnsdist.1.md index fc289ec755..5dbab8e667 100644 --- a/docs/manpages/dnsdist.1.md +++ b/docs/manpages/dnsdist.1.md @@ -81,6 +81,10 @@ Server for example is often mentioned. : Run in foreground, but do not spawn a console. Use this switch to run dnsdist inside a supervisor (use with e.g. systemd and daemontools). +--disable-syslog +: Disable logging to syslog. Use this when running inside a supervisor that + handles logging (like systemd). Do not use in combination with **--daemon**. + -p,--pidfile *FILE* : Write a pidfile to *FILE*, works only with **--daemon**. diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 0fce07e9b3..d08b0990b7 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -63,6 +63,7 @@ uint16_t g_maxOutstanding{10240}; bool g_console; bool g_verboseHealthChecks{false}; uint32_t g_staleCacheEntriesTTL{0}; +bool g_syslog{true}; GlobalStateHolder g_ACL; string g_outputBuffer; @@ -1257,6 +1258,7 @@ try {"daemon", 0, 0, 'd'}, {"pidfile", required_argument, 0, 'p'}, {"supervised", 0, 0, 's'}, + {"disable-syslog", 0, 0, 2}, {"uid", required_argument, 0, 'u'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, @@ -1277,6 +1279,9 @@ try case 1: g_cmdLine.checkConfig=true; break; + case 2: + g_syslog=false; + break; case 'C': g_cmdLine.config=optarg; break; @@ -1316,6 +1321,8 @@ try cout<<"-l,--local address Listen on this local address\n"; cout<<"--supervised Don't open a console, I'm supervised\n"; cout<<" (use with e.g. systemd and daemontools)\n"; + cout<<"--disable-syslog Don't log to syslog, only to stdout\n"; + cout<<" (use with e.g. systemd)\n"; cout<<"-p,--pidfile file Write a pidfile, works only with --daemon\n"; cout<<"-u,--uid uid Change the process user ID after binding sockets\n"; cout<<"-v,--verbose Enable verbose mode\n"; diff --git a/pdns/dolog.hh b/pdns/dolog.hh index eb988232ed..77c42bcd18 100644 --- a/pdns/dolog.hh +++ b/pdns/dolog.hh @@ -48,13 +48,15 @@ void dolog(std::ostream& os, const char* s, T value, Args... args) extern bool g_console; extern bool g_verbose; +extern bool g_syslog; template void genlog(int level, const char* s, Args... args) { std::ostringstream str; dolog(str, s, args...); - syslog(level, "%s", str.str().c_str()); + if(g_syslog) + syslog(level, "%s", str.str().c_str()); if(g_console) std::cout<