Browse code

Fix regressions in attach

* Wrong bool parsing
* Attach always all streams

Were introduced in #12120

Signed-off-by: Alexander Morozov <lk4d4@docker.com>

Alexander Morozov authored on 2015/04/10 01:58:44
Showing 2 changed files
... ...
@@ -1011,10 +1011,23 @@ func postContainersAttach(eng *engine.Engine, version version.Version, w http.Re
1011 1011
 	} else {
1012 1012
 		errStream = outStream
1013 1013
 	}
1014
-	logs := r.Form.Get("logs") != ""
1015
-	stream := r.Form.Get("stream") != ""
1014
+	logs := toBool(r.Form.Get("logs"))
1015
+	stream := toBool(r.Form.Get("stream"))
1016 1016
 
1017
-	if err := cont.AttachWithLogs(inStream, outStream, errStream, logs, stream); err != nil {
1017
+	var stdin io.ReadCloser
1018
+	var stdout, stderr io.Writer
1019
+
1020
+	if toBool(r.Form.Get("stdin")) {
1021
+		stdin = inStream
1022
+	}
1023
+	if toBool(r.Form.Get("stdout")) {
1024
+		stdout = outStream
1025
+	}
1026
+	if toBool(r.Form.Get("stderr")) {
1027
+		stderr = errStream
1028
+	}
1029
+
1030
+	if err := cont.AttachWithLogs(stdin, stdout, stderr, logs, stream); err != nil {
1018 1031
 		fmt.Fprintf(outStream, "Error attaching: %s\n", err)
1019 1032
 	}
1020 1033
 	return nil
... ...
@@ -61,13 +61,15 @@ func (c *Container) AttachWithLogs(stdin io.ReadCloser, stdout, stderr io.Writer
61 61
 	//stream
62 62
 	if stream {
63 63
 		var stdinPipe io.ReadCloser
64
-		r, w := io.Pipe()
65
-		go func() {
66
-			defer w.Close()
67
-			defer logrus.Debugf("Closing buffered stdin pipe")
68
-			io.Copy(w, stdin)
69
-		}()
70
-		stdinPipe = r
64
+		if stdin != nil {
65
+			r, w := io.Pipe()
66
+			go func() {
67
+				defer w.Close()
68
+				defer logrus.Debugf("Closing buffered stdin pipe")
69
+				io.Copy(w, stdin)
70
+			}()
71
+			stdinPipe = r
72
+		}
71 73
 		<-c.Attach(stdinPipe, stdout, stderr)
72 74
 		// If we are in stdinonce mode, wait for the process to end
73 75
 		// otherwise, simply return