diff --git a/FTL.h b/FTL.h index 6d9e541d..233e57c0 100644 --- a/FTL.h +++ b/FTL.h @@ -47,6 +47,12 @@ #define SOCKETBUFFERLEN 1024 // Static structs +typedef struct { + const char* log; + const char* pid; + const char* port; +} FTLFileNamesStruct; + typedef struct { const char* log; const char* gravity; @@ -112,6 +118,7 @@ typedef struct { enum { QUERIES, FORWARDED, CLIENTS, DOMAINS }; logFileNamesStruct files; +FTLFileNamesStruct FTLfiles; countersStruct counters; queriesDataStruct *queries; diff --git a/daemon.c b/daemon.c index 53ade7a4..b60d45bd 100644 --- a/daemon.c +++ b/daemon.c @@ -13,7 +13,7 @@ bool test_singularity(void) { FILE *f; - if((f = fopen("/etc/pihole/FTL.pid", "r")) == NULL) + if((f = fopen(FTLfiles.pid, "r")) == NULL) { logg("WARNING: Unable to read PID from file."); logg(" Cannot test if another FTL process is running!"); diff --git a/log.c b/log.c index 05413cb0..467d9c99 100644 --- a/log.c +++ b/log.c @@ -13,13 +13,9 @@ void open_FTL_log(void) { // Open a log file in write mode. - if((logfile = fopen("/etc/pihole/FTL.log", "a+")) == NULL) {; - printf("FATAL: Opening of /etc/pihole/FTL.log failed!\n"); + if((logfile = fopen(FTLfiles.log, "a+")) == NULL) {; + printf("FATAL: Opening of FTL log (%s) failed!\n",FTLfiles.log); printf(" Make sure it exists and is writable using\n"); - printf(" sudo touch /etc/pihole/FTL.log\n"); - printf(" sudo touch /etc/pihole/FTL.port\n"); - printf(" sudo touch /etc/pihole/FTL.pid\n"); - printf(" sudo chown user:user /etc/pihole/FTL.*\n"); // Return failure in exit status exit(1); } diff --git a/socket.c b/socket.c index 2478bdeb..2c30bec1 100644 --- a/socket.c +++ b/socket.c @@ -154,7 +154,7 @@ void swrite(void) void saveport(int port) { FILE *f; - if((f = fopen("/etc/pihole/FTL.port", "w+")) == NULL) + if((f = fopen(FTLfiles.port, "w+")) == NULL) { logg("WARNING: Unable to write used port to file."); logg(" Continuing anyway (API might not find the port)."); diff --git a/structs.c b/structs.c index aea542e3..54a2819b 100644 --- a/structs.c +++ b/structs.c @@ -10,6 +10,15 @@ #include "FTL.h" +FTLFileNamesStruct FTLfiles = { + "/etc/pihole/pihole-FTL.log", + "/etc/pihole/pihole-FTL.pid", + "/etc/pihole/pihole-FTL.port" + // "/var/log/pihole-FTL.log", + // "/var/run/pihole-FTL.pid", + // "/var/run/pihole-FTL.port" +}; + logFileNamesStruct files = { "/var/log/pihole.log", "/etc/pihole/list.preEventHorizon",