mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Don't read pihole.log.1 to enhance startup speed of FTL
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -84,7 +84,6 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
const char* log;
|
||||
const char* log1;
|
||||
const char* gravity;
|
||||
const char* whitelist;
|
||||
const char* blacklist;
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user