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 <bbaude@redhat.com>

Closes: #437
Approved by: baude
This commit is contained in:
baude
2018-03-02 08:38:52 -06:00
committed by Atomic Bot
parent 656840c992
commit 0c4a276a04

View File

@ -129,14 +129,14 @@ func logsCmd(c *cli.Context) error {
defer file.Close() defer file.Close()
reader := bufio.NewReader(file) reader := bufio.NewReader(file)
if opts.follow { if opts.follow {
followLog(reader, opts) followLog(reader, opts, ctr)
} else { } else {
dumpLog(reader, opts) dumpLog(reader, opts)
} }
return err return err
} }
func followLog(reader *bufio.Reader, opts logOptions) error { func followLog(reader *bufio.Reader, opts logOptions, ctr *libpod.Container) error {
var cacheOutput []string var cacheOutput []string
firstPass := false firstPass := false
if opts.tail > 0 { if opts.tail > 0 {
@ -161,6 +161,14 @@ func followLog(reader *bufio.Reader, opts logOptions) error {
continue continue
} }
time.Sleep(1 * time.Second) 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 continue
} }
// exits // exits