1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2019-03-12 00:36:44 -07:00
parent b73fb8fd5d
commit dd4bfe30a8

View file

@ -332,7 +332,7 @@ func (s *journald) readLogs(logWatcher *logger.LogWatcher, config logger.ReadCon
nano := config.Until.UnixNano() nano := config.Until.UnixNano()
untilUnixMicro = uint64(nano / 1000) untilUnixMicro = uint64(nano / 1000)
} }
if config.Tail > 0 { if config.Tail >= 0 {
// If until time provided, start from there. // If until time provided, start from there.
// Otherwise start at the end of the journal. // Otherwise start at the end of the journal.
if untilUnixMicro != 0 && C.sd_journal_seek_realtime_usec(j, C.uint64_t(untilUnixMicro)) < 0 { 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 return
} }
// (Try to) skip backwards by the requested number of lines... // (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" // ...but not before "since"
if sinceUnixMicro != 0 && if sinceUnixMicro != 0 &&
C.sd_journal_get_realtime_usec(j, &stamp) == 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 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 { if config.Follow {
cursor = s.followJournal(logWatcher, j, cursor, untilUnixMicro) cursor = s.followJournal(logWatcher, j, cursor, untilUnixMicro)
// Let followJournal handle freeing the journal context // Let followJournal handle freeing the journal context