Skip to content

Commit e5a7bc3

Browse files
authored
Merge pull request containerd#3841 from apostasie/fix-3840
Fix journald logger exit and wait behavior
2 parents 67a1088 + 82791bf commit e5a7bc3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/logging/journald_logger.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,21 @@ func FetchLogs(stdout, stderr io.Writer, journalctlArgs []string, stopChannel ch
173173
}
174174

175175
// Setup killing goroutine:
176+
killed := false
176177
go func() {
177178
<-stopChannel
179+
killed = true
178180
log.L.Debugf("killing journalctl logs process with PID: %#v", cmd.Process.Pid)
179181
cmd.Process.Kill()
180182
}()
181183

184+
err = cmd.Wait()
185+
if exitError, ok := err.(*exec.ExitError); ok {
186+
if !killed && exitError.ExitCode() != 0 {
187+
return fmt.Errorf("journalctl command exited with non-zero exit code (%d): %w", exitError.ExitCode(), exitError)
188+
}
189+
}
190+
182191
return nil
183192
}
184193

0 commit comments

Comments
 (0)