The Linux kernel handles signals for PID 1 processes differently. It
doesn't implement a default handler for some signals such as
SIGTERM/SIGINT.
When running pdns_recursor as a container, this causes a few annoyances.
You can work around those by running your containers with --init or by
installing `tini` inside the container. Or you can handle the signals in
the application itself.
This commit adds signal() handlers for SIGTERM and SIGINT for
pdns_recursor.
}
}
+static void termIntHandler(int)
+{
+ doExitNicely();
+}
+
static void usr1Handler(int)
{
statsWanted=true;
g_log.toConsole(Logger::Critical);
daemonize();
}
+ signal(SIGTERM,termIntHandler);
+ signal(SIGINT,termIntHandler);
signal(SIGUSR1,usr1Handler);
signal(SIGUSR2,usr2Handler);
signal(SIGPIPE,SIG_IGN);
void registerAllStats();
+void doExitGeneric(bool nicely);
+void doExit();
+void doExitNicely();
}
}
-static void doExitGeneric(bool nicely)
+void doExitGeneric(bool nicely)
{
g_log<<Logger::Error<<"Exiting on user request"<<endl;
extern RecursorControlChannel s_rcc;
_exit(1);
}
-static void doExit()
+void doExit()
{
doExitGeneric(false);
}
-static void doExitNicely()
+void doExitNicely()
{
doExitGeneric(true);
}