diff --git a/clientserver.c b/clientserver.c index 7c897abc..3800f0d6 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; diff --git a/options.c b/options.c index 74b39bf6..58ed035f 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 e311240a..e05f7ec2 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 e477759a..25ac7c9b 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);