From d3a433181d4aefb6b8d2efdd18066c7322f658a2 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 12 Aug 2019 16:30:05 -0400 Subject: Fix container exit code with Journald backend We weren't actually storing this, so we'd lose the exit code for containers run with --rm or force-removed while running if the journald backend for events was in use. Fixes #3795 Signed-off-by: Matthew Heon --- libpod/events/journal_linux.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libpod') diff --git a/libpod/events/journal_linux.go b/libpod/events/journal_linux.go index 7d195dc79..72551c9ec 100644 --- a/libpod/events/journal_linux.go +++ b/libpod/events/journal_linux.go @@ -4,6 +4,7 @@ package events import ( "fmt" + "strconv" "time" "github.com/coreos/go-systemd/journal" @@ -42,6 +43,7 @@ func (e EventJournalD) Write(ee Event) error { m["PODMAN_IMAGE"] = ee.Image m["PODMAN_NAME"] = ee.Name m["PODMAN_ID"] = ee.ID + m["PODMAN_EXIT_CODE"] = strconv.Itoa(ee.ContainerExitCode) case Volume: m["PODMAN_NAME"] = ee.Name } @@ -150,6 +152,14 @@ func newEventFromJournalEntry(entry *sdjournal.JournalEntry) (*Event, error) { / case Container, Pod: newEvent.ID = entry.Fields["PODMAN_ID"] newEvent.Image = entry.Fields["PODMAN_IMAGE"] + if code, ok := entry.Fields["PODMAN_EXIT_CODE"]; ok { + intCode, err := strconv.Atoi(code) + if err != nil { + logrus.Errorf("Error parsing event exit code %s", code) + } else { + newEvent.ContainerExitCode = intCode + } + } case Image: newEvent.ID = entry.Fields["PODMAN_ID"] } -- cgit v1.2.3-54-g00ecf