Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

podman unshare keep exit code #11513

Merged
merged 1 commit into from
Sep 11, 2021
Merged

Conversation

Luap99
Copy link
Member

@Luap99 Luap99 commented Sep 9, 2021

In case the command inside the podman unshare env failed podman unshare
always exits with 125 and prints Error: exit status 125. This is a
bad user experience and makes it difficult to use in scripts which could
expect certain exit codes.
This commit makes sure podman unshare uses the same exit code as the
command and does not print the useless exit status X message.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 9, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 9, 2021
@rhatdan
Copy link
Member

rhatdan commented Sep 9, 2021

This is how it should handle these errors: (The same way podman run and podman exec do.)

podman unshare --bogus
125
podman unshare /usr/bin/bogus
127
podman unshare /etc
126
podman unshare bash -c "exit 52"
52

@@ -47,8 +47,7 @@ var _ = Describe("Podman unshare", func() {
session := podmanTest.Podman([]string{"unshare", "readlink", "/proc/self/ns/user"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
ok, _ := session.GrepString(userNS)
Expect(ok).To(BeFalse())
Expect(session.OutputToString()).To(ContainSubstring(userNS))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this should be Not()?

@Luap99
Copy link
Member Author

Luap99 commented Sep 10, 2021

@rhatdan Thanks, I didn't know ENOENT and EPERM get special exit codes. This is how it looks now:

$ bin/podman unshare --bogus
Error: unknown flag: --bogus
125
$ bin/podman unshare /usr/bin/bogus
Error: fork/exec /usr/bin/bogus: no such file or directory
127
$ bin/podman unshare bogus
Error: exec: "bogus": executable file not found in $PATH
127
$ bin/podman unshare /etc
Error: fork/exec /etc: permission denied
126
$ bin/podman unshare bash -c "exit 52"
52

@Luap99 Luap99 force-pushed the unshare branch 2 times, most recently from 7c85305 to fd318f5 Compare September 10, 2021 08:06
@Luap99
Copy link
Member Author

Luap99 commented Sep 10, 2021

Test failures are because of #11521

@mheon
Copy link
Member

mheon commented Sep 10, 2021

Good to rebase, now that that is fixed?

@mheon
Copy link
Member

mheon commented Sep 10, 2021

LGTM

In case the command inside the podman unshare env failed podman unshare
always exits with 125 and prints `Error: exit status 125`. This is a
bad user experience and makes it difficult to use in scripts which could
expect certain exit codes.
This commit makes sure podman unshare uses the same exit code as the
command and does not print the useless `exit status X` message.

Also to match podman run/exec it should return 126 for EPERM
and 127 for ENOENT.

Signed-off-by: Paul Holzinger <[email protected]>
@rhatdan
Copy link
Member

rhatdan commented Sep 10, 2021

/lgtm
/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 10, 2021
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 10, 2021
@TomSweeneyRedHat
Copy link
Member

LGTM
/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 11, 2021
@openshift-merge-robot openshift-merge-robot merged commit ec30370 into containers:main Sep 11, 2021
@Luap99 Luap99 deleted the unshare branch September 11, 2021 21:34
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants