Use get_timestr() instead of ctime_r() to obtain string representation of a timestamp

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2019-04-23 11:18:42 +02:00
parent c323245990
commit c6785115fe
3 changed files with 12 additions and 9 deletions

13
gc.c
View File

@@ -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);

7
log.c
View File

@@ -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

View File

@@ -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);