mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Guarantee FTL's thread safety
This commit is contained in:
@@ -145,5 +145,7 @@ int setupVarsElements;
|
||||
|
||||
bool initialscan;
|
||||
bool debug;
|
||||
bool debugthreads;
|
||||
bool threadlock;
|
||||
|
||||
char ** wildcarddomains;
|
||||
|
||||
@@ -12,12 +12,18 @@
|
||||
#include "version.h"
|
||||
|
||||
bool debug = false;
|
||||
bool threaddebug = false;
|
||||
void parse_args(int argc, char* argv[])
|
||||
{
|
||||
int i;
|
||||
for(i=0; i < argc; i++) {
|
||||
if(strcmp(argv[i], "debug") == 0)
|
||||
debug = true;
|
||||
if(strcmp(argv[i], "threaddebug") == 0)
|
||||
{
|
||||
debug = true;
|
||||
threaddebug = true;
|
||||
}
|
||||
if(strcmp(argv[i], "test") == 0)
|
||||
killed = 1;
|
||||
if(strcmp(argv[i], "version") == 0)
|
||||
|
||||
@@ -43,16 +43,27 @@ void *pihole_log_thread(void *val)
|
||||
{
|
||||
int newdata = checkLogForChanges();
|
||||
|
||||
// Process new data if found
|
||||
if(newdata > 0)
|
||||
if(newdata != 0)
|
||||
{
|
||||
process_pihole_log();
|
||||
}
|
||||
|
||||
// Process flushed log
|
||||
else if(newdata < 0)
|
||||
{
|
||||
pihole_log_flushed();
|
||||
// Lock FTL data structure, since it is likely that it will be changed here
|
||||
// Requests should not be processed/answered when data is about to change
|
||||
while(threadlock) sleepms(1);
|
||||
if(debugthreads)
|
||||
logg("Thread lock enabled (pihole_log_thread)");
|
||||
threadlock = true;
|
||||
// Process new data if found
|
||||
if(newdata > 0)
|
||||
{
|
||||
process_pihole_log();
|
||||
}
|
||||
// Process flushed log
|
||||
else if(newdata < 0)
|
||||
{
|
||||
pihole_log_flushed();
|
||||
}
|
||||
threadlock = false;
|
||||
if(debugthreads)
|
||||
logg("Thread lock disabled (pihole_log_thread)");
|
||||
}
|
||||
|
||||
sleepms(50);
|
||||
|
||||
@@ -140,7 +140,12 @@ void process_request(char *client_message, int *sock)
|
||||
if(excludedomains != NULL)
|
||||
clearSetupVarsArray();
|
||||
if(debug)
|
||||
logg_int("Sent top lists data to client, ID: ", *sock);
|
||||
{
|
||||
if(blocked)
|
||||
logg_int("Sent top ads list data to client, ID: ", *sock);
|
||||
else
|
||||
logg_int("Sent top domains list data to client, ID: ", *sock);
|
||||
}
|
||||
}
|
||||
else if(command(client_message, ">top-clients"))
|
||||
{
|
||||
|
||||
@@ -157,7 +157,16 @@ void *connection_handler_thread(void *socket_desc)
|
||||
{
|
||||
char *message = calloc(strlen(client_message)+1,sizeof(char));
|
||||
strcpy(message, client_message);
|
||||
// Lock FTL data structure, since it is likely that it will be changed here
|
||||
// Requests should not be processed/answered when data is about to change
|
||||
while(threadlock) sleepms(1);
|
||||
threadlock = true;
|
||||
if(debugthreads)
|
||||
logg("Thread lock enabled (process_request)");
|
||||
process_request(message, &sock);
|
||||
threadlock = false;
|
||||
if(debugthreads)
|
||||
logg("Thread lock disabled (process_request)");
|
||||
free(message);
|
||||
if(sock == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user