Skip to content

Commit

Permalink
pkg/timezone: handle TZDIR and local correctly
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Luap99 authored and kwilczynski committed Nov 24, 2024
1 parent 18930ed commit c8f4e8b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/timezone/timezone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c8f4e8b

Please sign in to comment.