summaryrefslogtreecommitdiff
path: root/cmd/podman/start.go
diff options
context:
space:
mode:
authorMarco Vedovati <mvedovati@suse.com>2018-06-28 19:08:49 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-06 16:02:46 +0000
commit9eef9eb212cf4c3ec137de9db7eb8b67a8f6c351 (patch)
treed028cdc8f75dbc7f0ffc741f412d3a47979a8645 /cmd/podman/start.go
parentcf2be66f526fcd1ab9f7a1a3f9af6582070ef791 (diff)
downloadpodman-9eef9eb212cf4c3ec137de9db7eb8b67a8f6c351.tar.gz
podman-9eef9eb212cf4c3ec137de9db7eb8b67a8f6c351.tar.bz2
podman-9eef9eb212cf4c3ec137de9db7eb8b67a8f6c351.zip
Refactor podman/utils with a single container start and attach function
Use a single function startAttachCtr() to handle both container start with attach and attach to running containers, as the code handling the attach is common for the 2 use cases. Signed-off-by: Marco Vedovati <mvedovati@suse.com> Closes: #1025 Approved by: rhatdan
Diffstat (limited to 'cmd/podman/start.go')
-rw-r--r--cmd/podman/start.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/cmd/podman/start.go b/cmd/podman/start.go
index 00528d04e..e917d9198 100644
--- a/cmd/podman/start.go
+++ b/cmd/podman/start.go
@@ -96,16 +96,21 @@ func startCmd(c *cli.Context) error {
return errors.Wrapf(err, "unable to get container state")
}
+ ctrRunning := ctrState == libpod.ContainerStateRunning
+
if attach {
inputStream := os.Stdin
if !c.Bool("interactive") {
inputStream = nil
}
- if ctrState == libpod.ContainerStateRunning {
- return attachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys"), c.BoolT("sig-proxy"))
+
+ // attach to the container and also start it not already running
+ err = startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys"), c.Bool("sig-proxy"), !ctrRunning)
+ if ctrRunning {
+ return err
}
- if err := startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys"), c.Bool("sig-proxy")); err != nil {
+ if err != nil {
return errors.Wrapf(err, "unable to start container %s", ctr.ID())
}
@@ -117,7 +122,7 @@ func startCmd(c *cli.Context) error {
return ctr.Cleanup()
}
- if ctrState == libpod.ContainerStateRunning {
+ if ctrRunning {
fmt.Println(ctr.ID())
continue
}