mirror of https://github.com/docker/docs.git
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
|
@ -88,7 +88,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// When TTY is ON, use regular copy
|
// When TTY is ON, use regular copy
|
||||||
if setRawTerminal {
|
if setRawTerminal && stdout != nil {
|
||||||
_, err = io.Copy(stdout, br)
|
_, err = io.Copy(stdout, br)
|
||||||
} else {
|
} else {
|
||||||
_, err = utils.StdCopy(stdout, stderr, br)
|
_, err = utils.StdCopy(stdout, stderr, br)
|
||||||
|
|
|
@ -1218,3 +1218,51 @@ func TestDnsOptionsBasedOnHostResolvConf(t *testing.T) {
|
||||||
|
|
||||||
logDone("run - dns options based on host resolv.conf")
|
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…
Reference in New Issue