summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorAshley Cui <acui@redhat.com>2021-02-17 15:02:22 -0500
committerAshley Cui <acui@redhat.com>2021-02-19 02:21:12 -0500
commit9016387bba45bd681d64e6b01f9c94f7bbb0448a (patch)
treea95448fb35c2751d450df1b5ffb4d0bedb4470bd /libpod
parentf2d057c943957dce99b49d291c2e1b96af31a9e5 (diff)
downloadpodman-9016387bba45bd681d64e6b01f9c94f7bbb0448a.tar.gz
podman-9016387bba45bd681d64e6b01f9c94f7bbb0448a.tar.bz2
podman-9016387bba45bd681d64e6b01f9c94f7bbb0448a.zip
Fix journald logs --follow
Previously, --follow with a podman logs using journald would not exit Signed-off-by: Ashley Cui <acui@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_log_linux.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/libpod/container_log_linux.go b/libpod/container_log_linux.go
index af46191d0..713db9c1e 100644
--- a/libpod/container_log_linux.go
+++ b/libpod/container_log_linux.go
@@ -11,8 +11,10 @@ import (
"strings"
"time"
+ "github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/libpod/logs"
journal "github.com/coreos/go-systemd/v22/sdjournal"
+ "github.com/hpcloud/tail/watch"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -65,8 +67,12 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption
if options.Tail == math.MaxInt64 {
r.Rewind()
}
+ state, err := c.State()
+ if err != nil {
+ return err
+ }
- if options.Follow {
+ if options.Follow && state == define.ContainerStateRunning {
go func() {
done := make(chan bool)
until := make(chan time.Time)
@@ -78,6 +84,21 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption
// nothing to do anymore
}
}()
+ go func() {
+ for {
+ state, err := c.State()
+ if err != nil {
+ until <- time.Time{}
+ logrus.Error(err)
+ break
+ }
+ time.Sleep(watch.POLL_DURATION)
+ if state != define.ContainerStateRunning && state != define.ContainerStatePaused {
+ until <- time.Time{}
+ break
+ }
+ }
+ }()
follower := FollowBuffer{logChannel}
err := r.Follow(until, follower)
if err != nil {