1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #29863 from ncdc/journald-logdriver-drain-one-more-time-after-follow-ends

journald logs: drain 1 more time at container exit
This commit is contained in:
Alexander Morozov 2017-02-01 10:30:14 -08:00 committed by GitHub
commit dc78b3a1d4

View file

@ -245,20 +245,28 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
s.readers.mu.Lock() s.readers.mu.Lock()
s.readers.readers[logWatcher] = logWatcher s.readers.readers[logWatcher] = logWatcher
s.readers.mu.Unlock() s.readers.mu.Unlock()
go func() { go func() {
// Keep copying journal data out until we're notified to stop for {
// or we hit an error. // Keep copying journal data out until we're notified to stop
status := C.wait_for_data_cancelable(j, pfd[0]) // or we hit an error.
for status == 1 { status := C.wait_for_data_cancelable(j, pfd[0])
if status < 0 {
cerrstr := C.strerror(C.int(-status))
errstr := C.GoString(cerrstr)
fmtstr := "error %q while attempting to follow journal for container %q"
logrus.Errorf(fmtstr, errstr, s.vars["CONTAINER_ID_FULL"])
break
}
cursor = s.drainJournal(logWatcher, config, j, cursor) cursor = s.drainJournal(logWatcher, config, j, cursor)
status = C.wait_for_data_cancelable(j, pfd[0])
} if status != 1 {
if status < 0 { // We were notified to stop
cerrstr := C.strerror(C.int(-status)) break
errstr := C.GoString(cerrstr) }
fmtstr := "error %q while attempting to follow journal for container %q"
logrus.Errorf(fmtstr, errstr, s.vars["CONTAINER_ID_FULL"])
} }
// Clean up. // Clean up.
C.close(pfd[0]) C.close(pfd[0])
s.readers.mu.Lock() s.readers.mu.Lock()
@ -267,6 +275,7 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
C.sd_journal_close(j) C.sd_journal_close(j)
close(logWatcher.Msg) close(logWatcher.Msg)
}() }()
// Wait until we're told to stop. // Wait until we're told to stop.
select { select {
case <-logWatcher.WatchClose(): case <-logWatcher.WatchClose():