Explorar o código

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>
Nalin Dahyabhai %!s(int64=8) %!d(string=hai) anos
pai
achega
d57c330617
Modificáronse 1 ficheiros con 5 adicións e 0 borrados
  1. 5 0
      daemon/logger/journald/read.go

+ 5 - 0
daemon/logger/journald/read.go

@@ -246,6 +246,8 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
 	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() {
 		for {
 		for {
 			// Keep copying journal data out until we're notified to stop
 			// Keep copying journal data out until we're notified to stop
@@ -274,6 +276,7 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
 		s.readers.mu.Unlock()
 		s.readers.mu.Unlock()
 		C.sd_journal_close(j)
 		C.sd_journal_close(j)
 		close(logWatcher.Msg)
 		close(logWatcher.Msg)
+		newCursor <- cursor
 	}()
 	}()
 
 
 	// Wait until we're told to stop.
 	// Wait until we're told to stop.
@@ -283,6 +286,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
 }
 }