summaryrefslogtreecommitdiff
path: root/libpod/container_internal.go
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2019-02-12 12:57:11 -0500
committerMatthew Heon <mheon@redhat.com>2019-02-12 12:57:11 -0500
commit19a03976f73d21a821a07ae5f24250a4ceaee33a (patch)
tree8021d67f20528bd6c4bb79035d6e124b53b2b0db /libpod/container_internal.go
parentb6775d5d22d463e4d92d6358ccd48dab6f8a1862 (diff)
downloadpodman-19a03976f73d21a821a07ae5f24250a4ceaee33a.tar.gz
podman-19a03976f73d21a821a07ae5f24250a4ceaee33a.tar.bz2
podman-19a03976f73d21a821a07ae5f24250a4ceaee33a.zip
Retain a copy of container exit file on cleanup
When cleaning up containers, we presently remove the exit file created by Conmon, to ensure that if we restart the container, we won't have conflicts when Conmon tries writing a new exit file. Unfortunately, we need to retain that exit file (at least until we get a workable events system), so we can read it in cases where the container has been removed before 'podman run' can read its exit code. So instead of removing it, rename it, so there's no conflict with Conmon, and we can still read it later. Fixes: #1640 Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r--libpod/container_internal.go15
1 files changed, 13 insertions, 2 deletions
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