diff --git a/gc.c b/gc.c index 25676918..cdfd407b 100644 --- a/gc.c +++ b/gc.c @@ -42,13 +42,16 @@ void *GC_thread(void *val) mintime -= mintime % 3600; mintime += 3600; - if(config.debug & DEBUG_GC) timer_start(GC_TIMER); - - int removed = 0; - char ctimebuffer[32]; // need at least 26 bytes according to ctime_r man page - if(config.debug & DEBUG_GC) logg("GC starting, mintime: %lu %s", mintime, ctime_r(&mintime, ctimebuffer)); + if(config.debug & DEBUG_GC) + { + timer_start(GC_TIMER); + char timestring[84] = ""; + get_timestr(timestring, mintime); + logg("GC starting, mintime: %s (%lu)", timestring, mintime); + } // Process all queries + int removed = 0; for(long int i=0; i < counters->queries; i++) { queriesData* query = getQuery(i, true); diff --git a/log.c b/log.c index 64340e8f..1d617b47 100644 --- a/log.c +++ b/log.c @@ -50,11 +50,10 @@ void open_FTL_log(const bool test) } } -static void get_timestr(char *timestring) +void get_timestr(char *timestring, const time_t timein) { - const time_t t = time(NULL); struct tm tm; - localtime_r(&t, &tm); + localtime_r(&timein, &tm); struct timeval tv; gettimeofday(&tv, NULL); @@ -70,7 +69,7 @@ void __attribute__ ((format (gnu_printf, 1, 2))) logg(const char *format, ...) pthread_mutex_lock(&lock); - get_timestr(timestring); + get_timestr(timestring, time(NULL)); // Get and log PID of current process to avoid ambiguities when more than one // pihole-FTL instance is logging into the same file diff --git a/routines.h b/routines.h index 45370413..c5673641 100644 --- a/routines.h +++ b/routines.h @@ -21,6 +21,7 @@ void logg(const char* format, ...) __attribute__ ((format (gnu_printf, 1, 2))); void log_counter_info(void); void format_memory_size(char *prefix, unsigned long int bytes, double *formated); void log_FTL_version(bool crashreport); +void get_timestr(char *timestring, const time_t timein); // datastructure.c void strtolower(char *str);