Browse code

Close logs pipes and catch write errors

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

Alexandr Morozov authored on 2014/09/22 15:55:46
Showing 2 changed files
... ...
@@ -114,12 +114,14 @@ func (daemon *Daemon) ContainerLogs(job *engine.Job) engine.Status {
114 114
 		errors := make(chan error, 2)
115 115
 		if stdout {
116 116
 			stdoutPipe := container.StdoutLogPipe()
117
+			defer stdoutPipe.Close()
117 118
 			go func() {
118 119
 				errors <- jsonlog.WriteLog(stdoutPipe, job.Stdout, format)
119 120
 			}()
120 121
 		}
121 122
 		if stderr {
122 123
 			stderrPipe := container.StderrLogPipe()
124
+			defer stderrPipe.Close()
123 125
 			go func() {
124 126
 				errors <- jsonlog.WriteLog(stderrPipe, job.Stderr, format)
125 127
 			}()
... ...
@@ -40,6 +40,8 @@ func WriteLog(src io.Reader, dst io.Writer, format string) error {
40 40
 		if err != nil {
41 41
 			return err
42 42
 		}
43
-		fmt.Fprintf(dst, "%s", line)
43
+		if _, err := io.WriteString(dst, line); err != nil {
44
+			return err
45
+		}
44 46
 	}
45 47
 }