From 1ef9a9f128e30e835e71e77b02190e6706b77bc4 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 11 Nov 2022 16:30:49 +0100 Subject: [PATCH] Cancel pending restart timer on initctl stop/start/restart/reload When a service crashes Finit launches a restart timer that periodically will try restart the service. If a user calls `initctl stop foo` finit must cancel this timer callback, otherwise we may end up with a weird state where Finit thinkgs the service is running, but pid: 0, i.e., not started. Note: this fix has been expanded upon from the proof of concept submitted by Jack Newman. Bug #313 Signed-off-by: Joachim Wiberg --- src/api.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/api.c b/src/api.c index 8532727e..7886dbe8 100644 --- a/src/api.c +++ b/src/api.c @@ -63,6 +63,7 @@ static int stop(svc_t *svc, void *user_data) if (!svc) return 1; + service_timeout_cancel(svc); svc_stop(svc); service_step(svc); @@ -74,6 +75,7 @@ static int start(svc_t *svc, void *user_data) if (!svc) return 1; + service_timeout_cancel(svc); svc_start(svc); service_step(svc); @@ -93,6 +95,7 @@ static int restart(svc_t *svc, void *user_data) if (!svc_is_running(svc)) return start(svc, user_data); + service_timeout_cancel(svc); service_stop(svc); service_step(svc); @@ -106,6 +109,8 @@ static int reload(svc_t *svc, void *user_data) if (svc_is_blocked(svc)) svc_start(svc); + else + service_timeout_cancel(svc); svc_mark_dirty(svc); service_step(svc);