From 46ccdc38206daf5ed7abd4bcef6bbebbf8e22005 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 18 Apr 2021 09:52:48 +0200 Subject: [PATCH] Fix ordering issue, pid is unset for kill(-pid, SIGKILL) op Signed-off-by: Joachim Wiberg --- src/service.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/service.c b/src/service.c index 2140eeef..030ad522 100644 --- a/src/service.c +++ b/src/service.c @@ -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;