summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2017-11-15 17:58:26 -0500
committerGitHub <noreply@github.com>2017-11-15 17:58:26 -0500
commitbf8b9a37df2aeead009996875f58c59625110472 (patch)
tree73d21edb601163fa907049a10c152917cc766a57 /cmd
parentafe1a2e7f1a54946d86588398c37c6d52c4e125c (diff)
parentacd9c668647d273488772bfcb06a0f1a44dfb411 (diff)
downloadpodman-bf8b9a37df2aeead009996875f58c59625110472.tar.gz
podman-bf8b9a37df2aeead009996875f58c59625110472.tar.bz2
podman-bf8b9a37df2aeead009996875f58c59625110472.zip
Merge pull request #47 from baude/terminal_attach
Fix terminal attach
Diffstat (limited to 'cmd')
-rw-r--r--cmd/kpod/create.go10
-rw-r--r--cmd/kpod/run.go35
2 files changed, 36 insertions, 9 deletions
diff --git a/cmd/kpod/create.go b/cmd/kpod/create.go
index bbfeaebae..0a0e31c40 100644
--- a/cmd/kpod/create.go
+++ b/cmd/kpod/create.go
@@ -319,6 +319,14 @@ func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime) (*createConfig, er
blkioWeight = uint16(u)
}
+ // Because we cannot do a non-terminal attach, we need to set tty to true
+ // if detach is not false
+ // TODO Allow non-terminal attach
+ tty := c.Bool("tty")
+ if !c.Bool("detach") && !tty {
+ tty = true
+ }
+
config := &createConfig{
capAdd: c.StringSlice("cap-add"),
capDrop: c.StringSlice("cap-drop"),
@@ -387,7 +395,7 @@ func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime) (*createConfig, er
storageOpts: c.StringSlice("storage-opt"),
sysctl: sysctl,
tmpfs: c.StringSlice("tmpfs"),
- tty: c.Bool("tty"),
+ tty: tty,
user: uid,
group: gid,
volumes: c.StringSlice("volume"),
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
}