From 63487783482b451d482e394b92b43ac34c46fd75 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Tue, 29 Oct 2024 14:19:28 +0100 Subject: [PATCH] libpod: log file use Wait() over event API Using the internal Wait() API over the events API as this is much more efficient. Reading events will need to read a lot of data otherwise. For the function here it should work fine and it is even better as it does not depend on the event logger at all. Signed-off-by: Paul Holzinger --- libpod/container_log.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/libpod/container_log.go b/libpod/container_log.go index ea76c7ea39..91c0a50ccf 100644 --- a/libpod/container_log.go +++ b/libpod/container_log.go @@ -10,7 +10,6 @@ import ( "time" "github.com/containers/podman/v5/libpod/define" - "github.com/containers/podman/v5/libpod/events" "github.com/containers/podman/v5/libpod/logs" systemdDefine "github.com/containers/podman/v5/pkg/systemd/define" "github.com/nxadm/tail" @@ -139,20 +138,10 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption // The container is running, so we need to wait until the container exited go func() { - eventChannel := make(chan *events.Event) - eventOptions := events.ReadOptions{ - EventChannel: eventChannel, - Filters: []string{"event=died", "container=" + c.ID()}, - Stream: true, + _, err = c.Wait(ctx) + if err != nil && !errors.Is(err, define.ErrNoSuchCtr) { + logrus.Errorf("Waiting for container to exit: %v", err) } - go func() { - if err := c.runtime.Events(ctx, eventOptions); err != nil { - logrus.Errorf("Waiting for container to exit: %v", err) - } - }() - // Now wait for the died event and signal to finish - // reading the log until EOF. - <-eventChannel // Make sure to wait at least for the poll duration // before stopping the file logger (see #10675). time.Sleep(watch.POLL_DURATION)