From 7f7dc2e9fa1a638ec5cf0631ca1c2608bcf46a20 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 28 Feb 2022 21:22:56 +0100 Subject: [PATCH 1/2] Reload blocking mode independently of incoming queries Signed-off-by: DL6ER --- src/database/database-thread.c | 12 ++++++++++-- src/dnsmasq_interface.c | 8 +------- src/enums.h | 2 +- src/events.c | 4 ++-- src/signals.c | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/database/database-thread.c b/src/database/database-thread.c index 22e38a12e..5a312a26d 100644 --- a/src/database/database-thread.c +++ b/src/database/database-thread.c @@ -26,6 +26,8 @@ #include "aliasclients.h" // Eventqueue routines #include "../events.h" +// check_blocking_status() +#include "../setupVars.h" #define DBOPEN_OR_AGAIN() { db = dbopen(false); if(db == NULL) { thread_sleepms(DB, 5000); continue; } } #define BREAK_IF_KILLED() { if(killed) break; } @@ -116,8 +118,14 @@ void *DB_thread(void *val) BREAK_IF_KILLED(); - // Sleep 1 sec - thread_sleepms(DB, 1000); + // Inspect setupVars.conf to see if Pi-hole blocking is enabled + if(get_and_clear_event(RELOAD_BLOCKINGSTATUS)) + check_blocking_status(); + + BREAK_IF_KILLED(); + + // Sleep 0.1 sec + thread_sleepms(DB, 100); } logg("Terminating database thread"); diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index 2a2c3c9c6..d3022cca1 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -1230,12 +1230,6 @@ static bool special_domain(const queriesData *query, const char *domain) static bool _FTL_check_blocking(int queryID, int domainID, int clientID, const char* file, const int line) { - if(get_and_clear_event(RELOAD_BLOCKINGMODE)) - { - // Inspect setupVars.conf to see if Pi-hole blocking is enabled - check_blocking_status(); - } - // Only check blocking conditions when global blocking is enabled if(blockingstatus == BLOCKING_DISABLED) { @@ -1775,7 +1769,7 @@ void FTL_dnsmasq_reload(void) // Request reload the privacy level and blocking mode set_event(RELOAD_PRIVACY_LEVEL); - set_event(RELOAD_BLOCKINGMODE); + set_event(RELOAD_BLOCKINGSTATUS); // Reread pihole-FTL.conf to see which blocking mode the user wants to use // It is possible to change the blocking mode here as we anyhow clear the diff --git a/src/enums.h b/src/enums.h index d38fd882d..be682a12a 100644 --- a/src/enums.h +++ b/src/enums.h @@ -160,7 +160,7 @@ enum events { RERESOLVE_HOSTNAMES_FORCE, REIMPORT_ALIASCLIENTS, PARSE_NEIGHBOR_CACHE, - RELOAD_BLOCKINGMODE, + RELOAD_BLOCKINGSTATUS, EVENTS_MAX } __attribute__ ((packed)); diff --git a/src/events.c b/src/events.c index 8f01d6b12..2051f8107 100644 --- a/src/events.c +++ b/src/events.c @@ -100,8 +100,8 @@ static const char *eventtext(const enum events event) return "PARSE_NEIGHBOR_CACHE"; case RESOLVE_NEW_HOSTNAMES: return "RESOLVE_NEW_HOSTNAMES"; - case RELOAD_BLOCKINGMODE: - return "RELOAD_BLOCKINGMODE"; + case RELOAD_BLOCKINGSTATUS: + return "RELOAD_BLOCKINGSTATUS"; case EVENTS_MAX: // fall through default: return "UNKNOWN"; diff --git a/src/signals.c b/src/signals.c index 0f6995609..1d5afbaa8 100644 --- a/src/signals.c +++ b/src/signals.c @@ -293,7 +293,7 @@ static void SIGRT_handler(int signum, siginfo_t *si, void *unused) set_event(RELOAD_PRIVACY_LEVEL); // Reload blocking mode - set_event(RELOAD_BLOCKINGMODE); + set_event(RELOAD_BLOCKINGSTATUS); } else if(rtsig == 2) { From 29cc88212ed34d378a60ae6df18437b4d3e05e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 8 Mar 2022 12:53:18 +0100 Subject: [PATCH 2/2] Change blocking mode to blocking status in comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- src/dnsmasq_interface.c | 2 +- src/signals.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index d3022cca1..5881020d1 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -1767,7 +1767,7 @@ void FTL_dnsmasq_reload(void) logg("Reloading DNS cache"); lock_shm(); - // Request reload the privacy level and blocking mode + // Request reload the privacy level and blocking status set_event(RELOAD_PRIVACY_LEVEL); set_event(RELOAD_BLOCKINGSTATUS); diff --git a/src/signals.c b/src/signals.c index 1d5afbaa8..521c77af8 100644 --- a/src/signals.c +++ b/src/signals.c @@ -292,7 +292,7 @@ static void SIGRT_handler(int signum, siginfo_t *si, void *unused) // Reload the privacy level in case the user changed it set_event(RELOAD_PRIVACY_LEVEL); - // Reload blocking mode + // Reload blocking status set_event(RELOAD_BLOCKINGSTATUS); } else if(rtsig == 2)