]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Set socket-dir to RUNTIME_DIRECTORY under systemd. 9397/head
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 29 Apr 2020 09:32:23 +0000 (11:32 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 19 Aug 2020 13:28:19 +0000 (15:28 +0200)
RUNTIME_DIRECTORY is set by systemd to the value to `RuntimeDirectory`
, which is managed by systemd and so it is safe to use for the socket-dir.

(cherry picked from commit 9a5b0a54fa460c56fd895974ca41db4e869ae0e0)

pdns/common_startup.cc
pdns/pdns_recursor.cc

index 9b97b5e9a8a470f015701b8b05a7793a7be1de27..d7a9ef0c832fb56d57503194271dc2f0679a5534 100644 (file)
@@ -70,7 +70,16 @@ void declareArguments()
 {
   ::arg().set("config-dir","Location of configuration directory (pdns.conf)")=SYSCONFDIR;
   ::arg().set("config-name","Name of this virtual configuration - will rename the binary image")="";
-  ::arg().set("socket-dir",string("Where the controlsocket will live, ")+LOCALSTATEDIR+"/pdns when unset and not chrooted" )="";
+  ::arg().set("socket-dir",string("Where the controlsocket will live, ")+LOCALSTATEDIR+"/pdns when unset and not chrooted"
+#ifdef HAVE_SYSTEMD
+      + ". Set to the RUNTIME_DIRECTORY environment variable when that variable has a value (e.g. under systemd).")="";
+   auto runtimeDir = getenv("RUNTIME_DIRECTORY");
+   if (runtimeDir != nullptr) {
+     ::arg().set("socket-dir") = runtimeDir;
+   }
+#else
+      )="";
+#endif
   ::arg().set("module-dir","Default directory for modules")=PKGLIBDIR;
   ::arg().set("chroot","If set, chroot to this directory for more security")="";
   ::arg().set("logging-facility","Log under a specific facility")="";
index 9e420bb87ba80741707b880ff2abb1cabf59d4e4..d809bdb597d674b08cafc14ac80b0328ca08d2b6 100644 (file)
@@ -4721,7 +4721,16 @@ int main(int argc, char **argv)
     ::arg().set("socket-group","Group of socket")="";
     ::arg().set("socket-mode", "Permissions for socket")="";
 
-    ::arg().set("socket-dir",string("Where the controlsocket will live, ")+LOCALSTATEDIR+"/pdns-recursor when unset and not chrooted" )="";
+    ::arg().set("socket-dir",string("Where the controlsocket will live, ")+LOCALSTATEDIR+"/pdns-recursor when unset and not chrooted"
+#ifdef HAVE_SYSTEMD
+      + ". Set to the RUNTIME_DIRECTORY environment variable when that variable has a value (e.g. under systemd).")="";
+   auto runtimeDir = getenv("RUNTIME_DIRECTORY");
+   if (runtimeDir != nullptr) {
+     ::arg().set("socket-dir") = runtimeDir;
+   }
+#else
+      )="";
+#endif
     ::arg().set("delegation-only","Which domains we only accept delegations from")="";
     ::arg().set("query-local-address","Source IP address for sending queries")="0.0.0.0";
     ::arg().set("query-local-address6","Source IPv6 address for sending queries. IF UNSET, IPv6 WILL NOT BE USED FOR OUTGOING QUERIES")="";