From b338fa78fb9e021921014ea72d30d4ef085a861d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 18 Jul 2020 21:27:47 +0200 Subject: [PATCH] Use atomic_flag_test_and_set to ensure that FTL_TCP_worker_terminating() cannot run two times even when called exactly at the same time. Signed-off-by: DL6ER --- src/dnsmasq_interface.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index e26cdf76..cc194100 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -38,6 +38,8 @@ #include "args.h" // handle_realtime_signals() #include "signals.h" +// atomic_flag_test_and_set() +#include static void print_flags(const unsigned int flags); static void save_reply_type(const unsigned int flags, const union all_addr *addr, @@ -1785,15 +1787,14 @@ static void prepare_blocking_metadata(void) // Called when a (forked) TCP worker is terminated by receiving SIGALRM // We close the dedicated database connection this client had opened // to avoid dangling database locks -static volatile bool worker_already_terminating = false; +volatile atomic_flag worker_already_terminating = ATOMIC_FLAG_INIT; void FTL_TCP_worker_terminating(bool finished) { - if(worker_already_terminating) + if(atomic_flag_test_and_set(&worker_already_terminating)) { logg("TCP worker already terminating!"); return; } - worker_already_terminating = true; // Possible debug logging if(config.debug != 0)