diff options
author | Qi Wang <qiwan@redhat.com> | 2020-06-10 14:14:01 -0400 |
---|---|---|
committer | Qi Wang <qiwan@redhat.com> | 2020-06-11 17:55:26 -0400 |
commit | 033743cbee180d9a4149f574375cc1201e573d06 (patch) | |
tree | 280ff78ae8e5fffaf5c57acb77496c5358a95864 | |
parent | 1f05606fac7e5835cd76ef407a64597df3251aae (diff) | |
download | podman-033743cbee180d9a4149f574375cc1201e573d06.tar.gz podman-033743cbee180d9a4149f574375cc1201e573d06.tar.bz2 podman-033743cbee180d9a4149f574375cc1201e573d06.zip |
Fix -f logs follow with stopped container
Fix -f logs follow with stopped container. Close #6531
Signed-off-by: Qi Wang <qiwan@redhat.com>
-rw-r--r-- | libpod/container_log.go | 15 | ||||
-rw-r--r-- | test/e2e/logs_test.go | 12 |
2 files changed, 27 insertions, 0 deletions
diff --git a/libpod/container_log.go b/libpod/container_log.go index c3a84d048..36b89f1ae 100644 --- a/libpod/container_log.go +++ b/libpod/container_log.go @@ -30,6 +30,13 @@ func (c *Container) ReadLog(options *logs.LogOptions, logChannel chan *logs.LogL } func (c *Container) readFromLogFile(options *logs.LogOptions, logChannel chan *logs.LogLine) error { + state, err := c.State() + if err != nil { + return err + } + if state != define.ContainerStateRunning && state != define.ContainerStatePaused { + options.Follow = false + } t, tailLog, err := logs.GetLogFile(c.LogPath(), options) if err != nil { // If the log file does not exist, this is not fatal. @@ -69,6 +76,14 @@ func (c *Container) readFromLogFile(options *logs.LogOptions, logChannel chan *l if nll.Since(options.Since) { logChannel <- nll } + state, err := c.State() + if err != nil { + logrus.Error(err) + break + } + if options.Follow && state != define.ContainerStateRunning && state != define.ContainerStatePaused { + t.Kill(err) + } } options.WaitGroup.Done() }() diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go index f36163ccc..f9446e0c6 100644 --- a/test/e2e/logs_test.go +++ b/test/e2e/logs_test.go @@ -288,4 +288,16 @@ var _ = Describe("Podman logs", func() { logc.WaitWithDefaultTimeout() Expect(logc).To(Exit(0)) }) + + It("follow output stopped container", func() { + containerName := "logs-f" + + logc := podmanTest.Podman([]string{"run", "--name", containerName, "-d", ALPINE}) + logc.WaitWithDefaultTimeout() + Expect(logc).To(Exit(0)) + + results := podmanTest.Podman([]string{"logs", "-f", containerName}) + results.WaitWithDefaultTimeout() + Expect(results).To(Exit(0)) + }) }) |