aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-10-27 12:16:28 +0100
committerGitHub <noreply@github.com>2020-10-27 12:16:28 +0100
commit5c0849534d7bed20ec588d8ec0099a8b60df7e25 (patch)
tree1e8e2a60c1fa0f0c3f7a4743ddb0268e5d53c963 /cmd/podman
parentdbbd5987fde0547305bc42a27d355d2de9e08dd3 (diff)
parent32af1be01a37362d81baff47a2bb28e4c863a8c9 (diff)
downloadpodman-5c0849534d7bed20ec588d8ec0099a8b60df7e25.tar.gz
podman-5c0849534d7bed20ec588d8ec0099a8b60df7e25.tar.bz2
podman-5c0849534d7bed20ec588d8ec0099a8b60df7e25.zip
Merge pull request #8094 from rhatdan/cidfile
The cidfile should be created when the container is created
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/create.go32
-rw-r--r--cmd/podman/containers/run.go15
2 files changed, 4 insertions, 43 deletions
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
index e3e1038f4..b7b2a364f 100644
--- a/cmd/podman/containers/create.go
+++ b/cmd/podman/containers/create.go
@@ -15,11 +15,9 @@ import (
"github.com/containers/podman/v2/cmd/podman/utils"
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/domain/entities"
- "github.com/containers/podman/v2/pkg/errorhandling"
"github.com/containers/podman/v2/pkg/specgen"
"github.com/containers/podman/v2/pkg/util"
"github.com/pkg/errors"
- "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
@@ -94,15 +92,6 @@ 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 err := createInit(cmd); err != nil {
return err
@@ -139,10 +128,9 @@ func create(cmd *cobra.Command, args []string) error {
return err
}
- if cidFile != nil {
- _, err = cidFile.WriteString(report.Id)
- if err != nil {
- logrus.Error(err)
+ if cliVals.CIDFile != "" {
+ if err := util.CreateCidFile(cliVals.CIDFile, report.Id); err != nil {
+ return err
}
}
@@ -269,20 +257,6 @@ func pullImage(imageName string) (string, error) {
return imageName, 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
-}
-
// createPodIfNecessary automatically creates a pod when requested. if the pod name
// has the form new:ID, the pod ID is created and the name in the spec generator is replaced
// with ID.
diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go
index 6b294d69a..6cadbc7ec 100644
--- a/cmd/podman/containers/run.go
+++ b/cmd/podman/containers/run.go
@@ -111,15 +111,8 @@ 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.CIDFile = cliVals.CIDFile
runOpts.Rm = cliVals.Rm
if err := createInit(cmd); err != nil {
return err
@@ -193,12 +186,6 @@ 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 runOpts.Detach {
fmt.Println(report.Id)