summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-04-11 14:44:11 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-13 18:43:44 +0000
commit6609d555f75568bb4f1394736a3e3b31e5f0d355 (patch)
tree92cfca059a58882d205acd2c575b587850ae1798 /cmd
parent5e03cec7ec83f8ff8b31a89a6180dda203b04d9c (diff)
downloadpodman-6609d555f75568bb4f1394736a3e3b31e5f0d355.tar.gz
podman-6609d555f75568bb4f1394736a3e3b31e5f0d355.tar.bz2
podman-6609d555f75568bb4f1394736a3e3b31e5f0d355.zip
Fix terminal attach
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #608 Approved by: baude
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/attach.go6
-rw-r--r--cmd/podman/run.go13
-rw-r--r--cmd/podman/start.go13
-rw-r--r--cmd/podman/utils.go28
4 files changed, 27 insertions, 33 deletions
diff --git a/cmd/podman/attach.go b/cmd/podman/attach.go
index 4b16d013c..041cc0388 100644
--- a/cmd/podman/attach.go
+++ b/cmd/podman/attach.go
@@ -69,16 +69,12 @@ func attachCmd(c *cli.Context) error {
return errors.Errorf("you can only attach to running containers")
}
- if c.BoolT("sig-proxy") {
- ProxySignals(ctr)
- }
-
inputStream := os.Stdin
if c.Bool("no-stdin") {
inputStream = nil
}
- if err := attachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys")); err != nil {
+ if err := attachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys"), c.BoolT("sig-proxy")); err != nil {
return errors.Wrapf(err, "error attaching to container %s", ctr.ID())
}
diff --git a/cmd/podman/run.go b/cmd/podman/run.go
index b8d6e0968..cafb16d9d 100644
--- a/cmd/podman/run.go
+++ b/cmd/podman/run.go
@@ -179,8 +179,7 @@ func runCmd(c *cli.Context) error {
}
}
- attachChan, err := startAttachCtr(ctr, outputStream, errorStream, inputStream, c.String("detach-keys"))
- if err != nil {
+ if err := startAttachCtr(ctr, outputStream, errorStream, inputStream, c.String("detach-keys"), c.BoolT("sig-proxy")); err != nil {
// This means the command did not exist
exitCode = 127
if strings.Index(err.Error(), "permission denied") > -1 {
@@ -189,16 +188,6 @@ func runCmd(c *cli.Context) error {
return err
}
- if c.BoolT("sig-proxy") {
- ProxySignals(ctr)
- }
-
- // Wait for attach to complete
- err = <-attachChan
- if err != nil {
- return errors.Wrapf(err, "error attaching to container %s", ctr.ID())
- }
-
if ecode, err := ctr.ExitCode(); err != nil {
logrus.Errorf("unable to get exit code of container %s: %q", ctr.ID(), err)
} else {
diff --git a/cmd/podman/start.go b/cmd/podman/start.go
index 14b03ac7c..597ed29ae 100644
--- a/cmd/podman/start.go
+++ b/cmd/podman/start.go
@@ -110,21 +110,10 @@ func startCmd(c *cli.Context) error {
inputStream = nil
}
- attachChan, err := startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys"))
- if err != nil {
+ if err := startAttachCtr(ctr, os.Stdout, os.Stderr, inputStream, c.String("detach-keys"), c.Bool("sig-proxy")); err != nil {
return errors.Wrapf(err, "unable to start container %s", ctr.ID())
}
- if c.Bool("sig-proxy") {
- ProxySignals(ctr)
- }
-
- // Wait for attach to complete
- err = <-attachChan
- if err != nil {
- return errors.Wrapf(err, "error attaching to container %s", ctr.ID())
- }
-
if ecode, err := ctr.ExitCode(); err != nil {
logrus.Errorf("unable to get exit code of container %s: %q", ctr.ID(), err)
} else {
diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go
index 502424403..0238fc9c2 100644
--- a/cmd/podman/utils.go
+++ b/cmd/podman/utils.go
@@ -65,8 +65,9 @@ func getRuntime(c *cli.Context) (*libpod.Runtime, error) {
}
// Attach to a container
-func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string) error {
+func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool) error {
resize := make(chan remotecommand.TerminalSize)
+ defer close(resize)
haveTerminal := terminal.IsTerminal(int(os.Stdin.Fd()))
@@ -87,12 +88,17 @@ func attachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys
defer term.RestoreTerminal(os.Stdin.Fd(), oldTermState)
}
+ if sigProxy {
+ ProxySignals(ctr)
+ }
+
return ctr.Attach(stdout, stderr, stdin, detachKeys, resize)
}
// Start and attach to a container
-func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string) (<-chan error, error) {
+func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detachKeys string, sigProxy bool) error {
resize := make(chan remotecommand.TerminalSize)
+ defer close(resize)
haveTerminal := terminal.IsTerminal(int(os.Stdin.Fd()))
@@ -105,7 +111,7 @@ func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detac
oldTermState, err := term.SaveState(os.Stdin.Fd())
if err != nil {
- return nil, errors.Wrapf(err, "unable to save terminal state")
+ return errors.Wrapf(err, "unable to save terminal state")
}
term.SetRawTerminal(os.Stdin.Fd())
@@ -113,7 +119,21 @@ func startAttachCtr(ctr *libpod.Container, stdout, stderr, stdin *os.File, detac
defer term.RestoreTerminal(os.Stdin.Fd(), oldTermState)
}
- return ctr.StartAndAttach(stdout, stderr, stdin, detachKeys, resize)
+ attachChan, err := ctr.StartAndAttach(stdout, stderr, stdin, detachKeys, resize)
+ if err != nil {
+ return err
+ }
+
+ if sigProxy {
+ ProxySignals(ctr)
+ }
+
+ err = <-attachChan
+ if err != nil {
+ return errors.Wrapf(err, "error attaching to container %s", ctr.ID())
+ }
+
+ return nil
}
// Helper for prepareAttach - set up a goroutine to generate terminal resize events