]> granicus.if.org Git - pdns/commitdiff
auth: ensure control socket can be created when running in systemd
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 18 Jun 2019 15:09:35 +0000 (17:09 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Wed, 18 Sep 2019 16:14:16 +0000 (18:14 +0200)
builder-support/debian/authoritative/debian-buster/pdns-server.pdns.init
builder-support/debian/authoritative/debian-jessie/pdns-server.pdns.init
builder-support/debian/authoritative/debian-stretch/pdns-server.pdns.init
builder-support/debian/authoritative/ubuntu-trusty/pdns-server.pdns.init
builder-support/specs/pdns.init
pdns/common_startup.cc
pdns/dynlistener.cc
pdns/dynloader.cc
pdns/pdns.init.in
pdns/pdns.service.in
pdns/receiver.cc

index 16ce98be8bf533898e85027566e959767511d081..fc5b17a848b776af73f4251e9d5d87255de7c983 100644 (file)
@@ -21,7 +21,8 @@ NAME=pdns
 DAEMON=/usr/sbin/pdns_server
 DAEMON_ARGS=""
 CONTROL=/usr/bin/pdns_control
-PIDFILE=/var/run/$NAME.pid
+SOCKETDIR=/var/run/pdns
+PIDFILE=$SOCKETDIR/$NAME.pid
 SCRIPTNAME=/etc/init.d/$NAME
 
 [ -x "$DAEMON" ] || exit 0
@@ -36,7 +37,7 @@ if [ -n "$suffix" ]; then
        DAEMON_ARGS="$DAEMON_ARGS $SUFFIX"
        NAME="$NAME-$suffix"
        DESC="$DESC (config name $suffix)"
-       PIDFILE="/var/run/$NAME-$suffix.pid"
+       PIDFILE="/var/run/pdns/$NAME-$suffix.pid"
 fi
 
 # Load lsb stuff for systemd redirection (if available).
@@ -69,6 +70,7 @@ do_start()
        if isrunning; then
                return 1
        fi
+       mkdir -p $SOCKETDIR
        start-stop-daemon --start --quiet \
                --pidfile $PIDFILE --exec $DAEMON -- \
                $DAEMON_ARGS --daemon --guardian=yes \
index 16ce98be8bf533898e85027566e959767511d081..fc5b17a848b776af73f4251e9d5d87255de7c983 100644 (file)
@@ -21,7 +21,8 @@ NAME=pdns
 DAEMON=/usr/sbin/pdns_server
 DAEMON_ARGS=""
 CONTROL=/usr/bin/pdns_control
-PIDFILE=/var/run/$NAME.pid
+SOCKETDIR=/var/run/pdns
+PIDFILE=$SOCKETDIR/$NAME.pid
 SCRIPTNAME=/etc/init.d/$NAME
 
 [ -x "$DAEMON" ] || exit 0
@@ -36,7 +37,7 @@ if [ -n "$suffix" ]; then
        DAEMON_ARGS="$DAEMON_ARGS $SUFFIX"
        NAME="$NAME-$suffix"
        DESC="$DESC (config name $suffix)"
-       PIDFILE="/var/run/$NAME-$suffix.pid"
+       PIDFILE="/var/run/pdns/$NAME-$suffix.pid"
 fi
 
 # Load lsb stuff for systemd redirection (if available).
@@ -69,6 +70,7 @@ do_start()
        if isrunning; then
                return 1
        fi
+       mkdir -p $SOCKETDIR
        start-stop-daemon --start --quiet \
                --pidfile $PIDFILE --exec $DAEMON -- \
                $DAEMON_ARGS --daemon --guardian=yes \
index 16ce98be8bf533898e85027566e959767511d081..fc5b17a848b776af73f4251e9d5d87255de7c983 100644 (file)
@@ -21,7 +21,8 @@ NAME=pdns
 DAEMON=/usr/sbin/pdns_server
 DAEMON_ARGS=""
 CONTROL=/usr/bin/pdns_control
-PIDFILE=/var/run/$NAME.pid
+SOCKETDIR=/var/run/pdns
+PIDFILE=$SOCKETDIR/$NAME.pid
 SCRIPTNAME=/etc/init.d/$NAME
 
 [ -x "$DAEMON" ] || exit 0
@@ -36,7 +37,7 @@ if [ -n "$suffix" ]; then
        DAEMON_ARGS="$DAEMON_ARGS $SUFFIX"
        NAME="$NAME-$suffix"
        DESC="$DESC (config name $suffix)"
-       PIDFILE="/var/run/$NAME-$suffix.pid"
+       PIDFILE="/var/run/pdns/$NAME-$suffix.pid"
 fi
 
 # Load lsb stuff for systemd redirection (if available).
@@ -69,6 +70,7 @@ do_start()
        if isrunning; then
                return 1
        fi
+       mkdir -p $SOCKETDIR
        start-stop-daemon --start --quiet \
                --pidfile $PIDFILE --exec $DAEMON -- \
                $DAEMON_ARGS --daemon --guardian=yes \
index 16ce98be8bf533898e85027566e959767511d081..fc5b17a848b776af73f4251e9d5d87255de7c983 100644 (file)
@@ -21,7 +21,8 @@ NAME=pdns
 DAEMON=/usr/sbin/pdns_server
 DAEMON_ARGS=""
 CONTROL=/usr/bin/pdns_control
-PIDFILE=/var/run/$NAME.pid
+SOCKETDIR=/var/run/pdns
+PIDFILE=$SOCKETDIR/$NAME.pid
 SCRIPTNAME=/etc/init.d/$NAME
 
 [ -x "$DAEMON" ] || exit 0
@@ -36,7 +37,7 @@ if [ -n "$suffix" ]; then
        DAEMON_ARGS="$DAEMON_ARGS $SUFFIX"
        NAME="$NAME-$suffix"
        DESC="$DESC (config name $suffix)"
-       PIDFILE="/var/run/$NAME-$suffix.pid"
+       PIDFILE="/var/run/pdns/$NAME-$suffix.pid"
 fi
 
 # Load lsb stuff for systemd redirection (if available).
@@ -69,6 +70,7 @@ do_start()
        if isrunning; then
                return 1
        fi
+       mkdir -p $SOCKETDIR
        start-stop-daemon --start --quiet \
                --pidfile $PIDFILE --exec $DAEMON -- \
                $DAEMON_ARGS --daemon --guardian=yes \
index c544f9a95c605fa4d83b4fc7eb4d644659e1d7cf..7fd9b49296e43c7099d821c8a133d1ad3274c9c6 100644 (file)
@@ -20,12 +20,13 @@ prefix=/usr
 exec_prefix=/usr
 BINARYPATH=/usr/bin
 SBINARYPATH=/usr/sbin
-SOCKETPATH=/var/run
+SOCKETPATH=/var/run/pdns
 
 [ -f "$SBINARYPATH/pdns_server" ] || exit 0
 
 [ -r /etc/default/pdns ] && . /etc/default/pdns
 
+mkdir -p $SOCKETPATH
 cd $SOCKETPATH
 suffix=$(basename $0 | cut -d- -f2- -s)
 if [ -n "$suffix" ] 
index c1b3c1c2990c546960d43e4d12c65242142dedb2..0a4351cc64820be89332db97ab887d72db6e9913 100644 (file)
@@ -66,7 +66,7 @@ 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+" when unset and not chrooted" )="";
+  ::arg().set("socket-dir",string("Where the controlsocket will live, ")+LOCALSTATEDIR+"/pdns when unset and not chrooted" )="";
   ::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 59776a39bf33977bd9da1e844a910ba4d3878ae9..2deb2182b928a970e842e1b917cbd330792b03c3 100644 (file)
