1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fixing bug in AttachStreams that would fail to close StdIn

During a docker exec, if no TTY is specified, the code would still leave stdin open instead of closing it. This change adds handling for the execConfig TTY bool that mirrors what is already done for container config. (Updated this change to be Windows only.)

Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>
This commit is contained in:
Stefan J. Wernli 2016-06-16 17:34:00 -07:00
parent 7ef9aec90f
commit 176345435b

View file

@ -8,6 +8,7 @@ import (
"strconv" "strconv"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/daemon/exec"
"github.com/docker/docker/libcontainerd" "github.com/docker/docker/libcontainerd"
"github.com/docker/docker/runconfig" "github.com/docker/docker/runconfig"
) )
@ -103,10 +104,15 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
// AttachStreams is called by libcontainerd to connect the stdio. // AttachStreams is called by libcontainerd to connect the stdio.
func (daemon *Daemon) AttachStreams(id string, iop libcontainerd.IOPipe) error { func (daemon *Daemon) AttachStreams(id string, iop libcontainerd.IOPipe) error {
var s *runconfig.StreamConfig var (
s *runconfig.StreamConfig
ec *exec.Config
)
c := daemon.containers.Get(id) c := daemon.containers.Get(id)
if c == nil { if c == nil {
ec, err := daemon.getExecConfig(id) var err error
ec, err = daemon.getExecConfig(id)
if err != nil { if err != nil {
return fmt.Errorf("no such exec/container: %s", id) return fmt.Errorf("no such exec/container: %s", id)
} }
@ -127,7 +133,10 @@ func (daemon *Daemon) AttachStreams(id string, iop libcontainerd.IOPipe) error {
}() }()
} }
} else { } else {
if c != nil && !c.Config.Tty { //TODO(swernli): On Windows, not closing stdin when no tty is requested by the exec Config
// results in a hang. We should re-evaluate generalizing this fix for all OSes if
// we can determine that is the right thing to do more generally.
if (c != nil && !c.Config.Tty) || (ec != nil && !ec.Tty && runtime.GOOS == "windows") {
// tty is enabled, so dont close containerd's iopipe stdin. // tty is enabled, so dont close containerd's iopipe stdin.
if iop.Stdin != nil { if iop.Stdin != nil {
iop.Stdin.Close() iop.Stdin.Close()