summaryrefslogtreecommitdiff
path: root/libpod/container_log_linux.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-07-09 17:05:47 +0200
committerGitHub <noreply@github.com>2020-07-09 17:05:47 +0200
commitbc3b3b373fab58929f4583ab0b5eb529e64a54fc (patch)
treed6a64a013d2957d676a1e74e3374350dfc2fbef0 /libpod/container_log_linux.go
parentf86782c05293987acc750b259fa5a7fa0106b5b6 (diff)
parentd0ebea06437f05dfd42ec50e1eef2da0310b65d9 (diff)
downloadpodman-bc3b3b373fab58929f4583ab0b5eb529e64a54fc.tar.gz
podman-bc3b3b373fab58929f4583ab0b5eb529e64a54fc.tar.bz2
podman-bc3b3b373fab58929f4583ab0b5eb529e64a54fc.zip
Merge pull request #6916 from vrothberg/logs-fixes
log API: add context to allow for cancelling
Diffstat (limited to 'libpod/container_log_linux.go')
-rw-r--r--libpod/container_log_linux.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/libpod/container_log_linux.go b/libpod/container_log_linux.go
index fad3bf87c..00b2039a9 100644
--- a/libpod/container_log_linux.go
+++ b/libpod/container_log_linux.go
@@ -4,6 +4,7 @@
package libpod
import (
+ "context"
"fmt"
"io"
"math"
@@ -29,7 +30,7 @@ const (
bufLen = 16384
)
-func (c *Container) readFromJournal(options *logs.LogOptions, logChannel chan *logs.LogLine) error {
+func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOptions, logChannel chan *logs.LogLine) error {
var config journal.JournalReaderConfig
if options.Tail < 0 {
config.NumFromTail = math.MaxUint64
@@ -65,13 +66,24 @@ func (c *Container) readFromJournal(options *logs.LogOptions, logChannel chan *l
if options.Follow {
go func() {
+ done := make(chan bool)
+ until := make(chan time.Time)
+ go func() {
+ select {
+ case <-ctx.Done():
+ until <- time.Time{}
+ case <-done:
+ // nothing to do anymore
+ }
+ }()
follower := FollowBuffer{logChannel}
- err := r.Follow(nil, follower)
+ err := r.Follow(until, follower)
if err != nil {
logrus.Debugf(err.Error())
}
r.Close()
options.WaitGroup.Done()
+ done <- true
return
}()
return nil