Skip to content

Commit

Permalink
Merge pull request #1310 from pi-hole/tweak/blockind_status
Browse files Browse the repository at this point in the history
Reload blocking mode independently of incoming queries
  • Loading branch information
yubiuser authored Mar 8, 2022
2 parents cb0d42d + 29cc882 commit e62063a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
12 changes: 10 additions & 2 deletions src/database/database-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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");
Expand Down
10 changes: 2 additions & 8 deletions src/dnsmasq_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -1773,9 +1767,9 @@ 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_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
Expand Down
2 changes: 1 addition & 1 deletion src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ enum events {
RERESOLVE_HOSTNAMES_FORCE,
REIMPORT_ALIASCLIENTS,
PARSE_NEIGHBOR_CACHE,
RELOAD_BLOCKINGMODE,
RELOAD_BLOCKINGSTATUS,
EVENTS_MAX
} __attribute__ ((packed));

Expand Down
4 changes: 2 additions & 2 deletions src/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions src/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ 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
set_event(RELOAD_BLOCKINGMODE);
// Reload blocking status
set_event(RELOAD_BLOCKINGSTATUS);
}
else if(rtsig == 2)
{
Expand Down

0 comments on commit e62063a

Please sign in to comment.