Browse code

fix a panic when the exec fails to start

Signed-off-by: Shijiang Wei <mountkin@gmail.com>

Shijiang Wei authored on 2015/08/21 21:39:26
Showing 3 changed files
... ...
@@ -65,7 +65,7 @@ func (s *Server) postContainerExecStart(version version.Version, w http.Response
65 65
 	}
66 66
 	var (
67 67
 		execName                  = vars["name"]
68
-		stdin                     io.ReadCloser
68
+		stdin, inStream           io.ReadCloser
69 69
 		stdout, stderr, outStream io.Writer
70 70
 	)
71 71
 
... ...
@@ -77,7 +77,7 @@ func (s *Server) postContainerExecStart(version version.Version, w http.Response
77 77
 	if !execStartCheck.Detach {
78 78
 		var err error
79 79
 		// Setting up the streaming http interface.
80
-		inStream, outStream, err := hijackServer(w)
80
+		inStream, outStream, err = hijackServer(w)
81 81
 		if err != nil {
82 82
 			return err
83 83
 		}
... ...
@@ -95,6 +95,8 @@ func (s *Server) postContainerExecStart(version version.Version, w http.Response
95 95
 			stderr = stdcopy.NewStdWriter(outStream, stdcopy.Stderr)
96 96
 			stdout = stdcopy.NewStdWriter(outStream, stdcopy.Stdout)
97 97
 		}
98
+	} else {
99
+		outStream = w
98 100
 	}
99 101
 
100 102
 	// Now run the user process in container.
... ...
@@ -595,3 +595,14 @@ func (s *DockerSuite) TestExecOnReadonlyContainer(c *check.C) {
595 595
 		c.Fatalf("exec into a read-only container failed with exit status %d", status)
596 596
 	}
597 597
 }
598
+
599
+// #15750
600
+func (s *DockerSuite) TestExecStartFails(c *check.C) {
601
+	name := "exec-15750"
602
+	dockerCmd(c, "run", "-d", "--name", name, "busybox", "top")
603
+
604
+	_, errmsg, status := dockerCmdWithStdoutStderr(nil, "exec", name, "no-such-cmd")
605
+	if status == 255 && !strings.Contains(errmsg, "executable file not found") {
606
+		c.Fatal("exec error message not received. The daemon might had crashed")
607
+	}
608
+}
... ...
@@ -602,7 +602,9 @@ func dockerCmdWithError(args ...string) (string, int, error) {
602 602
 
603 603
 func dockerCmdWithStdoutStderr(c *check.C, args ...string) (string, string, int) {
604 604
 	stdout, stderr, status, err := runCommandWithStdoutStderr(exec.Command(dockerBinary, args...))
605
-	c.Assert(err, check.IsNil, check.Commentf("%q failed with errors: %s, %v", strings.Join(args, " "), stderr, err))
605
+	if c != nil {
606
+		c.Assert(err, check.IsNil, check.Commentf("%q failed with errors: %s, %v", strings.Join(args, " "), stderr, err))
607
+	}
606 608
 	return stdout, stderr, status
607 609
 }
608 610