mirror of
https://github.com/containers/podman.git
synced 2025-05-17 06:59:07 +08:00
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:
@ -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)
|
||||
|
Reference in New Issue
Block a user