Skip to content

Commit

Permalink
Synchronize the cursor returned by followJournal
Browse files Browse the repository at this point in the history
Make sure that the cursor value returned by followJournal() is the last
of the values returned by its goroutine's calls to drainJournal() by
waiting for it, rather than returning a value that may be superceded by
another if we're singalling the goroutine that it should exit by closing
a pipe.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
  • Loading branch information
nalind committed Feb 22, 2017
1 parent 4534dcd commit d57c330
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions daemon/logger/journald/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
s.readers.readers[logWatcher] = logWatcher
s.readers.mu.Unlock()

newCursor := make(chan *C.char)

go func() {
for {
// Keep copying journal data out until we're notified to stop
Expand Down Expand Up @@ -274,6 +276,7 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
s.readers.mu.Unlock()
C.sd_journal_close(j)
close(logWatcher.Msg)
newCursor <- cursor
}()

// Wait until we're told to stop.
Expand All @@ -283,6 +286,8 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
C.close(pfd[1])
}

cursor = <-newCursor

return cursor
}

Expand Down

0 comments on commit d57c330

Please sign in to comment.