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 <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-10-29 14:19:28 +01:00
parent af34b2db47
commit 6348778348

View File

@ -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)