From a6bf91d95a38ecffbd26c86da9263b32ec4ccd99 Mon Sep 17 00:00:00 2001 From: Steve Grubb Date: Sun, 26 May 2024 12:01:27 -0400 Subject: [PATCH] Check stop flag before waiting If the stop flag is set before starting a wait, break out of the loop. With the move closing the FANOTIFY fd, we need to check the flag or this thread can wait for an event that will never come since fanotofy was just unmarked. --- src/daemon/notify.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/daemon/notify.c b/src/daemon/notify.c index 1031a34d..5cb265ec 100644 --- a/src/daemon/notify.c +++ b/src/daemon/notify.c @@ -362,9 +362,8 @@ static void *decision_thread_main(void *arg) struct timespec rpt_timeout; // if an interval was configured, reports are enabled - if (rpt_interval) { + if (rpt_interval) rpt_init(&rpt_timeout); - } // start with a fresh report run_stats = 1; @@ -410,6 +409,8 @@ static void *decision_thread_main(void *arg) } // await a fan event, timing out at the // next report interval + if (stop) + break; pthread_cond_timedwait(&do_decision, &decision_lock, &rpt_timeout); @@ -418,11 +419,16 @@ static void *decision_thread_main(void *arg) run_stats = 0; } // no interval reports, await a fan event indefinitely + if (stop) + break; pthread_cond_wait(&do_decision, &decision_lock); } - if (stop) + if (stop) { + msg(LOG_DEBUG, "Exiting decision thread"); + pthread_mutex_unlock(&decision_lock); return NULL; + } alive = 1; rpt_is_stale = 1;