Rationalize exit codes for failed execs

This cleans up some exit code processing. Previously a failed exec
would produce exit code 125 unconditionally, while a failed posix_spawn
would produce exit code 1 (!).

With this change, fish reports exit code 126 for not-executable, and 127
for file-not-found. This matches bash.
This commit is contained in:
ridiculousfish
2021-03-27 21:21:29 -07:00
parent 694e112a9b
commit b44f40547b
5 changed files with 46 additions and 16 deletions

View File

@@ -11,11 +11,13 @@ chmod a+x file
function runfile
# Run our file twice, printing status.
# Arguments are passed to exercise the re-execve code paths; they have no other effect.
set -g fish_use_posix_spawn 0
true # clear status
set -g fish_use_posix_spawn 1
./file arg1 arg2 arg3
echo $status
set -g fish_use_posix_spawn 1
true # clear status
set -g fish_use_posix_spawn 0
./file arg1 arg2 arg3 arg4 arg5
echo $status
end
@@ -42,12 +44,12 @@ set -g fish_use_posix_spawn 1
./file.fish
echo $status
rm file.fish
#CHECK: 125
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}
#CHECK: 125
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}
@@ -63,12 +65,12 @@ runfile
# Doesn't meet our heuristic as there is no newline.
echo -n -e 'true\x00' >file
runfile
#CHECK: 125
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}
#CHECK: 125
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}
@@ -76,12 +78,12 @@ runfile
# Doesn't meet our heuristic as there is no lowercase before newline.
echo -n -e 'NOPE\n\x00' >file
runfile
#CHECK: 125
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}
#CHECK: 125
#CHECK: 126
#CHECKERR: Failed {{.*}}
#CHECKERR: exec: {{.*}}
#CHECKERR: {{.*}}