@@ -177,7 +177,7 @@ DynListener::DynListener(const string &progname)
     string socketname = ::arg()["socket-dir"];
     if (::arg()["socket-dir"].empty()) {
       if (::arg()["chroot"].empty())
-        socketname = LOCALSTATEDIR;
+        socketname = std::string(LOCALSTATEDIR) + "/pdns";
       else
         socketname = ::arg()["chroot"];
     } else if (!::arg()["socket-dir"].empty() && !::arg()["chroot"].empty()) {
index 7654d6a026aabeb44d55461e5e749886f478d8ae..212a416133f40add66bd9b40c700151c73646346 100644 (file)
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
   string s_programname="pdns";
 
   ::arg().set("config-dir","Location of configuration directory (pdns.conf)")=SYSCONFDIR;
-  ::arg().set("socket-dir",string("Where the controlsocket will live, ")+LOCALSTATEDIR+" when unset and not chrooted" )="";
+  ::arg().set("socket-dir",string("Where the controlsocket will live, ")+LOCALSTATEDIR+"/pdns when unset and not chrooted" )="";
   ::arg().set("remote-address","Remote address to query");
   ::arg().set("remote-port","Remote port to query")="53000";
   ::arg().set("secret","Secret needed to connect to remote PowerDNS");
@@ -97,7 +97,7 @@ int main(int argc, char **argv)
   string socketname=::arg()["socket-dir"];
   if (::arg()["socket-dir"].empty()) {
     if (::arg()["chroot"].empty())
-      socketname = LOCALSTATEDIR;
+      socketname = std::string(LOCALSTATEDIR) + "/pdns";
     else
       socketname = ::arg()["chroot"] + "/";
   } else if (!::arg()["socket-dir"].empty() && !::arg()["chroot"].empty()) {
index 63c1a54a6f33a04f4c98a50460126650f3a2aebc..7aba99be05dc10ea97c5abae05bebbdd24f1c349 100755 (executable)
@@ -19,7 +19,7 @@ set -e
 exec_prefix=@exec_prefix@
 BINARYPATH=@bindir@
 SBINARYPATH=@sbindir@
-SOCKETPATH=@socketdir@
+SOCKETPATH=@socketdir@/pdns
 DAEMON_ARGS=""
 
 [ -f "$SBINARYPATH/pdns_server" ] || exit 0
index a272eddfbf8e217c645cbe96404d083d6b4f5872..6613ba17b90954e01c4b39763a686f1da620ec35 100644 (file)
@@ -13,6 +13,7 @@ Type=notify
 Restart=on-failure
 RestartSec=1
 StartLimitInterval=0
+RuntimeDirectory=pdns
 
 # Sandboxing
 CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_CHOWN
index e01c378b964f8341162c1f67393d50094e0e4958..40944349f333f705ee8d7df2a64dd871f2b835f6 100644 (file)
@@ -137,7 +137,7 @@ static void writePid(void)
   string fname=::arg()["socket-dir"];
   if (::arg()["socket-dir"].empty()) {
     if (::arg()["chroot"].empty())
-      fname = LOCALSTATEDIR;
+      fname = std::string(LOCALSTATEDIR) + "/pdns";
     else
       fname = ::arg()["chroot"] + "/";
   } else if (!::arg()["socket-dir"].empty() && !::arg()["chroot"].empty()) {