From f5ea4ced2e4fb61bc2940b1b82540bb87e3fa0c9 Mon Sep 17 00:00:00 2001 From: Peter Morrow Date: Tue, 13 Apr 2021 17:20:42 +0100 Subject: [PATCH] core: allow services stuck in reloading state to exit If a service is in reloading state but has exited do not delay the final exit until the service reload timer expires. Instead allow the service to exit immediately since we can't expect the service to ever transition out of reloading state. For example if a service sent RELOADING=1 but crashed before it could send READY=1 then it should be restarted if the service had Restart= configured. Signed-off-by: Peter Morrow (cherry picked from commit bbe19f68846bb3cd5fcf3e4f612268064df53b53) --- src/core/service.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/service.c b/src/core/service.c index 1c6083f8e4..901f41b937 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -3460,6 +3460,15 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { case SERVICE_START_POST: case SERVICE_RELOAD: + /* If neither main nor control processes are running then + * the current state can never exit cleanly, hence immediately + * terminate the service. */ + if (control_pid_good(s) <= 0) + service_enter_stop(s, f); + + /* Otherwise need to wait untill the operation is done. */ + break; + case SERVICE_STOP: /* Need to wait until the operation is * done */ -- 2.25.1