summaryrefslogtreecommitdiff
path: root/cmd/podman/run.go
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2019-02-11 12:57:08 -0500
committerMatthew Heon <mheon@redhat.com>2019-02-12 10:14:57 -0500
commitb6775d5d22d463e4d92d6358ccd48dab6f8a1862 (patch)
treea0c0373125736b8b9bf59c93a794c7cadadd05c2 /cmd/podman/run.go
parentbdf537f4fc983c30c945297d9ee33891a127f9bd (diff)
downloadpodman-b6775d5d22d463e4d92d6358ccd48dab6f8a1862.tar.gz
podman-b6775d5d22d463e4d92d6358ccd48dab6f8a1862.tar.bz2
podman-b6775d5d22d463e4d92d6358ccd48dab6f8a1862.zip
Fix manual detach from containers to not wait for exit
At present, when manually detaching from an attached container (using the detach hotkeys, default C-p C-q), Podman will still wait for the container to exit to obtain its exit code (so we can set Podman's exit code to match). This is correct in the case where attach finished because the container exited, but very wrong for the manual detach case. As a result of this, we can no longer guarantee that the cleanup and --rm functions will fire at the end of 'podman run' - we may be exiting before we get that far. Cleanup is easy enough - we swap to unconditionally using the cleanup processes we've used for detached and rootless containers all along. To duplicate --rm we need to also teach 'podman cleanup' to optionally remove containers instead of cleaning them up. (There is an argument for just using 'podman rm' instead of 'podman cleanup --rm', but cleanup does have different semantics given that we only ever expect it to run when the container has just exited. I think it might be useful to keep the two separate for things like 'podman events'...) Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'cmd/podman/run.go')
-rw-r--r--cmd/podman/run.go24
1 files changed, 8 insertions, 16 deletions
diff --git a/cmd/podman/run.go b/cmd/podman/run.go
index 8649dc190..6002578ff 100644
--- a/cmd/podman/run.go
+++ b/cmd/podman/run.go
@@ -118,6 +118,14 @@ func runCmd(c *cliconfig.RunValues) error {
}
}
if err := startAttachCtr(ctr, outputStream, errorStream, inputStream, c.String("detach-keys"), c.Bool("sig-proxy"), true); err != nil {
+ // We've manually detached from the container
+ // Do not perform cleanup, or wait for container exit code
+ // Just exit immediately
+ if err == libpod.ErrDetach {
+ exitCode = 0
+ return nil
+ }
+
// This means the command did not exist
exitCode = 127
if strings.Index(err.Error(), "permission denied") > -1 {
@@ -147,22 +155,6 @@ func runCmd(c *cliconfig.RunValues) error {
exitCode = int(ecode)
}
- if createConfig.Rm {
- return runtime.RemoveContainer(ctx, ctr, true)
- }
-
- if err := ctr.Cleanup(ctx); err != nil {
- // If the container has been removed already, no need to error on cleanup
- // Also, if it was restarted, don't error either
- if errors.Cause(err) == libpod.ErrNoSuchCtr ||
- errors.Cause(err) == libpod.ErrCtrRemoved ||
- errors.Cause(err) == libpod.ErrCtrStateInvalid {
- return nil
- }
-
- return err
- }
-
return nil
}