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

Add CloseWriters back and do an interface cast
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby 11 роки тому
батько
коміт
8e2284aaa2
4 змінених файлів з 11 додано та 7 видалено
  1. 2 2
      container.go
  2. 7 3
      execdriver/term.go
  3. 1 1
      utils/utils.go
  4. 1 1
      utils/utils_test.go

+ 2 - 2
container.go

@@ -829,10 +829,10 @@ func (container *Container) cleanup() {
 			utils.Errorf("%s: Error close stdin: %s", container.ID, err)
 		}
 	}
-	if err := container.stdout.Close(); err != nil {
+	if err := container.stdout.CloseWriters(); err != nil {
 		utils.Errorf("%s: Error close stdout: %s", container.ID, err)
 	}
-	if err := container.stderr.Close(); err != nil {
+	if err := container.stderr.CloseWriters(); err != nil {
 		utils.Errorf("%s: Error close stderr: %s", container.ID, err)
 	}
 	if container.command.Terminal != nil {

+ 7 - 3
execdriver/term.go

@@ -14,10 +14,10 @@ type Term interface {
 
 type Pipes struct {
 	Stdin          io.ReadCloser
-	Stdout, Stderr io.WriteCloser
+	Stdout, Stderr io.Writer
 }
 
-func NewPipes(stdin io.ReadCloser, stdout, stderr io.WriteCloser, useStdin bool) *Pipes {
+func NewPipes(stdin io.ReadCloser, stdout, stderr io.Writer, useStdin bool) *Pipes {
 	p := &Pipes{
 		Stdout: stdout,
 		Stderr: stderr,
@@ -76,7 +76,11 @@ func (t *TtyConsole) attach(command *Command, pipes *Pipes) error {
 	command.Console = t.Slave.Name()
 
 	go func() {
-		defer pipes.Stdout.Close()
+		if wb, ok := pipes.Stdout.(interface {
+			CloseWriters() error
+		}); ok {
+			defer wb.CloseWriters()
+		}
 		io.Copy(pipes.Stdout, t.Master)
 	}()
 

+ 1 - 1
utils/utils.go

@@ -388,7 +388,7 @@ func (w *WriteBroadcaster) Write(p []byte) (n int, err error) {
 	return len(p), nil
 }
 
-func (w *WriteBroadcaster) Close() error {
+func (w *WriteBroadcaster) CloseWriters() error {
 	w.Lock()
 	defer w.Unlock()
 	for sw := range w.writers {

+ 1 - 1
utils/utils_test.go

@@ -110,7 +110,7 @@ func TestWriteBroadcaster(t *testing.T) {
 		t.Errorf("Buffer contains %v", bufferC.String())
 	}
 
-	writer.Close()
+	writer.CloseWriters()
 }
 
 type devNullCloser int