From: Heiko Schlittermann (HS12-RIPE) Date: Thu, 22 Mar 2018 22:32:53 +0000 (+0100) Subject: Set a TERM handler to terminate properly if running as PID 1 X-Git-Tag: exim-4_91_RC3~32 X-Git-Url: https://git.exim.org/exim.git/commitdiff_plain/830832c9aac90729e88bab0d1daa1ec8bb6848f5 Set a TERM handler to terminate properly if running as PID 1 --- diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog index 236ccae8b..459ffe11a 100644 --- a/doc/doc-txt/ChangeLog +++ b/doc/doc-txt/ChangeLog @@ -165,6 +165,9 @@ JH/30 The (EXPERIMENTAL_DMARC) variable $dmarc_ar_header is withdrawn, being JH/31 Bug 2257: Fix pipe transport to not use a socket-only syscall. +HS/03 Set a handler for SIGTERM and call exit(3) if running as PID 1. This + allows proper process termination in container environments. + Exim version 4.90 ----------------- diff --git a/src/src/exim.c b/src/src/exim.c index 4d35b51f3..d740814f9 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -187,7 +187,15 @@ DEBUG(D_process_info) debug_printf("set_process_info: %s", process_info); va_end(ap); } +/*********************************************** +* Handler for SIGTERM * +***********************************************/ +static void +term_handler(int sig) +{ + exit(1); +} /************************************************* @@ -1678,6 +1686,10 @@ descriptive text. */ set_process_info("initializing"); os_restarting_signal(SIGUSR1, usr1_handler); +/* If running in a dockerized environment, the TERM signal is only +delegated to the PID 1 if we request it by setting an signal handler */ +if (getpid() == 1) signal(SIGTERM, term_handler); + /* SIGHUP is used to get the daemon to reconfigure. It gets set as appropriate in the daemon code. For the rest of Exim's uses, we ignore it. */