diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2018-10-23 14:45:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-23 14:45:33 -0700 |
commit | 37e9e5667e2ed6b790d5d8271509ef93d2935083 (patch) | |
tree | a4d1d7bad134c2fa77a30ea2ee019f460a4745b2 /cmd/podman/pod_create.go | |
parent | 28279ce6bda0e5a5acd06b98f7d8f52c8fc8a393 (diff) | |
parent | dfc689efc9a5746b0c31147562c5051c45874002 (diff) | |
download | podman-37e9e5667e2ed6b790d5d8271509ef93d2935083.tar.gz podman-37e9e5667e2ed6b790d5d8271509ef93d2935083.tar.bz2 podman-37e9e5667e2ed6b790d5d8271509ef93d2935083.zip |
Merge pull request #1706 from giuseppe/fix-cidfile-rootless
create: fix writing cidfile when using rootless
Diffstat (limited to 'cmd/podman/pod_create.go')
-rw-r--r-- | cmd/podman/pod_create.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/cmd/podman/pod_create.go b/cmd/podman/pod_create.go index c3a45a093..63fa6b294 100644 --- a/cmd/podman/pod_create.go +++ b/cmd/podman/pod_create.go @@ -90,13 +90,17 @@ func podCreateCmd(c *cli.Context) error { } defer runtime.Shutdown(false) - if c.IsSet("pod-id-file") { - if _, err = os.Stat(c.String("pod-id-file")); err == nil { - return errors.Errorf("pod id file exists. ensure another pod is not using it or delete %s", c.String("pod-id-file")) + var podIdFile *os.File + if c.IsSet("pod-id-file") && os.Geteuid() == 0 { + podIdFile, err = libpod.OpenExclusiveFile(c.String("pod-id-file")) + if err != nil && os.IsExist(err) { + return errors.Errorf("pod id file exists. Ensure another pod is not using it or delete %s", c.String("pod-id-file")) } - if err = libpod.WriteFile("", c.String("pod-id-file")); err != nil { - return errors.Wrapf(err, "unable to write pod id file %s", c.String("pod-id-file")) + if err != nil { + return errors.Errorf("error opening pod-id-file %s", c.String("pod-id-file")) } + defer podIdFile.Close() + defer podIdFile.Sync() } if !c.BoolT("infra") && c.IsSet("share") && c.String("share") != "none" && c.String("share") != "" { return errors.Errorf("You cannot share kernel namespaces on the pod level without an infra container") @@ -137,8 +141,8 @@ func podCreateCmd(c *cli.Context) error { return err } - if c.IsSet("pod-id-file") { - err = libpod.WriteFile(pod.ID(), c.String("pod-id-file")) + if podIdFile != nil { + _, err = podIdFile.WriteString(pod.ID()) if err != nil { logrus.Error(err) } |