Skip to content

Commit 5a27d7d

Browse files
committed
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 <[email protected]>
1 parent a44f1f1 commit 5a27d7d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pkg/timezone/timezone.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@ func ConfigureContainerTimeZone(timezone, containerRunDir, mountPoint, etcPath,
2323
switch {
2424
case timezone == "":
2525
return "", nil
26-
case os.Getenv("TZDIR") != "":
27-
// Allow using TZDIR per:
28-
// https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzfile.c;h=8a923d0cccc927a106dc3e3c641be310893bab4e;hb=HEAD#l149
29-
30-
timezonePath = filepath.Join(os.Getenv("TZDIR"), timezone)
3126
case timezone == "local":
3227
timezonePath, err = filepath.EvalSymlinks("/etc/localtime")
3328
if err != nil {
3429
return "", fmt.Errorf("finding local timezone for container %s: %w", containerID, err)
3530
}
3631
default:
37-
timezonePath = filepath.Join("/usr/share/zoneinfo", timezone)
32+
// Allow using TZDIR per:
33+
// https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzfile.c;h=8a923d0cccc927a106dc3e3c641be310893bab4e;hb=HEAD#l149
34+
zoneinfo := os.Getenv("TZDIR")
35+
if zoneinfo == "" {
36+
// default zoneinfo location
37+
zoneinfo = "/usr/share/zoneinfo"
38+
}
39+
timezonePath = filepath.Join(zoneinfo, timezone)
3840
}
3941

4042
etcFd, err := openDirectory(etcPath)

0 commit comments

Comments
 (0)