From d2037f4b549e221466ef8f78d13af16d27513617 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 9 May 2021 08:42:36 +0200 Subject: [PATCH] Improve warning message when importing queries from the future (a typical problem of systems starting at 1970-01-01 on every boot). Also, show the warning only once instead of flooding the log file. Signed-off-by: DL6ER --- src/config.c | 8 +++++++- src/overTime.c | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index b79423d68..0ae3c300e 100644 --- a/src/config.c +++ b/src/config.c @@ -236,10 +236,16 @@ void read_FTLconf(void) buffer = parse_FTLconf(fp, "MAXLOGAGE"); fvalue = 0; + const char *hint = ""; if(buffer != NULL && sscanf(buffer, "%f", &fvalue)) + { if(fvalue >= 0.0f && fvalue <= 1.0f*MAXLOGAGE) config.maxlogage = (int)(fvalue * 3600); - logg(" MAXLOGAGE: Importing up to %.1f hours of log data", (float)config.maxlogage/3600.0f); + else if(fvalue > 1.0f*MAXLOGAGE) + hint = " (value has been clipped to " str(MAXLOGAGE) " hours)"; + } + logg(" MAXLOGAGE: Importing up to %.1f hours of log data%s", + (float)config.maxlogage/3600.0f, hint); // PRIVACYLEVEL // Specify if we want to anonymize the DNS queries somehow, available options are: diff --git a/src/overTime.c b/src/overTime.c index 16d5437bd..56c7eaba6 100644 --- a/src/overTime.c +++ b/src/overTime.c @@ -78,6 +78,7 @@ void initOverTime(void) } } +bool warned_about_hwclock = false; unsigned int getOverTimeID(time_t timestamp) { // Center timestamp in OVERTIME_INTERVAL @@ -93,13 +94,19 @@ unsigned int getOverTimeID(time_t timestamp) // Check bounds manually if(id < 0) { - logg("WARN: getOverTimeID(%llu): %u is negative: %llu", (long long)timestamp, id, (long long)firstTimestamp); // Return first timestamp in case negative timestamp was determined return 0; } else if(id > OVERTIME_SLOTS-1) { - logg("WARN: getOverTimeID(%llu): %i is too large: %llu", (long long)timestamp, id, (long long)firstTimestamp); + if(!warned_about_hwclock) + { + const time_t lastTimestamp = overTime[OVERTIME_SLOTS-1].timestamp; + logg("WARN: Found database entries in the future (%llu, last: %llu). " + "Your over-time statistics may be incorrect", + (long long)timestamp, (long long)lastTimestamp); + warned_about_hwclock = true; + } // Return last timestamp in case a too large timestamp was determined return OVERTIME_SLOTS-1; }