{
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)
string progname=argv[0];
bool first=true;
- cpid=0;
pthread_mutex_lock(&g_guardian_lock);
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);
if(first) {
first=false;
- signal(SIGTERM, takedown);
-
signal(SIGHUP, SIG_IGN);
signal(SIGUSR1, SIG_IGN);
signal(SIGUSR2, SIG_IGN);
// 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);