diff options
-rw-r--r-- | .SRCINFO | 8 | ||||
-rw-r--r-- | 167.patch | 170 | ||||
-rw-r--r-- | 172.patch | 107 | ||||
-rw-r--r-- | PKGBUILD | 22 | ||||
-rw-r--r-- | pi-hole-ftl.conf | 4 |
5 files changed, 300 insertions, 11 deletions
@@ -1,7 +1,7 @@ pkgbase = pi-hole-ftl pkgdesc = The Pi-hole FTL engine pkgver = 2.12 - pkgrel = 2 + pkgrel = 3 url = https://github.com/pi-hole/FTL install = pi-hole-ftl.install arch = i686 @@ -18,11 +18,15 @@ pkgbase = pi-hole-ftl source = pi-hole-ftl.service source = pi-hole-ftl.conf source = pi-hole-ftl.sysuser + source = 167.patch + source = 172.patch md5sums = 97b328deae11133d489db76006ecd0a6 md5sums = a10e77e81c900819dfe78e1484e1e226 md5sums = 0f65203b2585fb83e02826091d220386 - md5sums = b332db50cf66e01d919cc426a31316f7 + md5sums = 2d6ae93eea48a09ce5bc5bf62e081dd4 md5sums = 68e78907dc2a0c89421d02377e76d353 + md5sums = 2f328c04db7e096bf3308a7cb7115798 + md5sums = 2aa307ca6d7145156541d9bed6003fdf pkgname = pi-hole-ftl diff --git a/167.patch b/167.patch new file mode 100644 index 000000000000..aa8b36e2cf25 --- /dev/null +++ b/167.patch @@ -0,0 +1,170 @@ +diff --git a/FTL.h b/FTL.h +index d751f93..f142176 100644 +--- a/FTL.h ++++ b/FTL.h +@@ -76,7 +76,7 @@ typedef struct { + const char* log; + const char* pid; + const char* port; +- const char* db; ++ char* db; + } FTLFileNamesStruct; + + typedef struct { +diff --git a/config.c b/config.c +index c854ec0..db3f5a2 100644 +--- a/config.c ++++ b/config.c +@@ -130,8 +130,31 @@ void read_FTLconf(void) + else + logg(" RESOLVE_IPV4: Don\'t resolve IPv4 addresses"); + ++ // DBFILE ++ // defaults to: "/etc/pihole/pihole-FTL.db" ++ buffer = parse_FTLconf(fp, "DBFILE"); ++ ++ if(buffer != NULL && sscanf(buffer, "%127ms", &FTLfiles.db)) ++ { ++ // Using custom path ++ } ++ else ++ { ++ FTLfiles.db = strdup("/etc/pihole/pihole-FTL.db"); ++ } ++ ++ // Test if memory allocation was successful ++ if(FTLfiles.db == NULL) ++ { ++ logg("FATAL: Allocating memory for FTLfiles.db failed (%i). Exiting.", errno); ++ exit(EXIT_FAILURE); ++ } ++ ++ logg(" DBFILE: Using %s", FTLfiles.db); ++ + logg("Finished config file parsing"); + ++ // Release memory + if(conflinebuffer != NULL) + { + free(conflinebuffer); +diff --git a/structs.c b/structs.c +index fe22f8b..2e7abcd 100644 +--- a/structs.c ++++ b/structs.c +@@ -15,7 +15,7 @@ FTLFileNamesStruct FTLfiles = { + "/var/log/pihole-FTL.log", + "/var/run/pihole-FTL.pid", + "/var/run/pihole-FTL.port", +- "/etc/pihole/pihole-FTL.db" ++ NULL + }; + + logFileNamesStruct files = { + +diff --git a/args.c b/args.c +index bee1ce0..563c71a 100644 +--- a/args.c ++++ b/args.c +@@ -113,7 +113,7 @@ void parse_args(int argc, char* argv[]) + { + travis = true; + FTLfiles.log = "pihole-FTL.log"; +- FTLfiles.db = "pihole-FTL.db"; ++ // FTLfiles.db will be set to "pihole-FTL.db" via config file on Travis + files.log = "pihole.log"; + ok = true; + } +diff --git a/config.c b/config.c +index db3f5a2..fc4a7a8 100644 +--- a/config.c ++++ b/config.c +@@ -134,23 +134,23 @@ void read_FTLconf(void) + // defaults to: "/etc/pihole/pihole-FTL.db" + buffer = parse_FTLconf(fp, "DBFILE"); + +- if(buffer != NULL && sscanf(buffer, "%127ms", &FTLfiles.db)) +- { +- // Using custom path +- } +- else ++ errno = 0; ++ if(!(buffer != NULL && sscanf(buffer, "%127ms", &FTLfiles.db))) + { ++ // Use standard path if no custom path was obtained from the config file + FTLfiles.db = strdup("/etc/pihole/pihole-FTL.db"); + } + + // Test if memory allocation was successful +- if(FTLfiles.db == NULL) ++ if(FTLfiles.db == NULL && errno != 0) + { +- logg("FATAL: Allocating memory for FTLfiles.db failed (%i). Exiting.", errno); ++ logg("FATAL: Allocating memory for FTLfiles.db failed (%s, %i). Exiting.", strerror(errno), errno); + exit(EXIT_FAILURE); + } +- +- logg(" DBFILE: Using %s", FTLfiles.db); ++ else if(FTLfiles.db != NULL && strlen(FTLfiles.db) > 0) ++ logg(" DBFILE: Using %s", FTLfiles.db); ++ else ++ logg(" DBFILE: Not using database due to empty filename"); + + logg("Finished config file parsing"); + +diff --git a/database.c b/database.c +index 110d60b..0c8f3ca 100644 +--- a/database.c ++++ b/database.c +@@ -128,6 +128,14 @@ bool db_create(void) + + void db_init(void) + { ++ // First check if the user doesn't want to use the database and set an ++ // empty string as file name in FTL's config file ++ if(FTLfiles.db == NULL || strlen(FTLfiles.db) == 0) ++ { ++ database = false; ++ return; ++ } ++ + int rc = sqlite3_open_v2(FTLfiles.db, &db, SQLITE_OPEN_READWRITE, NULL); + if( rc ){ + logg("db_init() - Cannot open database (%i): %s", rc, sqlite3_errmsg(db)); +diff --git a/args.c b/args.c +index 563c71a..16cfedd 100644 +--- a/args.c ++++ b/args.c +@@ -114,6 +114,7 @@ void parse_args(int argc, char* argv[]) + travis = true; + FTLfiles.log = "pihole-FTL.log"; + // FTLfiles.db will be set to "pihole-FTL.db" via config file on Travis ++ FTLfiles.conf = "pihole-FTL.conf"; + files.log = "pihole.log"; + ok = true; + } +diff --git a/config.c b/config.c +index fc4a7a8..d17e6ca 100644 +--- a/config.c ++++ b/config.c +@@ -28,7 +28,7 @@ void read_FTLconf(void) + } + + // Parse lines in the config file +- logg("Starting config file parsing"); ++ logg("Starting config file parsing (%s)", FTLfiles.conf); + + // SOCKET_LISTENING + // defaults to: listen only local + +diff --git a/config.c b/config.c +index d17e6ca..29b2e00 100644 +--- a/config.c ++++ b/config.c +@@ -135,6 +135,7 @@ void read_FTLconf(void) + buffer = parse_FTLconf(fp, "DBFILE"); + + errno = 0; ++ // Use sscanf() to obtain filename from config file parameter only if buffer != NULL + if(!(buffer != NULL && sscanf(buffer, "%127ms", &FTLfiles.db))) + { + // Use standard path if no custom path was obtained from the config file diff --git a/172.patch b/172.patch new file mode 100644 index 000000000000..b9a2ab953f76 --- /dev/null +++ b/172.patch @@ -0,0 +1,107 @@ +diff --git a/FTL.h b/FTL.h +index d751f93..42549dc 100644 +--- a/FTL.h ++++ b/FTL.h +@@ -66,10 +66,6 @@ + // Default -60 (one minute before a full hour) + #define GCdelay (-60) + +-// How often do we dump into FTL's database? +-// Default: 60 (once per minute) +-#define DBinterval 60 +- + // Static structs + typedef struct { + const char* conf; +@@ -125,6 +121,7 @@ typedef struct { + int maxDBdays; + bool resolveIPv6; + bool resolveIPv4; ++ int DBinterval; + } ConfigStruct; + + // Dynamic structs +diff --git a/config.c b/config.c +index c854ec0..6a2f126 100644 +--- a/config.c ++++ b/config.c +@@ -130,6 +130,26 @@ void read_FTLconf(void) + else + logg(" RESOLVE_IPV4: Don\'t resolve IPv4 addresses"); + ++ // DBINTERVAL ++ // How often do we store queries in FTL's database [minutes]? ++ // this value can be a floating point number, e.g. "DBINTERVAL=0.5" ++ // defaults to: 1 (once per minute) ++ config.DBinterval = 1; ++ buffer = parse_FTLconf(fp, "DBINTERVAL"); ++ ++ float fvalue = 0; ++ if(buffer != NULL && sscanf(buffer, "%f", &fvalue)) ++ // check if the read value is ++ // - larger than 0.1min (6sec), and ++ // - smaller than 43200 (once a month) ++ if(fvalue >= 0.1 && fvalue <= 43200.0) ++ config.DBinterval = (int)(60.*fvalue); ++ ++ if(config.DBinterval == 60) ++ logg(" DBINTERVAL: saving to DB file every minute"); ++ else ++ logg(" DBINTERVAL: saving to DB file every %i seconds", config.DBinterval); ++ + logg("Finished config file parsing"); + + if(conflinebuffer != NULL) +diff --git a/main.c b/main.c +index f748bc2..28b18e6 100644 +--- a/main.c ++++ b/main.c +@@ -86,7 +86,7 @@ int main (int argc, char* argv[]) { + if(((time(NULL) - GCdelay)%GCinterval) == 0) + runGCthread = true; + +- if(database && ((time(NULL)%DBinterval) == 0)) ++ if(database && ((time(NULL)%config.DBinterval) == 0)) + runDBthread = true; + + // Garbadge collect in regular interval, but don't do it if the threadlocks is set +@@ -134,7 +134,7 @@ int main (int argc, char* argv[]) { + } + + // Avoid immediate re-run of DB thread +- while(((time(NULL)%DBinterval) == 0)) ++ while(((time(NULL)%config.DBinterval) == 0)) + sleepms(100); + } + +diff --git a/config.c b/config.c +index 56cbbe8..a2697e8 100644 +--- a/config.c ++++ b/config.c +@@ -141,8 +141,8 @@ void read_FTLconf(void) + if(buffer != NULL && sscanf(buffer, "%f", &fvalue)) + // check if the read value is + // - larger than 0.1min (6sec), and +- // - smaller than 43200 (once a month) +- if(fvalue >= 0.1 && fvalue <= 43200.0) ++ // - smaller than 1440.0min (once a day) ++ if(fvalue >= 0.1 && fvalue <= 1440.0) + config.DBinterval = (int)(60.*fvalue); + + if(config.DBinterval == 60) + +diff --git a/config.c b/config.c +index a2697e8..b8880d9 100644 +--- a/config.c ++++ b/config.c +@@ -133,8 +133,8 @@ void read_FTLconf(void) + // DBINTERVAL + // How often do we store queries in FTL's database [minutes]? + // this value can be a floating point number, e.g. "DBINTERVAL=0.5" +- // defaults to: 1 (once per minute) +- config.DBinterval = 1; ++ // defaults to: once per minute ++ config.DBinterval = 60; + buffer = parse_FTLconf(fp, "DBINTERVAL"); + + float fvalue = 0; @@ -3,7 +3,7 @@ pkgname=pi-hole-ftl _pkgname=FTL pkgver=2.12 -pkgrel=2 +pkgrel=3 arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64') pkgdesc="The Pi-hole FTL engine" url="https://github.com/pi-hole/FTL" @@ -16,20 +16,26 @@ source=("https://github.com/pi-hole/FTL/archive/v$pkgver.tar.gz" "$pkgname.tmpfile" "$pkgname.service" "$pkgname.conf" - "$pkgname.sysuser") + "$pkgname.sysuser" + 167.patch + 172.patch) md5sums=('97b328deae11133d489db76006ecd0a6' 'a10e77e81c900819dfe78e1484e1e226' '0f65203b2585fb83e02826091d220386' - 'b332db50cf66e01d919cc426a31316f7' - '68e78907dc2a0c89421d02377e76d353') + '2d6ae93eea48a09ce5bc5bf62e081dd4' + '68e78907dc2a0c89421d02377e76d353' + '2f328c04db7e096bf3308a7cb7115798' + '2aa307ca6d7145156541d9bed6003fdf') prepare() { _ssc="/tmp/sedcontrol" - # as of 2.12 - # adjusted db commit timings - sed -i "s|#define DBinterval 60|#define DBinterval 3600|w $_ssc" "$srcdir"/$_pkgname-$pkgver/FTL.h - if [ -s $_ssc ] ; then rm $_ssc ; else echo " ==> Sed error: adjusted db commit timings" && return 1 ; fi + # pull #172 - Make DB interval adjustable + # pull #167 - Make long-term database location adjustable + cd "$srcdir"/"$_pkgname"-"$pkgver" + patch -p1 -i "$srcdir"/172.patch + patch -p1 -i "$srcdir"/167.patch + cd "$srcdir" # git descriptions setup sed -i "s|^GIT_BRANCH := .*$|GIT_BRANCH := master|w $_ssc" "$srcdir"/$_pkgname-$pkgver/Makefile diff --git a/pi-hole-ftl.conf b/pi-hole-ftl.conf index ddecd614f57c..8ca077a67305 100644 --- a/pi-hole-ftl.conf +++ b/pi-hole-ftl.conf @@ -4,4 +4,6 @@ QUERY_DISPLAY=yes AAAA_QUERY_ANALYSIS=yes MAXDBDAYS=365 RESOLVE_IPV6=yes -RESOLVE_IPV4=yes
\ No newline at end of file +RESOLVE_IPV4=yes +DBINTERVAL=1.0 +DBFILE=/etc/pihole/pihole-FTL.db
\ No newline at end of file |