diff --git a/src/database/database-thread.c b/src/database/database-thread.c index c5cef11b..d685953d 100644 --- a/src/database/database-thread.c +++ b/src/database/database-thread.c @@ -22,6 +22,8 @@ #include "timers.h" // global variable killed #include "signals.h" +// reimport_superclients() +#include "database/superclients.h" void *DB_thread(void *val) { @@ -74,6 +76,40 @@ void *DB_thread(void *val) if(now % 2592000L == 0) updateMACVendorRecords(); + // Reload all FTL-related lists on request + if(want_to_reload_lists) + { + want_to_reload_lists = false; + + lock_shm(); + + // Reload + // - gravity + // - exact whitelist + // - regex whitelist + // - exact blacklist + // - exact blacklist + // WITHOUT wiping the DNS cache itself + FTL_reload_all_domainlists(); + + // Reload the privacy level in case the user changed it + get_privacy_level(NULL); + + unlock_shm(); + } + + // Re-import super-clients on request + // We do this in the database thread to avoid lock-clashing + // when a signal arrives in the middle of another (locked) + // operation + if(want_to_reimport_superclients) + { + want_to_reimport_superclients = false; + lock_shm(); + reimport_superclients(); + unlock_shm(); + } + sleepms(100); } diff --git a/src/database/gravity-db.c b/src/database/gravity-db.c index 32ec6101..2df942b7 100644 --- a/src/database/gravity-db.c +++ b/src/database/gravity-db.c @@ -65,10 +65,8 @@ void gravityDB_forked(void) void gravityDB_reopen(void) { - lock_shm(); gravityDB_close(); gravityDB_open(); - unlock_shm(); } // Open gravity database diff --git a/src/signals.c b/src/signals.c index b58fb9cf..531d10b8 100644 --- a/src/signals.c +++ b/src/signals.c @@ -22,12 +22,12 @@ #include "config.h" // gettid() #include "daemon.h" -// reimport_superclients() -#include "database/superclients.h" #define BINARY_NAME "pihole-FTL" volatile sig_atomic_t killed = 0; +volatile sig_atomic_t want_to_reimport_superclients = 0; +volatile sig_atomic_t want_to_reload_lists = 0; static volatile pid_t mpid = -1; static time_t FTLstarttime = 0; extern volatile int exit_code; @@ -96,7 +96,7 @@ static void __attribute__((noreturn)) SIGSEGV_handler(int sig, siginfo_t *si, vo } log_FTL_version(true); char namebuf[16]; - logg("Process details: MID: %i",mpid); + logg("Process details: MID: %i", mpid); logg(" PID: %i", getpid()); logg(" TID: %i", gettid()); logg(" Name: %s", getthread_name(namebuf)); @@ -110,7 +110,7 @@ static void __attribute__((noreturn)) SIGSEGV_handler(int sig, siginfo_t *si, vo #if defined(SEGV_BNDERR) case SEGV_BNDERR: logg(" with code: SEGV_BNDERR (Failed address bound checks)"); break; #endif - default: logg(" with code: Unknown (%i)", si->si_code); break; + default: logg(" with code: Unknown (%i)", si->si_code); break; } // Check GLIBC availability as MUSL does not support live backtrace generation @@ -184,17 +184,8 @@ static void SIGRT_handler(int signum, siginfo_t *si, void *unused) if(rtsig == 0) { - // Reload - // - gravity - // - exact whitelist - // - regex whitelist - // - exact blacklist - // - exact blacklist - // WITHOUT wiping the DNS cache itself - FTL_reload_all_domainlists(); - - // Reload the privacy level in case the user changed it - get_privacy_level(NULL); + // Want to reload the cache without purging the dnsmasq cache + want_to_reload_lists = true; } else if(rtsig == 2) { @@ -205,7 +196,7 @@ static void SIGRT_handler(int signum, siginfo_t *si, void *unused) else if(rtsig == 3) { // Reimport super-clients from database - reimport_superclients(); + want_to_reimport_superclients = true; } } diff --git a/src/signals.h b/src/signals.h index cebfd26a..88b3995b 100644 --- a/src/signals.h +++ b/src/signals.h @@ -15,5 +15,7 @@ void handle_realtime_signals(void); pid_t main_pid(void); extern volatile sig_atomic_t killed; +extern volatile sig_atomic_t want_to_reimport_superclients; +extern volatile sig_atomic_t want_to_reload_lists; #endif //SIGNALS_H