diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-05-30 15:15:57 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-05-30 15:55:20 +0200 |
commit | 0e58636c3a599bb3d7d5ef06ab2773befe8a0150 (patch) | |
tree | 42435d07701510a6c7dd8bd4bbcbb5720f52b4ae /cmd/podman/system | |
parent | a6f8cad545fa3242a2778c9a0d25da4da0a51ce2 (diff) | |
download | podman-0e58636c3a599bb3d7d5ef06ab2773befe8a0150.tar.gz podman-0e58636c3a599bb3d7d5ef06ab2773befe8a0150.tar.bz2 podman-0e58636c3a599bb3d7d5ef06ab2773befe8a0150.zip |
podman machine ssh: set correct exit code
Forward the ssh exit code to the podman caller. This is useful for
scripts. Use the same logic as podman unshare.
Fixes #14401
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'cmd/podman/system')
-rw-r--r-- | cmd/podman/system/unshare.go | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/cmd/podman/system/unshare.go b/cmd/podman/system/unshare.go index 0ae5b81ad..1ed08eac3 100644 --- a/cmd/podman/system/unshare.go +++ b/cmd/podman/system/unshare.go @@ -2,10 +2,10 @@ package system import ( "os" - "os/exec" "github.com/containers/common/pkg/completion" "github.com/containers/podman/v4/cmd/podman/registry" + "github.com/containers/podman/v4/cmd/podman/utils" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/rootless" "github.com/pkg/errors" @@ -60,22 +60,5 @@ func unshare(cmd *cobra.Command, args []string) error { } 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 + return utils.HandleOSExecError(err) } |