Переглянути джерело

Merge pull request #12240 from LK4D4/fix_attach

Fix regressions in attach
Brian Goff 10 роки тому
батько
коміт
2052d01b1e
2 змінених файлів з 25 додано та 10 видалено
  1. 16 3
      api/server/server.go
  2. 9 7
      daemon/attach.go

+ 16 - 3
api/server/server.go

@@ -1011,10 +1011,23 @@ func postContainersAttach(eng *engine.Engine, version version.Version, w http.Re
 	} else {
 	} else {
 		errStream = outStream
 		errStream = outStream
 	}
 	}
-	logs := r.Form.Get("logs") != ""
-	stream := r.Form.Get("stream") != ""
+	logs := toBool(r.Form.Get("logs"))
+	stream := toBool(r.Form.Get("stream"))
 
 
-	if err := cont.AttachWithLogs(inStream, outStream, errStream, logs, stream); err != nil {
+	var stdin io.ReadCloser
+	var stdout, stderr io.Writer
+
+	if toBool(r.Form.Get("stdin")) {
+		stdin = inStream
+	}
+	if toBool(r.Form.Get("stdout")) {
+		stdout = outStream
+	}
+	if toBool(r.Form.Get("stderr")) {
+		stderr = errStream
+	}
+
+	if err := cont.AttachWithLogs(stdin, stdout, stderr, logs, stream); err != nil {
 		fmt.Fprintf(outStream, "Error attaching: %s\n", err)
 		fmt.Fprintf(outStream, "Error attaching: %s\n", err)
 	}
 	}
 	return nil
 	return nil

+ 9 - 7
daemon/attach.go

@@ -61,13 +61,15 @@ func (c *Container) AttachWithLogs(stdin io.ReadCloser, stdout, stderr io.Writer
 	//stream
 	//stream
 	if stream {
 	if stream {
 		var stdinPipe io.ReadCloser
 		var stdinPipe io.ReadCloser
-		r, w := io.Pipe()
-		go func() {
-			defer w.Close()
-			defer logrus.Debugf("Closing buffered stdin pipe")
-			io.Copy(w, stdin)
-		}()
-		stdinPipe = r
+		if stdin != nil {
+			r, w := io.Pipe()
+			go func() {
+				defer w.Close()
+				defer logrus.Debugf("Closing buffered stdin pipe")
+				io.Copy(w, stdin)
+			}()
+			stdinPipe = r
+		}
 		<-c.Attach(stdinPipe, stdout, stderr)
 		<-c.Attach(stdinPipe, stdout, stderr)
 		// If we are in stdinonce mode, wait for the process to end
 		// If we are in stdinonce mode, wait for the process to end
 		// otherwise, simply return
 		// otherwise, simply return