summaryrefslogtreecommitdiff
path: root/cmd/podman/system/unshare.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-09-11 17:26:35 -0400
committerGitHub <noreply@github.com>2021-09-11 17:26:35 -0400
commitec3037062d1f9a5ece00ffd465c0f815c06f1b5c (patch)
tree54ecc133a0103d19084ed4ac99f7b57aebd97d4a /cmd/podman/system/unshare.go
parent0501258b735684948e32019c0499030309349fc9 (diff)
parentd2e10a71d69565929309ff3c32665b216698d8b1 (diff)
downloadpodman-ec3037062d1f9a5ece00ffd465c0f815c06f1b5c.tar.gz
podman-ec3037062d1f9a5ece00ffd465c0f815c06f1b5c.tar.bz2
podman-ec3037062d1f9a5ece00ffd465c0f815c06f1b5c.zip
Merge pull request #11513 from Luap99/unshare
podman unshare keep exit code
Diffstat (limited to 'cmd/podman/system/unshare.go')
-rw-r--r--cmd/podman/system/unshare.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/cmd/podman/system/unshare.go b/cmd/podman/system/unshare.go
index f930d8b62..50230609e 100644
--- a/cmd/podman/system/unshare.go
+++ b/cmd/podman/system/unshare.go
@@ -2,6 +2,7 @@ package system
import (
"os"
+ "os/exec"
"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v3/cmd/podman/registry"
@@ -50,5 +51,23 @@ func unshare(cmd *cobra.Command, args []string) error {
args = []string{shell}
}
- return registry.ContainerEngine().Unshare(registry.Context(), args, unshareOptions)
+ err := registry.ContainerEngine().Unshare(registry.Context(), args, unshareOptions)
+ if err != nil {
+ if exitError, ok := err.(*exec.ExitError); ok {
+ // the user command inside the unshare env has failed
+ // we set the exit code, do not return the error to the user
+ // otherwise "exit status X" will be printed
+ registry.SetExitCode(exitError.ExitCode())
+ return nil
+ }
+ // cmd.Run() can return fs.ErrNotExist, fs.ErrPermission or exec.ErrNotFound
+ // follow podman run/exec standard with the exit codes
+ if errors.Is(err, os.ErrNotExist) || errors.Is(err, exec.ErrNotFound) {
+ registry.SetExitCode(127)
+ } else if errors.Is(err, os.ErrPermission) {
+ registry.SetExitCode(126)
+ }
+ return err
+ }
+ return nil
}