From 0375566412eee45583a89fe4e50574d42780df18 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 12 Mar 2019 00:36:44 -0700 Subject: [PATCH] journald: fix for --tail 0 From the first glance, `docker logs --tail 0` does not make sense, as it is supposed to produce no output, but `tail -n 0` from GNU coreutils is working like that, plus there is even a test case (`TestLogsTail` in integration-cli/docker_cli_logs_test.go). Now, something like `docker logs --follow --tail 0` makes total sense, so let's make it work. (NOTE if --tail is not used, config.Tail is set to -1) Signed-off-by: Kir Kolyshkin (cherry picked from commit dd4bfe30a8ac1b31630310090dc36ae3d9253444) Signed-off-by: Kir Kolyshkin --- daemon/logger/journald/read.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/daemon/logger/journald/read.go b/daemon/logger/journald/read.go index 36240a832a..d6458b4986 100644 --- a/daemon/logger/journald/read.go +++ b/daemon/logger/journald/read.go @@ -332,7 +332,7 @@ func (s *journald) readLogs(logWatcher *logger.LogWatcher, config logger.ReadCon nano := config.Until.UnixNano() untilUnixMicro = uint64(nano / 1000) } - if config.Tail > 0 { + if config.Tail >= 0 { // If until time provided, start from there. // Otherwise start at the end of the journal. if untilUnixMicro != 0 && C.sd_journal_seek_realtime_usec(j, C.uint64_t(untilUnixMicro)) < 0 { @@ -343,7 +343,7 @@ func (s *journald) readLogs(logWatcher *logger.LogWatcher, config logger.ReadCon return } // (Try to) skip backwards by the requested number of lines... - if C.sd_journal_previous_skip(j, C.uint64_t(config.Tail)) > 0 { + if C.sd_journal_previous_skip(j, C.uint64_t(config.Tail)) >= 0 { // ...but not before "since" if sinceUnixMicro != 0 && C.sd_journal_get_realtime_usec(j, &stamp) == 0 && @@ -367,7 +367,9 @@ func (s *journald) readLogs(logWatcher *logger.LogWatcher, config logger.ReadCon return } } - cursor, _, _ = s.drainJournal(logWatcher, j, nil, untilUnixMicro) + if config.Tail != 0 { // special case for --tail 0 + cursor, _, _ = s.drainJournal(logWatcher, j, nil, untilUnixMicro) + } if config.Follow { cursor = s.followJournal(logWatcher, j, cursor, untilUnixMicro) // Let followJournal handle freeing the journal context