summaryrefslogtreecommitdiff
path: root/libpod
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 /libpod
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 'libpod')
-rw-r--r--libpod/container.go4
-rw-r--r--libpod/container_attach.go18
2 files changed, 14 insertions, 8 deletions
diff --git a/libpod/container.go b/libpod/container.go
index 7c2f921f3..d93efda97 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -393,7 +393,7 @@ func (c *Container) Exec(cmd []string, tty bool, stdin bool) (string, error) {
// Attach attaches to a container
// Returns fully qualified URL of streaming server for the container
-func (c *Container) Attach(noStdin bool, keys string) error {
+func (c *Container) Attach(noStdin bool, keys string, attached chan<- bool) error {
// Check the validity of the provided keys first
var err error
detachKeys := []byte{}
@@ -410,7 +410,7 @@ func (c *Container) Attach(noStdin bool, keys string) error {
}
resize := make(chan remotecommand.TerminalSize)
defer close(resize)
- err = c.attachContainerSocket(resize, noStdin, detachKeys)
+ err = c.attachContainerSocket(resize, noStdin, detachKeys, attached)
if err != nil {
return err
}
diff --git a/libpod/container_attach.go b/libpod/container_attach.go
index e308df4a4..8c1c98fe5 100644
--- a/libpod/container_attach.go
+++ b/libpod/container_attach.go
@@ -2,6 +2,7 @@ package libpod
import (
"fmt"
+ "golang.org/x/crypto/ssh/terminal"
"io"
"net"
"os"
@@ -25,7 +26,7 @@ const (
)
// attachContainerSocket connects to the container's attach socket and deals with the IO
-func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSize, noStdIn bool, detachKeys []byte) error {
+func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSize, noStdIn bool, detachKeys []byte, attached chan<- bool) error {
inputStream := os.Stdin
outputStream := os.Stdout
errorStream := os.Stderr
@@ -38,12 +39,14 @@ func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSi
return errors.Errorf("no tty available for %s", c.ID())
}
- oldTermState, err := term.SaveState(inputStream.Fd())
- if err != nil {
- return errors.Wrapf(err, "unable to save terminal state")
- }
+ if terminal.IsTerminal(int(inputStream.Fd())) {
+ oldTermState, err := term.SaveState(inputStream.Fd())
+ if err != nil {
+ return errors.Wrapf(err, "unable to save terminal state")
+ }
- defer term.RestoreTerminal(inputStream.Fd(), oldTermState)
+ defer term.RestoreTerminal(inputStream.Fd(), oldTermState)
+ }
// Put both input and output into raw
if !noStdIn {
@@ -71,6 +74,9 @@ func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSi
}
defer conn.Close()
+ // signal back that the connection was made
+ attached <- true
+
receiveStdoutError := make(chan error)
if outputStream != nil || errorStream != nil {
go func() {