summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2020-04-22 11:50:52 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2020-04-22 11:53:00 -0400
commit1be8ded964a52a0bbdc753d47ad6141b3aa1a2e4 (patch)
tree93dc6a7d1aed40ea0680212174b73a7914e8f177 /cmd
parent7f1d00108e441b012785fa9d6e75317bad7ce239 (diff)
downloadpodman-1be8ded964a52a0bbdc753d47ad6141b3aa1a2e4.tar.gz
podman-1be8ded964a52a0bbdc753d47ad6141b3aa1a2e4.tar.bz2
podman-1be8ded964a52a0bbdc753d47ad6141b3aa1a2e4.zip
Fix podman rm to have correct exit codes
If you attempt to remove a running container is it supposed to exit with 2 If you attempt to remove a non existing container is is supposed to exit with 1 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/containers/rm.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go
index 12a7a3d89..3021853a9 100644
--- a/cmd/podman/containers/rm.go
+++ b/cmd/podman/containers/rm.go
@@ -95,11 +95,9 @@ func rm(cmd *cobra.Command, args []string) error {
}
responses, err := registry.ContainerEngine().ContainerRm(context.Background(), args, rmOptions)
if err != nil {
- // TODO exitcode is a global main variable to track exit codes.
- // we need this enabled
- //if len(c.InputArgs) < 2 {
- // exitCode = setExitCode(err)
- //}
+ if len(args) < 2 {
+ setExitCode(err)
+ }
return err
}
for _, r := range responses {
@@ -108,6 +106,7 @@ func rm(cmd *cobra.Command, args []string) error {
if errors.Cause(err) == define.ErrWillDeadlock {
logrus.Errorf("Potential deadlock detected - please run 'podman system renumber' to resolve")
}
+ setExitCode(r.Err)
errs = append(errs, r.Err)
} else {
fmt.Println(r.Id)
@@ -115,3 +114,13 @@ func rm(cmd *cobra.Command, args []string) error {
}
return errs.PrintErrors()
}
+
+func setExitCode(err error) {
+ cause := errors.Cause(err)
+ switch cause {
+ case define.ErrNoSuchCtr:
+ registry.SetExitCode(1)
+ case define.ErrCtrStateInvalid:
+ registry.SetExitCode(2)
+ }
+}