mirror of
https://github.com/containers/podman.git
synced 2025-08-23 09:18:19 +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"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/podman/v5/libpod/define"
|
"github.com/containers/podman/v5/libpod/define"
|
||||||
"github.com/containers/podman/v5/libpod/events"
|
|
||||||
"github.com/containers/podman/v5/libpod/logs"
|
"github.com/containers/podman/v5/libpod/logs"
|
||||||
systemdDefine "github.com/containers/podman/v5/pkg/systemd/define"
|
systemdDefine "github.com/containers/podman/v5/pkg/systemd/define"
|
||||||
"github.com/nxadm/tail"
|
"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
|
// The container is running, so we need to wait until the container exited
|
||||||
go func() {
|
go func() {
|
||||||
eventChannel := make(chan *events.Event)
|
_, err = c.Wait(ctx)
|
||||||
eventOptions := events.ReadOptions{
|
if err != nil && !errors.Is(err, define.ErrNoSuchCtr) {
|
||||||
EventChannel: eventChannel,
|
logrus.Errorf("Waiting for container to exit: %v", err)
|
||||||
Filters: []string{"event=died", "container=" + c.ID()},
|
|
||||||
Stream: true,
|
|
||||||
}
|
}
|
||||||
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
|
// Make sure to wait at least for the poll duration
|
||||||
// before stopping the file logger (see #10675).
|
// before stopping the file logger (see #10675).
|
||||||
time.Sleep(watch.POLL_DURATION)
|
time.Sleep(watch.POLL_DURATION)
|
||||||
|
Reference in New Issue
Block a user