From 48186a68624e6212ca0cf8da29d88c720fca56dd Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 24 Mar 2020 17:20:13 +0100 Subject: [PATCH] Add DELAY_STARTUP setting to delay startup of the embedded dnsmasq. Signed-off-by: DL6ER --- src/config.c | 13 +++++++++++++ src/config.h | 1 + src/daemon.c | 15 +++++++++++++++ src/daemon.h | 1 + src/main.c | 3 ++- 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 2ae1cd14..ad354588 100644 --- a/src/config.c +++ b/src/config.c @@ -358,6 +358,19 @@ void read_FTLconf(void) else logg(" CNAME_DEEP_INSPECT: Inactive"); + // DELAY_STARTUP + // defaults to: zero (seconds) + buffer = parse_FTLconf(fp, "DELAY_STARTUP"); + + config.delay_startup = 0; + if(buffer != NULL && sscanf(buffer, "%u", &config.delay_startup) && + (config.delay_startup > 0 && config.delay_startup <= 300)) + { + logg(" DELAY_STARTUP: Requested to wait %u seconds during startup.", config.delay_startup); + } + else + logg(" DELAY_STARTUP: No delay requested."); + // Read DEBUG_... setting from pihole-FTL.conf read_debuging_settings(fp); diff --git a/src/config.h b/src/config.h index 8ecfbbe2..fc8ff0b0 100644 --- a/src/config.h +++ b/src/config.h @@ -21,6 +21,7 @@ typedef struct { int DBinterval; int port; int maxlogage; + unsigned int delay_startup; int16_t debug; unsigned char privacylevel; unsigned char blockingmode; diff --git a/src/daemon.c b/src/daemon.c index eb21b77a..a8e1bd21 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -13,6 +13,8 @@ #include "memory.h" #include "config.h" #include "log.h" +// sleepms() +#include "timers.h" void go_daemon(void) { @@ -126,3 +128,16 @@ char *getUserName(void) return name; } + +void delay_startup(void) +{ + // Exit early if not sleeping + if(config.delay_startup == 0u) + return; + + // Sleep if requested by DELAY_STARTUP + logg("Sleeping for %d seconds as requested by configuration ...", + config.delay_startup); + sleep(config.delay_startup); + logg("Done sleeping, continuing startup of resolver...\n"); +} diff --git a/src/daemon.h b/src/daemon.h index ba153c86..d94f4cf5 100644 --- a/src/daemon.h +++ b/src/daemon.h @@ -14,5 +14,6 @@ void go_daemon(void); void savepid(void); char * getUserName(void); void removepid(void); +void delay_startup(void); #endif //DAEMON_H diff --git a/src/main.c b/src/main.c index 1c34d946..e0da19be 100644 --- a/src/main.c +++ b/src/main.c @@ -82,7 +82,8 @@ int main (int argc, char* argv[]) // immediately before starting the resolver. check_capabilities(); - // Start the resolver + // Start the resolver, delay startup if requested + delay_startup(); startup = false; main_dnsmasq(argc_dnsmasq, argv_dnsmasq);