Log original exit code used when a builtin returns a negative exit code

Port of b91723dab6
This commit is contained in:
Fabian Boehm 2024-01-05 16:52:18 +01:00
parent 4286b049ca
commit 06de374ffd
2 changed files with 8 additions and 8 deletions

View file

@ -456,16 +456,16 @@ pub fn builtin_run(parser: &Parser, argv: &mut [&wstr], streams: &mut IoStreams)
// would assert() out, which is a terrible failure mode
// So instead, what we do is we get a positive code,
// and we avoid 0.
code = ((256 + code) % 256).abs();
if code == 0 {
code = 255;
}
FLOGF!(
warning,
"builtin %ls returned invalid exit code %d",
argv[0],
code
);
code = ((256 + code) % 256).abs();
if code == 0 {
code = 255;
}
}
ProcStatus::from_exit_code(code)

View file

@ -26,22 +26,22 @@ echo $status
# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~^
$fish -c 'exit -5'
# CHECKERR: warning: builtin exit returned invalid exit code 251
# CHECKERR: warning: builtin exit returned invalid exit code -5
echo $status
# CHECK: 251
$fish -c 'exit -1'
# CHECKERR: warning: builtin exit returned invalid exit code 255
# CHECKERR: warning: builtin exit returned invalid exit code -1
echo $status
# CHECK: 255
# (we avoid 0, so this is turned into 255 again)
$fish -c 'exit -256'
# CHECKERR: warning: builtin exit returned invalid exit code 255
# CHECKERR: warning: builtin exit returned invalid exit code -256
echo $status
# CHECK: 255
$fish -c 'exit -512'
# CHECKERR: warning: builtin exit returned invalid exit code 255
# CHECKERR: warning: builtin exit returned invalid exit code -512
echo $status
# CHECK: 255