From 5a27d7d969d096706ad5a827869285abda855975 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 30 Oct 2024 13:55:26 +0100 Subject: [PATCH] pkg/timezone: handle TZDIR and local correctly The special value local must always be higher priority then the TZDIR env so make sure local is matched before. Without this we joined local on the TZDIR path which of course does not result in a valid timezone path. I will add a regression test in podman. Fixes: containers/podman#23550 Signed-off-by: Paul Holzinger --- pkg/timezone/timezone.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/timezone/timezone.go b/pkg/timezone/timezone.go index 1fcbd5c42..b82dc309d 100644 --- a/pkg/timezone/timezone.go +++ b/pkg/timezone/timezone.go @@ -23,18 +23,20 @@ func ConfigureContainerTimeZone(timezone, containerRunDir, mountPoint, etcPath, switch { case timezone == "": return "", nil - case os.Getenv("TZDIR") != "": - // Allow using TZDIR per: - // https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzfile.c;h=8a923d0cccc927a106dc3e3c641be310893bab4e;hb=HEAD#l149 - - timezonePath = filepath.Join(os.Getenv("TZDIR"), timezone) case timezone == "local": timezonePath, err = filepath.EvalSymlinks("/etc/localtime") if err != nil { return "", fmt.Errorf("finding local timezone for container %s: %w", containerID, err) } default: - timezonePath = filepath.Join("/usr/share/zoneinfo", timezone) + // Allow using TZDIR per: + // https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzfile.c;h=8a923d0cccc927a106dc3e3c641be310893bab4e;hb=HEAD#l149 + zoneinfo := os.Getenv("TZDIR") + if zoneinfo == "" { + // default zoneinfo location + zoneinfo = "/usr/share/zoneinfo" + } + timezonePath = filepath.Join(zoneinfo, timezone) } etcFd, err := openDirectory(etcPath)