summaryrefslogtreecommitdiff
path: root/cmd/kpod/run.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2017-11-08 15:14:33 -0600
committerbaude <bbaude@redhat.com>2017-11-15 16:27:57 -0600
commitacd9c668647d273488772bfcb06a0f1a44dfb411 (patch)
tree5ff634e00c700b16f1ae4369df4ea021a4888073 /cmd/kpod/run.go
parent5cfd7a313fcae7c748b5bae84de779b28d4ea01b (diff)
downloadpodman-acd9c668647d273488772bfcb06a0f1a44dfb411.tar.gz
podman-acd9c668647d273488772bfcb06a0f1a44dfb411.tar.bz2
podman-acd9c668647d273488772bfcb06a0f1a44dfb411.zip
Fix terminal attach
Re-order the startup of a new container via run from initialize > start > attach to initialize > attach > start. This fixes output when running: kpod run -i -t IMAGE command and kpod run IMAGE command Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/kpod/run.go')
-rw-r--r--cmd/kpod/run.go35
1 files changed, 27 insertions, 8 deletions
diff --git a/cmd/kpod/run.go b/cmd/kpod/run.go
index 84da12e6a..87ff2d035 100644
--- a/cmd/kpod/run.go
+++ b/cmd/kpod/run.go
@@ -2,6 +2,7 @@ package main
import (
"fmt"
+ "sync"
"github.com/pkg/errors"
"github.com/projectatomic/libpod/libpod"
@@ -91,20 +92,38 @@ func runCmd(c *cli.Context) error {
libpod.WriteFile(ctr.ID(), c.String("cidfile"))
return nil
}
+
+ // Create a bool channel to track that the console socket attach
+ // is successful.
+ attached := make(chan bool)
+ // Create a waitgroup so we can sync and wait for all goroutines
+ // to finish before exiting main
+ var wg sync.WaitGroup
+
+ if !createConfig.detach {
+ // We increment the wg counter because we need to do the attach
+ wg.Add(1)
+ // Attach to the running container
+ go func() {
+ logrus.Debug("trying to attach to the container %s", ctr.ID())
+ defer wg.Done()
+ if err := ctr.Attach(false, c.String("detach-keys"), attached); err != nil {
+ logrus.Errorf("unable to attach to container %s: %q", ctr.ID(), err)
+ }
+ }()
+ if !<-attached {
+ return errors.Errorf("unable to attach to container %s", ctr.ID())
+ }
+ }
// Start the container
if err := ctr.Start(); err != nil {
return errors.Wrapf(err, "unable to start container %q", ctr.ID())
}
logrus.Debug("started container ", ctr.ID())
- if createConfig.tty {
- // Attach to the running container
- logrus.Debug("trying to attach to the container %s", ctr.ID())
- if err := ctr.Attach(false, c.String("detach-keys")); err != nil {
- return errors.Wrapf(err, "unable to attach to container %s", ctr.ID())
- }
- } else {
+
+ if createConfig.detach {
fmt.Printf("%s\n", ctr.ID())
}
-
+ wg.Wait()
return nil
}