Fix ordering issue, pid is unset for kill(-pid, SIGKILL) op

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-04-18 09:52:48 +02:00
1 parent 242fe54afd
commit 46ccdc3820
1 file changed
+6 -6
+6 -6
View File
@@ -659,14 +659,14 @@ static void service_cleanup(svc_t *svc)
{
char *fn;
/* PID collected, cancel any pending SIGKILL */
service_timeout_cancel(svc);
fn = pid_file(svc);
if (fn && remove(fn) && errno != ENOENT)
logit(LOG_CRIT, "Failed removing service %s pidfile %s",
basename(svc->cmd), fn);
/* PID collected, cancel any pending SIGKILL */
service_timeout_cancel(svc);
/* No longer running, update books. */
if (svc_is_tty(svc) && svc->pid > 1)
utmp_set_dead(svc->pid); /* Set DEAD_PROCESS UTMP entry */
@@ -1376,6 +1376,9 @@ void service_monitor(pid_t lost, int status)
if (svc_is_starting(svc) && svc_is_forking(svc))
return;
/* Terminate any children in the same proess group, e.g. logit */
kill(-svc->pid, SIGKILL);
/* Try removing PID file (in case service does not clean up after itself) */
if (svc_is_daemon(svc) || svc_is_tty(svc)) {
service_cleanup(svc);
@@ -1387,9 +1390,6 @@ void service_monitor(pid_t lost, int status)
svc->started = 0;
}
/* Terminate any children in the same proess group, e.g. logit */
kill(-svc->pid, SIGKILL);
/* No longer running, update books. */
svc->start_time = svc->pid = 0;