Files
podman/pkg/machine/ignition/ignition_linux.go
Paul Holzinger a90fad3fc8 pkg/machine: rework getLocalTimeZone on linux
Get the timezone off the localtime symlink like systemd does it.
It is more efficient then fork/exec another command for it that may or
may not exits and the /etc/timezone files doesn't exist on most distros
so that is not a great fallback.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-05-02 11:56:47 +02:00

30 lines
748 B
Go

package ignition
import (
"errors"
"os"
"path/filepath"
"strings"
)
func getLocalTimeZone() (string, error) {
path, err := filepath.EvalSymlinks("/etc/localtime")
if err != nil {
// of the path does not exist, ignore it as the code default to UTC then
if errors.Is(err, os.ErrNotExist) {
return "", nil
}
return "", err
}
// 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"
}
// Trim of the TZDIR part to extract the actual timezone name
return strings.TrimPrefix(path, filepath.Clean(zoneinfo)+"/"), nil
}