]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
pdns: Kill all spawned processes
authorIgor Maravic <igor@spotify.com>
Thu, 19 Sep 2013 21:04:00 +0000 (23:04 +0200)
committerIgor Maravic <igor@spotify.com>
Tue, 8 Oct 2013 08:00:48 +0000 (10:00 +0200)
Pipe backend spawned processes can still be alive after the pdns_server-instance was killed.
If the children remain alive, sockets will not be released, and the pdns_server-instance can't be respawned.

To be sure that all the spawned processes are killed, we must kill by using the process GID.
To be able to do the soft reloads, pdns_server-instance is declared as process group lider.

Also, all forced kills must kill by GID, not by PID, so all the processes would properly die.

Signed-off-by: Igor Maravic <igor@spotify.com>
Signed-off-by: Alexey Lapitsky <alexey@spotify.com>
debian/init.d/pdns
pdns/pdns-recursor.init.d
pdns/receiver.cc

index 57e66b8fef8d3d6aa13373790f140f4a6ace924a..28f6ae09983934ce1bb6f8f2a0578762d200a3ad 100644 (file)
@@ -68,7 +68,7 @@ case "$1" in
 
        force-stop)
                echo -n "Stopping PowerDNS authoritative nameserver: "
-               killall -v -9 pdns_server
+               killall -v -g -9 pdns_server
                echo "killed"
        ;;
 
index 12348ca174d807c67767570f2e43d6f76c4f4c2c..83e28cd39cef0c042b47b68b99377ce6e9af8ec5 100755 (executable)
@@ -57,7 +57,7 @@ case "$1" in
 
        force-stop)
                echo -n "Stopping PowerDNS recursing nameserver: "
-               killall -v -9 pdns_server
+               killall -v -g -9 pdns_server
                echo "killed"
        ;;
 
index bc514a13ecf32ef3e4ec8958fcdd28aae66ee2f1..331570658a6221e56fa0a711455af51a15cbbed5 100644 (file)
@@ -117,7 +117,7 @@ static void takedown(int i)
 {
   if(cpid) {
     L<<Logger::Error<<"Guardian is killed, taking down children with us"<<endl;
-    kill(cpid,SIGKILL);
+    kill(-getpgid(cpid),SIGKILL);
     exit(0);
   }
 }
@@ -139,8 +139,7 @@ pthread_mutex_t g_guardian_lock = PTHREAD_MUTEX_INITIALIZER;
 // The next two methods are not in dynhandler.cc because they use a few items declared in this file.
 static string DLCycleHandler(const vector<string>&parts, pid_t ppid)
 {
-  kill(cpid, SIGKILL); // why?
-  kill(cpid, SIGKILL); // why?
+  kill(-getpgid(cpid), SIGKILL);
   sleep(1);
   return "ok";
 }
@@ -220,6 +219,11 @@ static int guardian(int argc, char **argv)
       signal(SIGUSR1, SIG_DFL);
       signal(SIGUSR2, SIG_DFL);
 
+      // Set different pgrp for this child,
+      // so we could kill all of it's children
+      // with one kill call
+      setpgid(getpid(), 0);
+
       char **const newargv=new char*[argc+2];
       int n;