From 9f50b033d9ac2b07aef4a8bac46438196a42f58b Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 28 Nov 2017 08:00:46 +0100 Subject: [PATCH] Abort service kill if already terminated, otherwise kill(0, SIGKILL) This patch fixes a rather nasty bug in the SIGTERM+SIGKILL logic employed by Finit when stopping tasks, e.g. at a runlevel change. When a process terminates, after Finit having sent it SIGTERM, and the SIGKILL timer expires *before* the timer has been cancelled, then the timer callback would cause kill(0, SIGKILL). Signed-off-by: Joachim Nilsson --- src/service.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/service.c b/src/service.c index 61f2c180..0a7a90e6 100644 --- a/src/service.c +++ b/src/service.c @@ -358,10 +358,16 @@ static void service_kill(svc_t *svc) { service_timeout_cancel(svc); + if (svc->pid <= 1) { + /* Avoid killing ourselves or all processes ... */ + _d("%s: Aborting SIGKILL, already terminated.", svc->cmd); + return; + } + if (runlevel != 1) print_desc("Killing ", svc->desc); - _d("Sending SIGKILL to pid:%d name:%s", svc->pid, pid_get_name(svc->pid, NULL, 0)); + _d("%s: Sending SIGKILL to pid:%d", pid_get_name(svc->pid, NULL, 0), svc->pid); kill(svc->pid, SIGKILL); /* Let SIGKILLs stand out, show result as [WARN] */