Skip to content

Commit

Permalink
pkg/timezone: make "local" timezone work when TZDIR is set
Browse files Browse the repository at this point in the history
More specifically, when timezone is "local", ignore the value of TZDIR
entirely - previously, ConfigureContainerTimeZone would check TZDIR
first, and then look for a literal "local" timezone.

This lead to a "/etc/zoneinfo/local: No such file or directory" error
with `podman start` on NixOS.
See: containers/podman#23550

Signed-off-by: Vivienne Watermeier <vwatermeier@igalia.com>
  • Loading branch information
vivienne-w committed Aug 9, 2024
1 parent d93f74f commit 71d2b97
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/timezone/timezone.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ 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":
// Check timezone first, otherwise we might end up looking for a literal "local" timeline if TZDIR is also set
// See: https://github.com/containers/podman/issues/23550

timezonePath, err = filepath.EvalSymlinks("/etc/localtime")
if err != nil {
return "", fmt.Errorf("finding local timezone for container %s: %w", containerID, err)
}
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)
default:
timezonePath = filepath.Join("/usr/share/zoneinfo", timezone)
}
Expand Down

0 comments on commit 71d2b97

Please sign in to comment.