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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-04-08 07:27:42 +02:00
parent 7f8a96a73e
commit a39d958d25
+11 -1
View File
@@ -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);