From 902abb77a7b5ebd18d01b8dcae147ebc33cd3cbe Mon Sep 17 00:00:00 2001 From: Michal Ruprich Date: Fri, 31 Jan 2025 14:35:18 +0100 Subject: [PATCH 1/2] 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 74b39bf6a..58ed035fe 100644 --- a/options.c +++ b/options.c @@ -1159,7 +1159,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 e311240af..e05f7ec23 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 e477759a4..25ac7c9b0 100644 --- a/util1.c +++ b/util1.c @@ -1393,7 +1393,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); From 5d4f7ee744f062c16ec89747cbfbf4117024f84c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Apr 2026 12:53:13 +1000 Subject: [PATCH 2/2] call tzset() before chroot to cache timezone data localtime/localtime_r need /etc/localtime for timezone info. After chroot this file is inaccessible, causing log timestamps to fall back to UTC. Calling tzset() before chroot ensures the timezone data is cached by glibc for subsequent calls. Co-Authored-By: Claude Opus 4.6 (1M context) --- clientserver.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clientserver.c b/clientserver.c index 7c897abc4..3800f0d62 100644 --- a/clientserver.c +++ b/clientserver.c @@ -976,6 +976,8 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char } if (use_chroot) { + /* Cache timezone data before chroot makes /etc/localtime inaccessible */ + tzset(); if (chroot(module_chdir)) { rsyserr(FLOG, errno, "chroot(\"%s\") failed", module_chdir); io_printf(f_out, "@ERROR: chroot failed\n"); @@ -1301,6 +1303,7 @@ int start_daemon(int f_in, int f_out) p = lp_daemon_chroot(); if (*p) { log_init(0); /* Make use we've initialized syslog before chrooting. */ + tzset(); if (chroot(p) < 0) { rsyserr(FLOG, errno, "daemon chroot(\"%s\") failed", p); return -1;