aboutsummaryrefslogtreecommitdiff
path: root/libpod/container_internal_linux.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-07-06 13:28:20 -0400
committerGitHub <noreply@github.com>2020-07-06 13:28:20 -0400
commit9532509c50113ac9470108e3492e2769bac533e8 (patch)
tree4d691205d2c574b6c7ab6eb3c62937b327898f58 /libpod/container_internal_linux.go
parent9eac75a967e3459b32b1acd220afb49b60f5e5aa (diff)
parent9a1543caec75a7b02dd2ec9a1111756bb1716454 (diff)
downloadpodman-9532509c50113ac9470108e3492e2769bac533e8.tar.gz
podman-9532509c50113ac9470108e3492e2769bac533e8.tar.bz2
podman-9532509c50113ac9470108e3492e2769bac533e8.zip
Merge pull request #6836 from ashley-cui/tzlibpod
Add --tz flag to create, run
Diffstat (limited to 'libpod/container_internal_linux.go')
-rw-r--r--libpod/container_internal_linux.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index c58350d18..8bf6092c3 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -1241,6 +1241,31 @@ func (c *Container) makeBindMounts() error {
c.state.BindMounts["/etc/hostname"] = hostnamePath
}
+ // Make /etc/localtime
+ if c.Timezone() != "" {
+ if _, ok := c.state.BindMounts["/etc/localtime"]; !ok {
+ var zonePath string
+ if c.Timezone() == "local" {
+ zonePath, err = filepath.EvalSymlinks("/etc/localtime")
+ if err != nil {
+ return errors.Wrapf(err, "error finding local timezone for container %s", c.ID())
+ }
+ } else {
+ zone := filepath.Join("/usr/share/zoneinfo", c.Timezone())
+ zonePath, err = filepath.EvalSymlinks(zone)
+ if err != nil {
+ return errors.Wrapf(err, "error setting timezone for container %s", c.ID())
+ }
+ }
+ localtimePath, err := c.copyTimezoneFile(zonePath)
+ if err != nil {
+ return errors.Wrapf(err, "error setting timezone for container %s", c.ID())
+ }
+ c.state.BindMounts["/etc/localtime"] = localtimePath
+
+ }
+ }
+
// Make .containerenv
// Empty file, so no need to recreate if it exists
if _, ok := c.state.BindMounts["/run/.containerenv"]; !ok {
@@ -1533,3 +1558,35 @@ func (c *Container) getOCICgroupPath() (string, error) {
return "", errors.Wrapf(define.ErrInvalidArg, "invalid cgroup manager %s requested", c.runtime.config.Engine.CgroupManager)
}
}
+
+func (c *Container) copyTimezoneFile(zonePath string) (string, error) {
+ var localtimeCopy string = filepath.Join(c.state.RunDir, "localtime")
+ file, err := os.Stat(zonePath)
+ if err != nil {
+ return "", err
+ }
+ if file.IsDir() {
+ return "", errors.New("Invalid timezone: is a directory")
+ }
+ src, err := os.Open(zonePath)
+ if err != nil {
+ return "", err
+ }
+ defer src.Close()
+ dest, err := os.Create(localtimeCopy)
+ if err != nil {
+ return "", err
+ }
+ defer dest.Close()
+ _, err = io.Copy(dest, src)
+ if err != nil {
+ return "", err
+ }
+ if err := label.Relabel(localtimeCopy, c.config.MountLabel, false); err != nil {
+ return "", err
+ }
+ if err := dest.Chown(c.RootUID(), c.RootGID()); err != nil {
+ return "", err
+ }
+ return localtimeCopy, err
+}