mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #15750 from mountkin/fix-exec-panic
fix a panic when the exec fails to start
This commit is contained in:
commit
fefc9a3a6a
3 changed files with 18 additions and 3 deletions
|
@ -65,7 +65,7 @@ func (s *Server) postContainerExecStart(version version.Version, w http.Response
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
execName = vars["name"]
|
execName = vars["name"]
|
||||||
stdin io.ReadCloser
|
stdin, inStream io.ReadCloser
|
||||||
stdout, stderr, outStream io.Writer
|
stdout, stderr, outStream io.Writer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func (s *Server) postContainerExecStart(version version.Version, w http.Response
|
||||||
if !execStartCheck.Detach {
|
if !execStartCheck.Detach {
|
||||||
var err error
|
var err error
|
||||||
// Setting up the streaming http interface.
|
// Setting up the streaming http interface.
|
||||||
inStream, outStream, err := hijackServer(w)
|
inStream, outStream, err = hijackServer(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,8 @@ func (s *Server) postContainerExecStart(version version.Version, w http.Response
|
||||||
stderr = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
|
stderr = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
|
||||||
stdout = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
|
stdout = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
outStream = w
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now run the user process in container.
|
// Now run the user process in container.
|
||||||
|
|
|
@ -595,3 +595,14 @@ func (s *DockerSuite) TestExecOnReadonlyContainer(c *check.C) {
|
||||||
c.Fatalf("exec into a read-only container failed with exit status %d", status)
|
c.Fatalf("exec into a read-only container failed with exit status %d", status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #15750
|
||||||
|
func (s *DockerSuite) TestExecStartFails(c *check.C) {
|
||||||
|
name := "exec-15750"
|
||||||
|
dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
|
||||||
|
|
||||||
|
_, errmsg, status := dockerCmdWithStdoutStderr(nil, "exec", name, "no-such-cmd")
|
||||||
|
if status == 255 && !strings.Contains(errmsg, "executable file not found") {
|
||||||
|
c.Fatal("exec error message not received. The daemon might had crashed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -602,7 +602,9 @@ func dockerCmdWithError(args ...string) (string, int, error) {
|
||||||
|
|
||||||
func dockerCmdWithStdoutStderr(c *check.C, args ...string) (string, string, int) {
|
func dockerCmdWithStdoutStderr(c *check.C, args ...string) (string, string, int) {
|
||||||
stdout, stderr, status, err := runCommandWithStdoutStderr(exec.Command(dockerBinary, args...))
|
stdout, stderr, status, err := runCommandWithStdoutStderr(exec.Command(dockerBinary, args...))
|
||||||
c.Assert(err, check.IsNil, check.Commentf("%q failed with errors: %s, %v", strings.Join(args, " "), stderr, err))
|
if c != nil {
|
||||||
|
c.Assert(err, check.IsNil, check.Commentf("%q failed with errors: %s, %v", strings.Join(args, " "), stderr, err))
|
||||||
|
}
|
||||||
return stdout, stderr, status
|
return stdout, stderr, status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue