mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Synchronize the cursor returned by followJournal
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>
(cherry picked from commit d57c330617
)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
52a7b8350a
commit
4730409857
1 changed files with 6 additions and 0 deletions
|
@ -248,6 +248,9 @@ 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()
|
||||||
|
|
||||||
|
newCursor := make(chan *C.char)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// Keep copying journal data out until we're notified to stop
|
// Keep copying journal data out until we're notified to stop
|
||||||
// or we hit an error.
|
// or we hit an error.
|
||||||
|
@ -268,6 +271,7 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
|
||||||
delete(s.readers.readers, logWatcher)
|
delete(s.readers.readers, logWatcher)
|
||||||
s.readers.mu.Unlock()
|
s.readers.mu.Unlock()
|
||||||
close(logWatcher.Msg)
|
close(logWatcher.Msg)
|
||||||
|
newCursor <- cursor
|
||||||
}()
|
}()
|
||||||
// Wait until we're told to stop.
|
// Wait until we're told to stop.
|
||||||
select {
|
select {
|
||||||
|
@ -276,6 +280,8 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
|
||||||
C.close(pfd[1])
|
C.close(pfd[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cursor = <-newCursor
|
||||||
|
|
||||||
return cursor
|
return cursor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue