summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-03-17 10:09:10 -0500
committerbaude <bbaude@redhat.com>2019-03-18 08:58:48 -0500
commit46f18764f205ead97fb5da70104951cf90bf5b6b (patch)
tree4f6512ae594ec9b475af29716afb9916428a7542
parentea54a1c2f51d3173649277939738ce9b1c392076 (diff)
downloadpodman-46f18764f205ead97fb5da70104951cf90bf5b6b.tar.gz
podman-46f18764f205ead97fb5da70104951cf90bf5b6b.tar.bz2
podman-46f18764f205ead97fb5da70104951cf90bf5b6b.zip
podman logs on created container should exit
when running podman logs on a created container (which has no logs), podman should return gracefully (like docker) with a 0 return code. if multiple containers are provided and one is only in the created state (and no follow is used), we still display the logs for the other ids. fixes issue #2677 Signed-off-by: baude <bbaude@redhat.com>
-rw-r--r--libpod/container_log.go7
-rw-r--r--test/e2e/logs_test.go10
2 files changed, 16 insertions, 1 deletions
diff --git a/libpod/container_log.go b/libpod/container_log.go
index 7964e4022..e998ad316 100644
--- a/libpod/container_log.go
+++ b/libpod/container_log.go
@@ -3,6 +3,7 @@ package libpod
import (
"fmt"
"io/ioutil"
+ "os"
"strings"
"sync"
"time"
@@ -54,6 +55,10 @@ func (r *Runtime) Log(containers []*Container, options *LogOptions, logChannel c
func (c *Container) ReadLog(options *LogOptions, logChannel chan *LogLine) error {
t, tailLog, err := getLogFile(c.LogPath(), options)
if err != nil {
+ // If the log file does not exist, this is not fatal.
+ if os.IsNotExist(errors.Cause(err)) {
+ return nil
+ }
return errors.Wrapf(err, "unable to read log file %s for %s ", c.ID(), c.LogPath())
}
options.WaitGroup.Add(1)
@@ -111,7 +116,7 @@ func getLogFile(path string, options *LogOptions) (*tail.Tail, []*LogLine, error
Whence: whence,
}
- t, err := tail.TailFile(path, tail.Config{Poll: true, Follow: options.Follow, Location: &seek, Logger: tail.DiscardingLogger})
+ t, err := tail.TailFile(path, tail.Config{MustExist: true, Poll: true, Follow: options.Follow, Location: &seek, Logger: tail.DiscardingLogger})
return t, logTail, err
}
diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go
index d383a83b3..d051e3dba 100644
--- a/test/e2e/logs_test.go
+++ b/test/e2e/logs_test.go
@@ -132,4 +132,14 @@ var _ = Describe("Podman logs", func() {
Expect(len(output)).To(Equal(6))
Expect(strings.Contains(output[0], cid1[:12]) || strings.Contains(output[0], cid2[:12])).To(BeTrue())
})
+
+ It("podman logs on a created container should result in 0 exit code", func() {
+ session := podmanTest.Podman([]string{"create", "-dt", "--name", "log", ALPINE})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(BeZero())
+
+ results := podmanTest.Podman([]string{"logs", "log"})
+ results.WaitWithDefaultTimeout()
+ Expect(results.ExitCode()).To(BeZero())
+ })
})