mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Bugfix: only use io.Copy in hijack if attaching both stdout and stderr
Add regression tests to ensure issue is fixed. Docker-DCO-1.1-Signed-off-by: Matt Heon <mheon@redhat.com> (github: mheon)
This commit is contained in:
parent
3b3f0fa085
commit
1476f295ac
2 changed files with 49 additions and 1 deletions
|
@ -88,7 +88,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
|
|||
}()
|
||||
|
||||
// When TTY is ON, use regular copy
|
||||
if setRawTerminal {
|
||||
if setRawTerminal && stdout != nil {
|
||||
_, err = io.Copy(stdout, br)
|
||||
} else {
|
||||
_, err = utils.StdCopy(stdout, stderr, br)
|
||||
|
|
|
@ -1218,3 +1218,51 @@ func TestDnsOptionsBasedOnHostResolvConf(t *testing.T) {
|
|||
|
||||
logDone("run - dns options based on host resolv.conf")
|
||||
}
|
||||
|
||||
// Regression test for #6983
|
||||
func TestAttachStdErrOnlyTTYMode(t *testing.T) {
|
||||
cmd := exec.Command(dockerBinary, "run", "-t", "-a", "stderr", "busybox", "true")
|
||||
|
||||
exitCode, err := runCommand(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if exitCode != 0 {
|
||||
t.Fatalf("Container should have exited with error code 0")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("run - Attach stderr only with -t")
|
||||
}
|
||||
|
||||
// Regression test for #6983
|
||||
func TestAttachStdOutOnlyTTYMode(t *testing.T) {
|
||||
cmd := exec.Command(dockerBinary, "run", "-t", "-a", "stdout", "busybox", "true")
|
||||
|
||||
exitCode, err := runCommand(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if exitCode != 0 {
|
||||
t.Fatalf("Container should have exited with error code 0")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("run - Attach stdout only with -t")
|
||||
}
|
||||
|
||||
// Regression test for #6983
|
||||
func TestAttachStdOutAndErrTTYMode(t *testing.T) {
|
||||
cmd := exec.Command(dockerBinary, "run", "-t", "-a", "stdout", "-a", "stderr", "busybox", "true")
|
||||
|
||||
exitCode, err := runCommand(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if exitCode != 0 {
|
||||
t.Fatalf("Container should have exited with error code 0")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("run - Attach stderr and stdout with -t")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue