Guarantee FTL's thread safety

This commit is contained in:
DL6ER
2017-03-08 11:47:58 +01:00
parent fa99b5b88d
commit 6ccfeea2da
5 changed files with 43 additions and 10 deletions
+2
View File
@@ -145,5 +145,7 @@ int setupVarsElements;
bool initialscan;
bool debug;
bool debugthreads;
bool threadlock;
char ** wildcarddomains;
+6
View File
@@ -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)
+20 -9
View File
@@ -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);
+6 -1
View File
@@ -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"))
{
+9
View File
@@ -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)
{