From a462478539bd3c01c56c2f13413ea4b9ed6afbde Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 23 Jun 2017 04:20:09 +0200 Subject: [PATCH] nspawn: make sure to send SIGTERM/SIGHUP to the main nspawn process if stubinit receives SIGRTMIN+3 (#6167) This code already existed in some form, however commented. Remove the comments, as this was most likely simply a forgotten commenting for debugging purposes. This also extends the logic a bit, by sending SIGHUP right after the SIGTERM, so that shells will also terminate, when PID 1 gets a SIGRTMIN+3. Fixes: #5711 --- src/nspawn/nspawn-stub-pid1.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/nspawn/nspawn-stub-pid1.c b/src/nspawn/nspawn-stub-pid1.c index 99e52974dcc..0c48434db8e 100644 --- a/src/nspawn/nspawn-stub-pid1.c +++ b/src/nspawn/nspawn-stub-pid1.c @@ -188,7 +188,16 @@ int stub_pid1(sd_id128_t uuid) { else assert_not_reached("Got unexpected signal"); - /* (void) kill_and_sigcont(pid, SIGTERM); */ + r = kill_and_sigcont(pid, SIGTERM); + + /* Let's send a SIGHUP after the SIGTERM, as shells tend to ignore SIGTERM but do react to SIGHUP. We + * do it strictly in this order, so that the SIGTERM is dispatched first, and SIGHUP second for those + * processes which handle both. That's because services tend to bind configuration reload or something + * else to SIGHUP. */ + + if (r != -ESRCH) + (void) kill(pid, SIGHUP); + quit_usec = now(CLOCK_MONOTONIC) + DEFAULT_TIMEOUT_USEC; } -- 2.47.3