Skip to content

Commit

Permalink
Bugfix: only use io.Copy in hijack if attaching both stdout and stderr
Browse files Browse the repository at this point in the history
Add regression tests to ensure issue is fixed.

Docker-DCO-1.1-Signed-off-by: Matt Heon <mheon@redhat.com> (github: mheon)
  • Loading branch information
mheon committed Jul 17, 2014
1 parent 3b3f0fa commit 1476f29
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/client/hijack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 48 additions & 0 deletions integration-cli/docker_cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 1476f29

Please sign in to comment.