]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
call tzset() before chroot to cache timezone data
authorAndrew Tridgell <andrew@tridgell.net>
Wed, 22 Apr 2026 02:53:13 +0000 (12:53 +1000)
committerAndrew Tridgell <andrew@tridgell.net>
Wed, 22 Apr 2026 03:02:10 +0000 (13:02 +1000)
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) <noreply@anthropic.com>
clientserver.c

index 7c897abc45713c89fd56600e680c3c922c3083a2..3800f0d62d63c7fa3567799e5e5d9df2582e66ed 100644 (file)
@@ -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;