diff options
author | Tiwei Bie <tiwei.btw@antgroup.com> | 2021-07-07 16:39:48 +0800 |
---|---|---|
committer | Tiwei Bie <tiwei.btw@antgroup.com> | 2021-07-09 10:14:17 +0800 |
commit | c7ac581049cf623067ff143b76ca20401077ab5f (patch) | |
tree | 3257480bf8debf0bc0ea02e90b5ed8fbc5f076cf /runsc/cmd/gofer.go | |
parent | c4c5f4d92a13aa5357002fe5ddf116433ec4e9a7 (diff) |
runsc: fix the local timezone support in logs
This patch fixes the local timezone support in logs by creating
etc/localtime in the rootfs of sandbox process and gofer process
based on the current /etc/localtime on host.
Before this patch, the timestamps in sandbox and gofer logs will
fallback to UTC timezone after execving "/proc/self/exe" which
may not be very convenient for users to analyse the logs:
I0708 15:37:43.825100 1 chroot.go:69] Setting up sandbox chroot in "/tmp"
I0708 15:37:43.825189 1 chroot.go:31] Mounting "proc" at "/tmp/proc"
......
I0708 15:37:43.850926 1 cmd.go:73] Execve "/proc/self/exe" again, bye!
I0708 07:37:43.856719 1 main.go:218] ***************************
I0708 07:37:43.856751 1 main.go:219] Args: [runsc-sandbox --root=/run/...]
I0708 07:37:43.856785 1 main.go:220] Version release-20210628.0-27-g02fec8dba5a6
I0708 07:37:43.856795 1 main.go:221] GOOS: linux
I0708 07:37:43.856803 1 main.go:222] GOARCH: amd64
......
Fixes #1984
Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
Diffstat (limited to 'runsc/cmd/gofer.go')
-rw-r--r-- | runsc/cmd/gofer.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/runsc/cmd/gofer.go b/runsc/cmd/gofer.go index 181bae3e2..c2922bf13 100644 --- a/runsc/cmd/gofer.go +++ b/runsc/cmd/gofer.go @@ -290,11 +290,17 @@ func setupRootFS(spec *specs.Spec, conf *config.Config) error { if err := os.Mkdir("/proc/root", 0755); err != nil { Fatalf("error creating /proc/root: %v", err) } + if err := os.Mkdir("/proc/etc", 0755); err != nil { + Fatalf("error creating /proc/etc: %v", err) + } // This cannot use SafeMount because there's no available procfs. But we // know that /proc is an empty tmpfs mount, so this is safe. if err := unix.Mount("runsc-proc", "/proc/proc", "proc", flags|unix.MS_RDONLY, ""); err != nil { Fatalf("error mounting proc: %v", err) } + if err := copyFile("/proc/etc/localtime", "/etc/localtime"); err != nil { + log.Warningf("Failed to copy /etc/localtime: %v. UTC timezone will be used.", err) + } root = "/proc/root" procPath = "/proc/proc" } |