2022-09-08 22:34:08 +02:00
|
|
|
//go:build linux
|
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-11-10 11:08:34 +01:00
|
|
|
"os"
|
|
|
|
"time"
|
2022-09-08 22:34:08 +02:00
|
|
|
_ "time/tzdata"
|
|
|
|
|
|
|
|
reaper "github.com/ramr/go-reaper"
|
|
|
|
)
|
|
|
|
|
|
|
|
//nolint:gochecknoinits
|
|
|
|
func init() {
|
|
|
|
go reaper.Reap()
|
2022-11-10 11:08:34 +01:00
|
|
|
|
2022-11-11 22:23:11 +01:00
|
|
|
setLocaltime()
|
|
|
|
}
|
|
|
|
|
|
|
|
// set localtime to /etc/localtime if available
|
|
|
|
// or modify the system time with the TZ environment variable if it is provided
|
|
|
|
func setLocaltime() {
|
|
|
|
// load /etc/localtime without modifying it
|
|
|
|
if lt, err := os.ReadFile("/etc/localtime"); err == nil {
|
|
|
|
if t, err := time.LoadLocationFromTZData("", lt); err == nil {
|
|
|
|
time.Local = t
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// use zoneinfo from time/tzdata and set location with the TZ environment variable
|
2022-11-10 11:08:34 +01:00
|
|
|
if tz := os.Getenv("TZ"); tz != "" {
|
2022-11-11 22:23:11 +01:00
|
|
|
if t, err := time.LoadLocation(tz); err == nil {
|
|
|
|
time.Local = t
|
2022-11-10 11:08:34 +01:00
|
|
|
|
2022-11-11 22:23:11 +01:00
|
|
|
return
|
2022-11-10 11:08:34 +01:00
|
|
|
}
|
|
|
|
}
|
2022-09-08 22:34:08 +02:00
|
|
|
}
|