From 8b9bb1c7cee3bebe16a0765263d8f48b8b92d680 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Tue, 15 Nov 2022 00:56:21 +0100 Subject: [PATCH] Fix #314: skip restart if conditions are lost This change prevents Finit from attempting to continue restarting crashing services that've lost their conditions. Signed-off-by: Joachim Wiberg --- src/cond-w.c | 6 ++++++ src/svc.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/cond-w.c b/src/cond-w.c index b1a891d7..889beaa0 100644 --- a/src/cond-w.c +++ b/src/cond-w.c @@ -270,6 +270,12 @@ int cond_update(const char *name) affects++; dbg("%s: match <%s> %s(%s)", name ?: "nil", svc->cond, svc->desc, svc->cmd); + /* Fix bug #314: race condition between crashing services and conditions */ + if (svc_is_restart(svc) && cond_get_agg(svc->cond) == COND_OFF) { + dbg("%s: cancel timer & unblock => WAITING state.", name ?: "nil"); + service_timeout_cancel(svc); + svc_unblock(svc); + } service_step(svc); } diff --git a/src/svc.h b/src/svc.h index e0f54a3a..16572d58 100644 --- a/src/svc.h +++ b/src/svc.h @@ -263,6 +263,7 @@ static inline int svc_is_blocked (svc_t *svc) { return svc && svc->block != SV static inline int svc_is_busy (svc_t *svc) { return svc && svc->block == SVC_BLOCK_BUSY; } static inline int svc_is_missing (svc_t *svc) { return svc && svc->block == SVC_BLOCK_MISSING; } static inline int svc_is_crashing (svc_t *svc) { return svc && svc->block == SVC_BLOCK_CRASHING; } +static inline int svc_is_restart (svc_t *svc) { return svc && svc->block == SVC_BLOCK_RESTARTING; } static inline void svc_unblock (svc_t *svc) { if (svc) svc->block = SVC_BLOCK_NONE; } #define svc_start(svc) svc_unblock(svc)