aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-04-22 17:02:16 +0200
committerGitHub <noreply@github.com>2020-04-22 17:02:16 +0200
commit7f1d00108e441b012785fa9d6e75317bad7ce239 (patch)
treefedf22549750a7b7d1fc6a178712df6c5f7767ce
parent0d57ea420e88bb5c0f1201fc389825df2c6fa0af (diff)
parent94b62dac7497ae50fc4149f404b317de542c30a1 (diff)
downloadpodman-7f1d00108e441b012785fa9d6e75317bad7ce239.tar.gz
podman-7f1d00108e441b012785fa9d6e75317bad7ce239.tar.bz2
podman-7f1d00108e441b012785fa9d6e75317bad7ce239.zip
Merge pull request #5938 from rhatdan/v2
Fix handling of --cidfile on create/run
-rw-r--r--cmd/podman/containers/create.go35
-rw-r--r--cmd/podman/containers/run.go17
-rw-r--r--test/e2e/stop_test.go1
3 files changed, 52 insertions, 1 deletions
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
index 0c96f1a5c..8c0e40122 100644
--- a/cmd/podman/containers/create.go
+++ b/cmd/podman/containers/create.go
@@ -2,12 +2,15 @@ package containers
import (
"fmt"
+ "os"
"github.com/containers/common/pkg/config"
"github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/pkg/domain/entities"
+ "github.com/containers/libpod/pkg/errorhandling"
"github.com/containers/libpod/pkg/specgen"
+ "github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -79,6 +82,16 @@ func create(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
+ cidFile, err := openCidFile(cliVals.CIDFile)
+ if err != nil {
+ return err
+ }
+
+ if cidFile != nil {
+ defer errorhandling.CloseQuiet(cidFile)
+ defer errorhandling.SyncQuiet(cidFile)
+ }
+
if rfs := cliVals.RootFS; !rfs {
rawImageInput = args[0]
}
@@ -101,6 +114,14 @@ func create(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
+
+ if cidFile != nil {
+ _, err = cidFile.WriteString(report.Id)
+ if err != nil {
+ logrus.Error(err)
+ }
+ }
+
fmt.Println(report.Id)
return nil
}
@@ -154,3 +175,17 @@ func pullImage(imageName string) error {
}
return nil
}
+
+func openCidFile(cidfile string) (*os.File, error) {
+ if cidfile == "" {
+ return nil, nil
+ }
+ cidFile, err := util.OpenExclusiveFile(cidfile)
+ if err != nil && os.IsExist(err) {
+ return nil, errors.Errorf("container id file exists. Ensure another container is not using it or delete %s", cidfile)
+ }
+ if err != nil {
+ return nil, errors.Errorf("error opening cidfile %s", cidfile)
+ }
+ return cidFile, nil
+}
diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go
index 06b89b0fc..409b72198 100644
--- a/cmd/podman/containers/run.go
+++ b/cmd/podman/containers/run.go
@@ -9,6 +9,7 @@ import (
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/domain/entities"
+ "github.com/containers/libpod/pkg/errorhandling"
"github.com/containers/libpod/pkg/specgen"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -89,6 +90,15 @@ func run(cmd *cobra.Command, args []string) error {
return errors.Wrapf(err, "error checking authfile path %s", af)
}
}
+ cidFile, err := openCidFile(cliVals.CIDFile)
+ if err != nil {
+ return err
+ }
+
+ if cidFile != nil {
+ defer errorhandling.CloseQuiet(cidFile)
+ defer errorhandling.SyncQuiet(cidFile)
+ }
runOpts.Rm = cliVals.Rm
if err := createInit(cmd); err != nil {
return err
@@ -140,6 +150,13 @@ func run(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
+ if cidFile != nil {
+ _, err = cidFile.WriteString(report.Id)
+ if err != nil {
+ logrus.Error(err)
+ }
+ }
+
if cliVals.Detach {
fmt.Println(report.Id)
return nil
diff --git a/test/e2e/stop_test.go b/test/e2e/stop_test.go
index a0c573c55..54c64d66b 100644
--- a/test/e2e/stop_test.go
+++ b/test/e2e/stop_test.go
@@ -18,7 +18,6 @@ var _ = Describe("Podman stop", func() {
)
BeforeEach(func() {
- Skip(v2fail)
tempdir, err = CreateTempDirInTempDir()
if err != nil {
os.Exit(1)