From 4730409857f4bb0494a381398d878a4a49378ced Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 22 Feb 2017 16:22:00 -0500 Subject: [PATCH] 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 (cherry picked from commit d57c330617efb97cad736a3e4ede82bb46ebbbf2) Signed-off-by: Victor Vieux --- daemon/logger/journald/read.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/daemon/logger/journald/read.go b/daemon/logger/journald/read.go index c01b28ca34..2fbbfe175d 100644 --- a/daemon/logger/journald/read.go +++ b/daemon/logger/journald/read.go @@ -248,6 +248,9 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re s.readers.mu.Lock() s.readers.readers[logWatcher] = logWatcher s.readers.mu.Unlock() + + newCursor := make(chan *C.char) + go func() { // Keep copying journal data out until we're notified to stop // or we hit an error. @@ -268,6 +271,7 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re delete(s.readers.readers, logWatcher) s.readers.mu.Unlock() close(logWatcher.Msg) + newCursor <- cursor }() // Wait until we're told to stop. select { @@ -276,6 +280,8 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re C.close(pfd[1]) } + cursor = <-newCursor + return cursor }