Skip to content

Commit

Permalink
Merge pull request moby#20647 from coolljt0725/fix_20638
Browse files Browse the repository at this point in the history
Fix exec start api with detach and AttachStdin at same time. fixes #2
  • Loading branch information
calavera committed Feb 25, 2016
2 parents 0f01b21 + fb0ac1a commit cee4ff1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion daemon/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (d *Daemon) ContainerExecStart(name string, stdin io.ReadCloser, stdout io.
logrus.Debugf("starting exec command %s in container %s", ec.ID, c.ID)
d.LogContainerEvent(c, "exec_start: "+ec.ProcessConfig.Entrypoint+" "+strings.Join(ec.ProcessConfig.Arguments, " "))

if ec.OpenStdin {
if ec.OpenStdin && stdin != nil {
r, w := io.Pipe()
go func() {
defer w.Close()
Expand Down
30 changes: 30 additions & 0 deletions integration-cli/docker_api_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,36 @@ func (s *DockerSuite) TestExecApiStartMultipleTimesError(c *check.C) {
startExec(c, execID, http.StatusConflict)
}

// #20638
func (s *DockerSuite) TestExecApiStartWithDetach(c *check.C) {
name := "foo"
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "top")
data := map[string]interface{}{
"cmd": []string{"true"},
"AttachStdin": true,
}
_, b, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), data)
c.Assert(err, checker.IsNil, check.Commentf(string(b)))

createResp := struct {
ID string `json:"Id"`
}{}
c.Assert(json.Unmarshal(b, &createResp), checker.IsNil, check.Commentf(string(b)))

_, body, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", createResp.ID), strings.NewReader(`{"Detach": true}`), "application/json")
c.Assert(err, checker.IsNil)

b, err = readBody(body)
comment := check.Commentf("response body: %s", b)
c.Assert(err, checker.IsNil, comment)

resp, _, err := sockRequestRaw("GET", "/_ping", nil, "")
c.Assert(err, checker.IsNil)
if resp.StatusCode != http.StatusOK {
c.Fatal("daemon is down, it should alive")
}
}

func createExec(c *check.C, name string) string {
_, b, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}})
c.Assert(err, checker.IsNil, check.Commentf(string(b)))
Expand Down

0 comments on commit cee4ff1

Please sign in to comment.