summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-13 22:55:52 +0100
committerGitHub <noreply@github.com>2019-02-13 22:55:52 +0100
commitdfc64e15d7f8b1715798fd68bd3ff74ae192b354 (patch)
tree28fff3097e5705623bc48670c67dee64a5296329 /libpod
parent29d9ccf38158235ef37e4f5c20ad152bb396e3b9 (diff)
parent9d4e7fe58b10c4130340a151a377cf7be8aaa810 (diff)
downloadpodman-dfc64e15d7f8b1715798fd68bd3ff74ae192b354.tar.gz
podman-dfc64e15d7f8b1715798fd68bd3ff74ae192b354.tar.bz2
podman-dfc64e15d7f8b1715798fd68bd3ff74ae192b354.zip
Merge pull request #2319 from mheon/unconditional_cleanup
Fix manual detach from containers to not wait for exit
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_attach_linux.go4
-rw-r--r--libpod/container_internal.go15
-rw-r--r--libpod/errors.go5
3 files changed, 20 insertions, 4 deletions
diff --git a/libpod/container_attach_linux.go b/libpod/container_attach_linux.go
index 1d6f0bd96..3ff6ddc76 100644
--- a/libpod/container_attach_linux.go
+++ b/libpod/container_attach_linux.go
@@ -109,8 +109,8 @@ func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSi
case err := <-receiveStdoutError:
return err
case err := <-stdinDone:
- if _, ok := err.(utils.DetachError); ok {
- return nil
+ if err == ErrDetach {
+ return err
}
if streams.AttachOutput || streams.AttachError {
return <-receiveStdoutError
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
diff --git a/libpod/errors.go b/libpod/errors.go
index 30a19d30f..dd82d0796 100644
--- a/libpod/errors.go
+++ b/libpod/errors.go
@@ -4,6 +4,7 @@ import (
"errors"
"github.com/containers/libpod/libpod/image"
+ "github.com/containers/libpod/utils"
)
var (
@@ -56,6 +57,10 @@ var (
// ErrInternal indicates an internal library error
ErrInternal = errors.New("internal libpod error")
+ // ErrDetach indicates that an attach session was manually detached by
+ // the user.
+ ErrDetach = utils.ErrDetach
+
// ErrRuntimeStopped indicates that the runtime has already been shut
// down and no further operations can be performed on it
ErrRuntimeStopped = errors.New("runtime has already been stopped")