mirror of
https://github.com/containers/podman.git
synced 2026-03-28 03:22:18 -04:00
In cases where systemd was not available, podman machine was erroring out using timedatectl (it requires systemd). on other providers like windows, we don't do any timezone detection so it seems valid to return a "" for timezone. This fixes the first problem described #25950. Fixes: https://github.com/containers/podman/issues/25950 Signed-off-by: Brent Baude <bbaude@redhat.com>
30 lines
790 B
Go
30 lines
790 B
Go
package ignition
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func getLocalTimeZone() (string, error) {
|
|
trimTzFunc := func(s string) string {
|
|
return strings.TrimPrefix(strings.TrimSuffix(s, "\n"), "Timezone=")
|
|
}
|
|
|
|
// perform a variety of ways to see if we can determine the tz
|
|
output, err := exec.Command("timedatectl", "show", "--property=Timezone").Output()
|
|
if err == nil {
|
|
return trimTzFunc(string(output)), nil
|
|
}
|
|
logrus.Debugf("Timedatectl show --property=Timezone failed: %s", err)
|
|
output, err = os.ReadFile("/etc/timezone")
|
|
if err == nil {
|
|
return trimTzFunc(string(output)), nil
|
|
}
|
|
logrus.Debugf("unable to read /etc/timezone, falling back to empty timezone: %s", err)
|
|
// if we cannot determine the tz, return empty string
|
|
return "", nil
|
|
}
|