From 082d792693504848e186a29db717ce20c7ff7774 Mon Sep 17 00:00:00 2001
From: Debarshi Ray <rishi@fedoraproject.org>
Date: Wed, 13 Mar 2019 20:19:31 +0100
Subject: Make 'podman rm' exit with 125 if it had a bogus & a running
 container

Getting a list of containers, and then deleting them are two separate
fallible steps that can run into different sets of errors. eg., in the
case of a bogus missing container and a container that's running or
paused, the first step will only trigger libpod.ErrNoSuchCtr. At this
point it might appear that the exit code ought to be 1. However, when
attempting the deletion, it will fail once more due to the status of
the running or paused container. Since libpod.ErrNoSuchCtr is no longer
the only error encountered, the exit code should be reset to 125.

This problem is currently masked for rootless usage due to commit
35432ecaae4a8372 ("rootless: fix rm when uid in the container != 0").

Fixes: 85db895012bead6b ("rm: set exit code to 1 if a specified ...")
       e41279b902a334e5 ("Change exit code to 1 on podman rm ...")

Signed-off-by: Debarshi Ray <rishi@fedoraproject.org>
---
 cmd/podman/rm.go | 5 +++++
 1 file changed, 5 insertions(+)

(limited to 'cmd')

diff --git a/cmd/podman/rm.go b/cmd/podman/rm.go
index 56aaae9eb..299420bb6 100644
--- a/cmd/podman/rm.go
+++ b/cmd/podman/rm.go
@@ -195,5 +195,10 @@ func rmCmd(c *cliconfig.RmValues) error {
 			exitCode = 1
 		}
 	}
+
+	if failureCnt > 0 {
+		exitCode = 125
+	}
+
 	return err
 }
-- 
cgit v1.2.3-54-g00ecf