diff --git a/FTL.h b/FTL.h index 0f457aff..d4d7f0d6 100644 --- a/FTL.h +++ b/FTL.h @@ -84,7 +84,6 @@ typedef struct { typedef struct { const char* log; - const char* log1; const char* gravity; const char* whitelist; const char* blacklist; diff --git a/parser.c b/parser.c index 735b6cc4..fbab1428 100644 --- a/parser.c +++ b/parser.c @@ -28,9 +28,7 @@ int loggeneration = 0; void initial_log_parsing(void) { initialscan = true; - if(config.include_yesterday) - process_pihole_log(1); - process_pihole_log(0); + process_pihole_log(); initialscan = false; } @@ -154,7 +152,7 @@ void *pihole_log_thread(void *val) if(newdata > 0 && !flush) { // Process new data if found only in main log (file 0) - process_pihole_log(0); + process_pihole_log(); } else { @@ -165,11 +163,9 @@ void *pihole_log_thread(void *val) // Reset file size and position oldfilesize = 0; lastpos = 0; - // Rescan files 0 (pihole.log) and 1 (pihole.log.1) + // Rescan pihole.log initialscan = true; - if(config.include_yesterday) - process_pihole_log(1); - process_pihole_log(0); + process_pihole_log(); needGC = true; initialscan = false; } @@ -220,40 +216,22 @@ bool checkQuery(char * readbuffer, const char * type) return true; } -void process_pihole_log(int file) +void process_pihole_log(void) { int i; char *readbuffer = NULL; size_t size1 = 0; FILE *fp; - if(file == 0) - { - // Read from pihole.log - if((fp = fopen(files.log, "r")) == NULL) { - logg("Warning: Reading of log file %s failed", files.log); - return; - } - // Skip to last read position - fseek(fp, lastpos, SEEK_SET); - if(initialscan) - get_file_permissions(files.log); - } - else if(file == 1) - { - // Read from pihole.log.1 - if((fp = fopen(files.log1, "r")) == NULL) { - logg("Warning: Reading of rotated log file %s failed", files.log1); - return; - } - if(initialscan) - get_file_permissions(files.log1); - } - else - { - logg("Error: Passed unknown file identifier (%i)", file); + // Read from pihole.log + if((fp = fopen(files.log, "r")) == NULL) { + logg("Warning: Reading of log file %s failed", files.log); return; } + // Skip to last read position + fseek(fp, lastpos, SEEK_SET); + if(initialscan) + get_file_permissions(files.log); long int fposbck = ftell(fp); @@ -918,15 +896,12 @@ void process_pihole_log(int file) fposbck = ftell(fp); // Return early if data structure is flushed - if(file == 0) + if(checkLogForChanges() < 0) { - if(checkLogForChanges() < 0) - { - logg("Notice: Returning early from log parsing for flushing"); - fclose(fp); - flush = true; - return; - } + logg("Notice: Returning early from log parsing for flushing"); + fclose(fp); + flush = true; + return; } } @@ -937,12 +912,8 @@ void process_pihole_log(int file) if(readbuffer != NULL) free(readbuffer); - // IF we are reading the main log, we want to store the last read - // position so that we can jump to this position in the next round - if(file == 0) - { - lastpos = ftell(fp); - } + // We want to store the last read position so that we can jump to this position in the next round + lastpos = ftell(fp); // Close file when parsing is finished fclose(fp); diff --git a/routines.h b/routines.h index 1a3d28e4..fe5fb1db 100644 --- a/routines.h +++ b/routines.h @@ -27,7 +27,7 @@ void initial_log_parsing(void); long int checkLogForChanges(void); void open_pihole_log(void); void handle_signals(void); -void process_pihole_log(int file); +void process_pihole_log(void); void *pihole_log_thread(void *val); void validate_access(const char * name, int pos, bool testmagic, int line, const char * function, const char * file); void validate_access_oTfd(int timeidx, int forwardID, int line, const char * function, const char * file); diff --git a/structs.c b/structs.c index aa78aa9c..b49228fb 100644 --- a/structs.c +++ b/structs.c @@ -21,7 +21,6 @@ FTLFileNamesStruct FTLfiles = { logFileNamesStruct files = { "/var/log/pihole.log", - "/var/log/pihole.log.1", "/etc/pihole/list.preEventHorizon", "/etc/pihole/whitelist.txt", "/etc/pihole/blacklist.txt",