From a39d958d25c48e3e0cc7d3b58bab1e1e58baae8f Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 8 Apr 2022 07:27:42 +0200 Subject: [PATCH] Follow-up to 7dc7f9a, protect against stalling on non-existing pids A forking service, e.g. a SysV init script, that returns is no longer running, even though the monitored service may still be starting. We must mark the svc->pid as terminated until we know more -- otherwise we may stall on a shutdown at that exact point. Also, when shutting down, and stopping all services, ensure we do not start the carousel for non-existing PIDs. This might also cause our stalling at shutdown. Signed-off-by: Joachim Wiberg --- src/service.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/service.c b/src/service.c index 1bf168c4..feeb4223 100644 --- a/src/service.c +++ b/src/service.c @@ -747,6 +747,14 @@ static int service_stop(svc_t *svc) */ svc_started(svc); + /* + * Verify there's still something there before we send the reaper. + */ + if (svc->pid > 1 && !pid_alive(svc->pid)) { + svc->pid = 0; + return 0; + } + if (!svc->desc[0]) do_progress = 0; @@ -1501,8 +1509,10 @@ void service_monitor(pid_t lost, int status) } /* Forking sysv/services declare themselves with pid:!/path/to/pid.file */ - if (svc_is_starting(svc) && svc_is_forking(svc)) + if (svc_is_starting(svc) && svc_is_forking(svc)) { + svc->pid = 0; /* Expect no more activity from this one */ return; + } /* Terminate any children in the same proess group, e.g. logit */ kill(-svc->pid, SIGKILL);