Browse Source

Close logs pipes and catch write errors

Signed-off-by: Alexandr Morozov <lk4d4@docker.com>
Alexandr Morozov 10 years ago
parent
commit
a7ee201ee8
2 changed files with 5 additions and 1 deletions
  1. 2 0
      daemon/logs.go
  2. 3 1
      pkg/jsonlog/jsonlog.go

+ 2 - 0
daemon/logs.go

@@ -114,12 +114,14 @@ func (daemon *Daemon) ContainerLogs(job *engine.Job) engine.Status {
 		errors := make(chan error, 2)
 		if stdout {
 			stdoutPipe := container.StdoutLogPipe()
+			defer stdoutPipe.Close()
 			go func() {
 				errors <- jsonlog.WriteLog(stdoutPipe, job.Stdout, format)
 			}()
 		}
 		if stderr {
 			stderrPipe := container.StderrLogPipe()
+			defer stderrPipe.Close()
 			go func() {
 				errors <- jsonlog.WriteLog(stderrPipe, job.Stderr, format)
 			}()

+ 3 - 1
pkg/jsonlog/jsonlog.go

@@ -40,6 +40,8 @@ func WriteLog(src io.Reader, dst io.Writer, format string) error {
 		if err != nil {
 			return err
 		}
-		fmt.Fprintf(dst, "%s", line)
+		if _, err := io.WriteString(dst, line); err != nil {
+			return err
+		}
 	}
 }