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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-11-11 16:34:50 +01:00
parent d612a86c3b
commit 1ef9a9f128
+5
View File
@@ -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);