From 2dd28ea7fd41fbeef5a3e692b08afee175b3e671 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 19 Apr 2010 16:49:30 +0200 Subject: [PATCH] Use threadsafe time functions. --- src/alert-debuglog.c | 3 ++- src/alert-fastlog.c | 3 ++- src/counters.c | 3 ++- src/log-httplog.c | 3 ++- src/util-debug.c | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c index 9b2e7abda0..b05930677c 100644 --- a/src/alert-debuglog.c +++ b/src/alert-debuglog.c @@ -59,7 +59,8 @@ typedef struct AlertDebugLogThread_ { static void CreateTimeString (const struct timeval *ts, char *str, size_t size) { time_t time = ts->tv_sec; - struct tm *t = gmtime(&time); + struct tm local_tm; + struct tm *t = gmtime_r(&time, &local_tm); uint32_t sec = ts->tv_sec % 86400; snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", diff --git a/src/alert-fastlog.c b/src/alert-fastlog.c index 418b4a910c..53d1d5efed 100644 --- a/src/alert-fastlog.c +++ b/src/alert-fastlog.c @@ -88,7 +88,8 @@ typedef struct AlertFastLogThread_ { static void CreateTimeString (const struct timeval *ts, char *str, size_t size) { time_t time = ts->tv_sec; - struct tm *t = gmtime(&time); + struct tm local_tm; + struct tm *t = gmtime_r(&time, &local_tm); uint32_t sec = ts->tv_sec % 86400; snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", diff --git a/src/counters.c b/src/counters.c index aacf283449..a62183c091 100644 --- a/src/counters.c +++ b/src/counters.c @@ -697,7 +697,8 @@ static int SCPerfOutputCounterFileIface() memset(&tval, 0, sizeof(struct timeval)); gettimeofday(&tval, NULL); - tms = (struct tm *)localtime(&tval.tv_sec); + struct tm local_tm; + tms = (struct tm *)localtime_r(&tval.tv_sec, &local_tm); fprintf(sc_perf_op_ctx->fp, "----------------------------------------------" "---------------------\n"); diff --git a/src/log-httplog.c b/src/log-httplog.c index 343eb4f09d..388d8170d1 100644 --- a/src/log-httplog.c +++ b/src/log-httplog.c @@ -76,7 +76,8 @@ typedef struct LogHttpLogThread_ { static void CreateTimeString (const struct timeval *ts, char *str, size_t size) { time_t time = ts->tv_sec; - struct tm *t = gmtime(&time); + struct tm local_tm; + struct tm *t = gmtime_r(&time, &local_tm); uint32_t sec = ts->tv_sec % 86400; snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", diff --git a/src/util-debug.c b/src/util-debug.c index 05c73fb16f..68376201fb 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -311,7 +311,8 @@ SCError SCLogMessage(SCLogLevel log_level, char **msg, const char *file, temp_fmt[0] = '\0'; gettimeofday(&tval, NULL); - tms = localtime(&tval.tv_sec); + struct tm local_tm; + tms = localtime_r(&tval.tv_sec, &local_tm); cw = snprintf(temp, SC_LOG_MAX_LOG_MSG_LEN - (temp - *msg), "%s%d/%d/%04d -- %02d:%02d:%02d",