From 74fcd9fef3a31fa94f3487361b5fda1180e8cee2 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 11 Dec 2020 17:02:21 +0100 Subject: podman events allow future time for --until The podman events aren't read until the given timestamp if the timestamp is in the future. It just reads all events until now and exits afterwards. This does not make sense and does not match docker. The correct behavior is to read all events until the given time is reached. This fixes a bug where the wrong event log file path was used when running first time with a new storage location. Fixes #8694 This also fixes the events api endpoint which only exited when an error occurred. Otherwise it just hung after reading all events. Signed-off-by: Paul Holzinger --- libpod/events/journal_linux.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libpod/events/journal_linux.go') diff --git a/libpod/events/journal_linux.go b/libpod/events/journal_linux.go index 9a514e302..71c638017 100644 --- a/libpod/events/journal_linux.go +++ b/libpod/events/journal_linux.go @@ -8,6 +8,7 @@ import ( "strconv" "time" + "github.com/containers/podman/v2/pkg/util" "github.com/coreos/go-systemd/v22/journal" "github.com/coreos/go-systemd/v22/sdjournal" "github.com/pkg/errors" @@ -72,6 +73,13 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error { if err != nil { return errors.Wrapf(err, "failed to generate event options") } + var untilTime time.Time + if len(options.Until) > 0 { + untilTime, err = util.ParseInputTime(options.Until) + if err != nil { + return err + } + } j, err := sdjournal.NewJournal() if err != nil { return err @@ -122,10 +130,14 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error { return errors.Wrap(err, "failed to get journal cursor") } if prevCursor == newCursor { - if len(options.Until) > 0 || !options.Stream { + if !options.Stream || (len(options.Until) > 0 && time.Now().After(untilTime)) { break } - _ = j.Wait(sdjournal.IndefiniteWait) + t := sdjournal.IndefiniteWait + if len(options.Until) > 0 { + t = time.Until(untilTime) + } + _ = j.Wait(t) continue } prevCursor = newCursor -- cgit v1.2.3-54-g00ecf