diff options
-rw-r--r-- | cmd/podman/run.go | 2 | ||||
-rw-r--r-- | libpod/container_internal.go | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/cmd/podman/run.go b/cmd/podman/run.go index 6002578ff..86dc02dea 100644 --- a/cmd/podman/run.go +++ b/cmd/podman/run.go @@ -160,7 +160,7 @@ func runCmd(c *cliconfig.RunValues) error { // Read a container's exit file func readExitFile(runtimeTmp, ctrID string) (int, error) { - exitFile := filepath.Join(runtimeTmp, "exits", ctrID) + exitFile := filepath.Join(runtimeTmp, "exits", fmt.Sprintf("%s-old", ctrID)) logrus.Debugf("Attempting to read container %s exit code from file %s", ctrID, exitFile) diff --git a/libpod/container_internal.go b/libpod/container_internal.go index b0dcc853e..f82cbd674 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -489,9 +489,20 @@ func (c *Container) removeConmonFiles() error { return errors.Wrapf(err, "error removing container %s OOM file", c.ID()) } + // Instead of outright deleting the exit file, rename it (if it exists). + // We want to retain it so we can get the exit code of containers which + // are removed (at least until we have a workable events system) exitFile := filepath.Join(c.runtime.ociRuntime.exitsDir, c.ID()) - if err := os.Remove(exitFile); err != nil && !os.IsNotExist(err) { - return errors.Wrapf(err, "error removing container %s exit file", c.ID()) + oldExitFile := filepath.Join(c.runtime.ociRuntime.exitsDir, fmt.Sprintf("%s-old", c.ID())) + if _, err := os.Stat(exitFile); err != nil { + if !os.IsNotExist(err) { + return errors.Wrapf(err, "error running stat on container %s exit file", c.ID()) + } + } else if err == nil { + // Rename should replace the old exit file (if it exists) + if err := os.Rename(exitFile, oldExitFile); err != nil { + return errors.Wrapf(err, "error renaming container %s exit file", c.ID()) + } } return nil |