]> granicus.if.org Git - pdns/commitdiff
Terminate pdns process after SIGINT
authorIgor Maravic <igor@spotify.com>
Tue, 3 Dec 2013 19:47:42 +0000 (20:47 +0100)
committerIgor Maravic <igor@spotify.com>
Sat, 7 Dec 2013 14:53:58 +0000 (15:53 +0100)
pdns/receiver.cc

index 96b1fcffc416ca3fbe22781a296fd62627813054..ef8739a4eb8fdcfbeef64583391f7c203f5e2932 100644 (file)
@@ -120,9 +120,11 @@ static void takedown(int i)
 {
   if(cpid) {
     L<<Logger::Error<<"Guardian is killed, taking down children with us"<<endl;
-    kill(-getpgid(cpid),SIGKILL);
-    exit(0);
+  } else {
+    L<<Logger::Error<<"PDNS instance is going down, taking children with us"<<endl;
   }
+  kill(-getpgid(cpid),SIGKILL);
+  exit(0);
 }
 
 static void writePid(void)
@@ -196,7 +198,6 @@ static int guardian(int argc, char **argv)
   string progname=argv[0];
 
   bool first=true;
-  cpid=0;
 
   pthread_mutex_lock(&g_guardian_lock);
 
@@ -216,8 +217,6 @@ static int guardian(int argc, char **argv)
     setbuf(g_fp,0); // no buffering please, confuses select
 
     if(!(pid=fork())) { // child
-      signal(SIGTERM, SIG_DFL);
-
       signal(SIGHUP, SIG_DFL);
       signal(SIGUSR1, SIG_DFL);
       signal(SIGUSR2, SIG_DFL);
@@ -271,8 +270,6 @@ static int guardian(int argc, char **argv)
 
       if(first) {
         first=false;
-        signal(SIGTERM, takedown);
-
         signal(SIGHUP, SIG_IGN);
         signal(SIGUSR1, SIG_IGN);
         signal(SIGUSR2, SIG_IGN);
@@ -417,6 +414,15 @@ int main(int argc, char **argv)
   // the leader of the process group
   setpgid(getpid(), 0);
 
+  // Initialize child PID var. It will remain 0 for pdns instance.
+  // It will have child value in the PDNS guardian instance.
+  // cpid is needed to properly terminate PDNS process in
+  // takedown function, and in Guardian's Cycle handler.
+  cpid=0;
+
+  signal(SIGINT, takedown);
+  signal(SIGTERM, takedown);
+
   s_programname="pdns";
   s_starttime=time(0);