Skip to content

Commit

Permalink
Allow searching $TZDIR for timezone data
Browse files Browse the repository at this point in the history
glibc supports the environment variable as additional search path, means
we allow to override the `/usr/share/zoneinfo` path by setting the
variable.

Analogous change to containers/common#1772

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Dec 20, 2023
1 parent 65266a3 commit addc398
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/source/markdown/options/tz.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
####> are applicable to all of those.
#### **--tz**=*timezone*

Set timezone in container. This flag takes area-based timezones, GMT time, as well as `local`, which sets the timezone in the container to match the host machine. See `/usr/share/zoneinfo/` for valid timezones.
Set timezone in container. This flag takes area-based timezones, GMT time, as well as `local`, which sets the timezone in the container to match the host machine. See `/usr/share/zoneinfo/` for valid timezones. Podman honors the `$TZDIR` environment variable to modify the `/usr/share/zoneinfo` search path for valid timezones.
Remote connections use local containers.conf for defaults
8 changes: 8 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,14 @@ func (c *Container) mountStorage() (_ string, deferredErr error) {
tz := c.Timezone()
if tz != "" {
timezonePath := filepath.Join("/usr/share/zoneinfo", tz)

// Allow using TZDIR per:
// https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzfile.c;h=8a923d0cccc927a106dc3e3c641be310893bab4e;hb=HEAD#l149
tzdir := os.Getenv("TZDIR")
if tzdir != "" {
timezonePath = filepath.Join(tzdir, tz)
}

if tz == "local" {
timezonePath, err = filepath.EvalSymlinks("/etc/localtime")
if err != nil {
Expand Down

0 comments on commit addc398

Please sign in to comment.