Don't read pihole.log.1 to enhance startup speed of FTL

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2018-01-21 14:41:22 +01:00
parent a06d929bf0
commit 1ca920310e
4 changed files with 20 additions and 51 deletions
-1
View File
@@ -84,7 +84,6 @@ typedef struct {
typedef struct {
const char* log;
const char* log1;
const char* gravity;
const char* whitelist;
const char* blacklist;
+19 -48
View File
@@ -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);
+1 -1
View File
@@ -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);
-1
View File
@@ -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",