From 807db6c8f5ee4ca55990a7df8d181aa30f8ff3b0 Mon Sep 17 00:00:00 2001 From: Frank Louwers Date: Thu, 26 Sep 2019 11:42:27 +0200 Subject: [PATCH] Add comments on why we need this --- pdns/pdns_recursor.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index c9a417af2f..b28d870056 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -4081,7 +4081,19 @@ static int serviceMain(int argc, char*argv[]) daemonize(); } if(Utility::getpid() == 1) { - /* We are running as pid 1, register sigterm and sigint handler */ + /* We are running as pid 1, register sigterm and sigint handler + + The Linux kernel will handle SIGTERM and SIGINT for all processes, except PID 1. + It assumes that the processes running as pid 1 is an "init" like system. + For years, this was a safe assumption, but containers change that: in + most (all?) container implementations, the application itself is running + as pid 1. This means that sending signals to those applications, will not + be handled by default. Results might be "you container not responsing + when asking it to stop", or "ctrl-c" not working even when the app is + running in the foreground inside a container. + + So TL;DR: If we're running pid 1 (container), we should handle SIGTERM and SIGINT ourselves */ + signal(SIGTERM,termIntHandler); signal(SIGINT,termIntHandler); } -- 2.47.2