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 e916555
Show file tree
Hide file tree
Showing 3 changed files with 14 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
5 changes: 5 additions & 0 deletions test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ json-file | f
assert "$output" == "../usr/share/zoneinfo/Europe/Berlin" "localtime is linked correctly"
}

@test "podman run --tz with zoneinfo and custom TZDIR env" {
# Setting the timezone should fail because it does not exist
TZDIR="$PODMAN_TMPDIR/zoneinfo" run_podman 127 run --rm --tz Europe/Berlin "$SYSTEMD_IMAGE"
}

# run with --runtime should preserve the named runtime
@test "podman run : full path to --runtime is preserved" {
skip_if_remote "podman-remote does not support --runtime option"
Expand Down

0 comments on commit e916555

Please sign in to comment.