From c966f3864d79aae6a4b97e78403f7441325edded Mon Sep 17 00:00:00 2001
From: Michal Ruprich <mruprich@redhat.com>
Date: Fri, 31 Jan 2025 14:35:18 +0100
Subject: [PATCH 04/43] Using a correct time in log file

---
 options.c | 2 +-
 tls.c     | 2 +-
 util1.c   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/options.c b/options.c
index 7cfe6391..4ae1c58c 100644
--- a/options.c
+++ b/options.c
@@ -1156,7 +1156,7 @@ static time_t parse_time(const char *arg)
 {
 	const char *cp;
 	time_t val, now = time(NULL);
-	struct tm t, *today = localtime(&now);
+	struct tm t, tmp, *today = localtime_r(&now, &tmp);
 	int in_date, old_mday, n;
 
 	memset(&t, 0, sizeof t);
diff --git a/tls.c b/tls.c
index 858f8f10..7811e1fc 100644
--- a/tls.c
+++ b/tls.c
@@ -127,7 +127,7 @@ static void storetime(char *dest, size_t destsize, time_t t, int nsecs)
 {
 	if (t) {
 		int len;
-		struct tm *mt = gmtime(&t);
+		struct tm tmp, *mt = gmtime_r(&t, &tmp);
 
 		len = snprintf(dest, destsize,
 			" %04d-%02d-%02d %02d:%02d:%02d",
diff --git a/util1.c b/util1.c
index d84bc414..231d2206 100644
--- a/util1.c
+++ b/util1.c
@@ -1389,7 +1389,7 @@ char *timestring(time_t t)
 	static int ndx = 0;
 	static char buffers[4][20]; /* We support 4 simultaneous timestring results. */
 	char *TimeBuf = buffers[ndx = (ndx + 1) % 4];
-	struct tm *tm = localtime(&t);
+	struct tm tmp, *tm = localtime_r(&t, &tmp);
 	int len = snprintf(TimeBuf, sizeof buffers[0], "%4d/%02d/%02d %02d:%02d:%02d",
 		 (int)tm->tm_year + 1900, (int)tm->tm_mon + 1, (int)tm->tm_mday,
 		 (int)tm->tm_hour, (int)tm->tm_min, (int)tm->tm_sec);
-- 
2.51.0

