Skip to content

Commit 3ab0d82

Browse files
Merge pull request #25350 from giuseppe/unify-error-codes
oci: report empty exec path as ENOENT
2 parents aafc373 + 4695564 commit 3ab0d82

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

libpod/oci_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func getOCIRuntimeError(name, runtimeMsg string) error {
152152
}
153153
return fmt.Errorf("%s: %s: %w", name, strings.Trim(errStr, "\n"), define.ErrOCIRuntimePermissionDenied)
154154
}
155-
if match := regexp.MustCompile("(?i).*executable file not found in.*|.*no such file or directory.*").FindString(runtimeMsg); match != "" {
155+
if match := regexp.MustCompile("(?i).*executable file not found in.*|.*no such file or directory.*|.*open executable.*").FindString(runtimeMsg); match != "" {
156156
errStr := match
157157
if includeFullOutput {
158158
errStr = runtimeMsg

test/e2e/exec_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,17 +400,14 @@ var _ = Describe("Podman exec", func() {
400400
setup.WaitWithDefaultTimeout()
401401
Expect(setup).Should(ExitCleanly())
402402

403-
expect := "chdir to `/missing`: No such file or directory"
404-
if podmanTest.OCIRuntime == "runc" {
405-
expect = "chdir to cwd"
406-
}
403+
expect := ".*(chdir to cwd|chdir to `/missing`: No such file or directory).*"
407404
session := podmanTest.Podman([]string{"exec", "--workdir", "/missing", "test1", "pwd"})
408405
session.WaitWithDefaultTimeout()
409-
Expect(session).To(ExitWithError(127, expect))
406+
Expect(session).To(ExitWithErrorRegex(127, expect))
410407

411408
session = podmanTest.Podman([]string{"exec", "-w", "/missing", "test1", "pwd"})
412409
session.WaitWithDefaultTimeout()
413-
Expect(session).To(ExitWithError(127, expect))
410+
Expect(session).To(ExitWithErrorRegex(127, expect))
414411
})
415412

416413
It("podman exec cannot be invoked", func() {

test/e2e/run_entrypoint_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ CMD []
1818
podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
1919
session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"})
2020
session.WaitWithDefaultTimeout()
21-
Expect(session).Should(ExitWithErrorRegex(126, ".*(open executable|executable path is empty): Operation not permitted: OCI permission denied.*"))
21+
if session.ExitCode() == 126 {
22+
// special case for crun <= 1.20, remove once a new version is out
23+
Expect(session).Should(ExitWithError(126, "open executable: Operation not permitted: OCI permission denied"))
24+
return
25+
}
26+
Expect(session).Should(ExitWithErrorRegex(127, ".*(executable file not found in \\$PATH|cannot find `` in \\$PATH).*: OCI runtime attempted to invoke a command that was not found.*"))
2227
})
2328

2429
It("podman run entrypoint == [\"\"]", func() {

test/e2e/run_exit_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ var _ = Describe("Podman run exit", func() {
2222
It("podman run exit ExecErrorCodeCannotInvoke", func() {
2323
result := podmanTest.Podman([]string{"run", ALPINE, "/etc"})
2424
result.WaitWithDefaultTimeout()
25-
Expect(result).Should(ExitWithErrorRegex(define.ExecErrorCodeCannotInvoke, ".*(open executable|the path `/etc` is not a regular file): Operation not permitted: OCI permission denied.*"))
25+
expected := ".*(exec: \"/etc\": is a directory|(open executable|the path `/etc` is not a regular file): Operation not permitted: OCI permission denied).*"
26+
Expect(result).Should(ExitWithErrorRegex(define.ExecErrorCodeCannotInvoke, expected))
2627
})
2728

2829
It("podman run exit ExecErrorCodeNotFound", func() {
2930
result := podmanTest.Podman([]string{"run", ALPINE, "foobar"})
3031
result.WaitWithDefaultTimeout()
31-
Expect(result).Should(ExitWithError(define.ExecErrorCodeNotFound, "executable file `foobar` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found"))
32+
expected := ".*(executable file not found in \\$PATH|executable file `foobar` not found in \\$PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found).*"
33+
Expect(result).Should(ExitWithErrorRegex(define.ExecErrorCodeNotFound, expected))
3234
})
3335

3436
It("podman run exit 0", func() {

test/system/030-run.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ search | $IMAGE |
16571657
# runc and crun emit different diagnostics
16581658
runtime=$(podman_runtime)
16591659
case "$runtime" in
1660-
crun) expect='\(executable file `` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found\|executable path is empty\)' ;;
1660+
crun) expect='\(executable file `` not found in $PATH\|cannot find `` in $PATH\): No such file or directory: OCI runtime attempted to invoke a command that was not found' ;;
16611661
runc) expect='runc: runc create failed: unable to start container process: exec: "": executable file not found in $PATH: OCI runtime attempted to invoke a command that was not found' ;;
16621662
*) skip "Unknown runtime '$runtime'" ;;
16631663
esac

0 commit comments

Comments
 (0)