diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c index b61a344060..1029e621f2 100644 --- a/src/alert-debuglog.c +++ b/src/alert-debuglog.c @@ -89,7 +89,7 @@ typedef struct AlertDebugLogThread_ { static void CreateTimeString (const struct timeval *ts, char *str, size_t size) { time_t time = ts->tv_sec; struct tm local_tm; - struct tm *t = (struct tm*)localtime_r(&time, &local_tm); + struct tm *t = (struct tm*)SCLocalTime(time, &local_tm); snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, diff --git a/src/alert-fastlog.c b/src/alert-fastlog.c index a7060447ee..3ed3042a33 100644 --- a/src/alert-fastlog.c +++ b/src/alert-fastlog.c @@ -110,7 +110,7 @@ typedef struct AlertFastLogThread_ { static void CreateTimeString (const struct timeval *ts, char *str, size_t size) { time_t time = ts->tv_sec; struct tm local_tm; - struct tm *t = (struct tm *)localtime_r(&time, &local_tm); + struct tm *t = (struct tm *)SCLocalTime(time, &local_tm); snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, diff --git a/src/counters.c b/src/counters.c index bbb76a0d9d..cf4f9f3e9e 100644 --- a/src/counters.c +++ b/src/counters.c @@ -1022,7 +1022,7 @@ static int SCPerfOutputCounterFileIface() gettimeofday(&tval, NULL); struct tm local_tm; - tms = (struct tm *)localtime_r(&tval.tv_sec, &local_tm); + tms = (struct tm *)SCLocalTime(tval.tv_sec, &local_tm); /* Calculate the Engine uptime */ int up_time = (int)difftime(tval.tv_sec, sc_start_time); diff --git a/src/detect.c b/src/detect.c index ad60a254f1..4a634fc7fd 100644 --- a/src/detect.c +++ b/src/detect.c @@ -587,7 +587,7 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_excl struct tm *tms; gettimeofday(&tval, NULL); struct tm local_tm; - tms = (struct tm *)localtime_r(&tval.tv_sec, &local_tm); + tms = (struct tm *)SCLocalTime(tval.tv_sec, &local_tm); fprintf(fp_engine_analysis_FD, "----------------------------------------------" "---------------------\n"); fprintf(fp_engine_analysis_FD, "Date: %" PRId32 "/%" PRId32 "/%04d -- " diff --git a/src/log-droplog.c b/src/log-droplog.c index 6404a751f9..caac9640de 100644 --- a/src/log-droplog.c +++ b/src/log-droplog.c @@ -188,7 +188,7 @@ static void LogDropLogDeInitCtx(OutputCtx *output_ctx) static void CreateTimeString (const struct timeval *ts, char *str, size_t size) { time_t time = ts->tv_sec; struct tm local_tm; - struct tm *t = (struct tm *)localtime_r(&time, &local_tm); + struct tm *t = (struct tm *)SCLocalTime(time, &local_tm); snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, diff --git a/src/log-file.c b/src/log-file.c index 224d21a443..3bbd5276b6 100644 --- a/src/log-file.c +++ b/src/log-file.c @@ -93,7 +93,7 @@ typedef struct LogFileLogThread_ { static void CreateTimeString (const struct timeval *ts, char *str, size_t size) { time_t time = ts->tv_sec; struct tm local_tm; - struct tm *t = (struct tm *)localtime_r(&time, &local_tm); + struct tm *t = (struct tm *)SCLocalTime(time, &local_tm); snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, diff --git a/src/log-filestore.c b/src/log-filestore.c index 750bbdd4ca..0991f566df 100644 --- a/src/log-filestore.c +++ b/src/log-filestore.c @@ -96,7 +96,7 @@ typedef struct LogFilestoreLogThread_ { static void CreateTimeString (const struct timeval *ts, char *str, size_t size) { time_t time = ts->tv_sec; struct tm local_tm; - struct tm *t = (struct tm *)localtime_r(&time, &local_tm); + struct tm *t = (struct tm *)SCLocalTime(time, &local_tm); snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, diff --git a/src/log-httplog.c b/src/log-httplog.c index 3e1118706b..aeeea50fc1 100644 --- a/src/log-httplog.c +++ b/src/log-httplog.c @@ -115,7 +115,7 @@ typedef struct LogHttpLogThread_ { static void CreateTimeString (const struct timeval *ts, char *str, size_t size) { time_t time = ts->tv_sec; struct tm local_tm; - struct tm *t = (struct tm *)localtime_r(&time, &local_tm); + struct tm *t = (struct tm *)SCLocalTime(time, &local_tm); snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, diff --git a/src/log-pcap.c b/src/log-pcap.c index 05f31df227..4db305addd 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -280,7 +280,7 @@ TmEcode PcapLog (ThreadVars *t, Packet *p, void *data, PacketQueue *pq, if (pl->mode == LOGMODE_SGUIL) { struct tm local_tm; - struct tm *tms = (struct tm *)localtime_r(&p->ts.tv_sec, &local_tm); + struct tm *tms = (struct tm *)SCLocalTime(p->ts.tv_sec, &local_tm); if (tms->tm_mday != pl->prev_day) { rotate = 1; pl->prev_day = tms->tm_mday; @@ -350,7 +350,7 @@ TmEcode PcapLogDataInit(ThreadVars *t, void *initdata, void **data) memset(&ts, 0x00, sizeof(struct timeval)); TimeGet(&ts); struct tm local_tm; - struct tm *tms = (struct tm *)localtime_r(&ts.tv_sec, &local_tm); + struct tm *tms = (struct tm *)SCLocalTime(ts.tv_sec, &local_tm); pl->prev_day = tms->tm_mday; *data = (void *)pl; @@ -623,7 +623,7 @@ int PcapLogOpenFileCtx(PcapLogData *pl) if (pl->mode == LOGMODE_SGUIL) { struct tm local_tm; - struct tm *tms = (struct tm *)localtime_r(&ts.tv_sec, &local_tm); + struct tm *tms = (struct tm *)SCLocalTime(ts.tv_sec, &local_tm); char dirname[32], dirfull[PATH_MAX] = ""; diff --git a/src/util-debug.c b/src/util-debug.c index 620ade1f25..b3a7342cec 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -320,7 +320,7 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file, gettimeofday(&tval, NULL); struct tm local_tm; - tms = localtime_r(&tval.tv_sec, &local_tm); + tms = SCLocalTime(tval.tv_sec, &local_tm); cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - *msg), "%s%d/%d/%04d -- %02d:%02d:%02d", diff --git a/src/util-profiling.c b/src/util-profiling.c index 00e2f80a9b..3365526fd6 100644 --- a/src/util-profiling.c +++ b/src/util-profiling.c @@ -569,7 +569,7 @@ SCProfilingDump(void) gettimeofday(&tval, NULL); struct tm local_tm; - tms = (struct tm *)localtime_r(&tval.tv_sec, &local_tm); + tms = (struct tm *)SCLocalTime(tval.tv_sec, &local_tm); fprintf(fp, " ----------------------------------------------" "----------------------------\n"); diff --git a/src/util-time.c b/src/util-time.c index 5d7eb489eb..a7a3b4c178 100644 --- a/src/util-time.c +++ b/src/util-time.c @@ -111,3 +111,8 @@ void TimeSetIncrementTime(uint32_t tv_sec) { TimeSet(&tv); } + +struct tm *SCLocalTime(time_t timep, struct tm *result) +{ + return localtime_r(&timep, result); +} diff --git a/src/util-time.h b/src/util-time.h index a413407c6b..fc18db8d51 100644 --- a/src/util-time.h +++ b/src/util-time.h @@ -46,5 +46,7 @@ void TimeSetIncrementTime(uint32_t); void TimeModeSetLive(void); void TimeModeSetOffline (void); +struct tm *SCLocalTime(time_t timep, struct tm *result); + #endif /* __UTIL_TIME_H__ */