From 0c4a276a04e8d9344571aa30dcab966f7096dcdc Mon Sep 17 00:00:00 2001 From: baude Date: Fri, 2 Mar 2018 08:38:52 -0600 Subject: podman logs -f: does not detect container stop or rm If a container stops, we should stop the logging capability and gracefully exit. However, if the container pauses, we should allow the log to continue. Resolves issue: #435 Signed-off-by: baude Closes: #437 Approved by: baude --- cmd/podman/logs.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'cmd/podman/logs.go') diff --git a/cmd/podman/logs.go b/cmd/podman/logs.go index 07d95aaf8..1183abaa2 100644 --- a/cmd/podman/logs.go +++ b/cmd/podman/logs.go @@ -129,14 +129,14 @@ func logsCmd(c *cli.Context) error { defer file.Close() reader := bufio.NewReader(file) if opts.follow { - followLog(reader, opts) + followLog(reader, opts, ctr) } else { dumpLog(reader, opts) } return err } -func followLog(reader *bufio.Reader, opts logOptions) error { +func followLog(reader *bufio.Reader, opts logOptions, ctr *libpod.Container) error { var cacheOutput []string firstPass := false if opts.tail > 0 { @@ -161,6 +161,14 @@ func followLog(reader *bufio.Reader, opts logOptions) error { continue } time.Sleep(1 * time.Second) + // Check if container is still running or paused + state, err := ctr.State() + if err != nil { + return err + } + if state != libpod.ContainerStateRunning && state != libpod.ContainerStatePaused { + break + } continue } // exits -- cgit v1.2.3-54-g00ecf