summaryrefslogtreecommitdiff
path: root/cmd/kpod/run.go
diff options
context:
space:
mode:
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
}