mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
Log original exit code used when a builtin returns a negative exit code
This commit is contained in:
parent
0e4d088b11
commit
b91723dab6
@ -475,13 +475,13 @@ proc_status_t builtin_run(parser_t &parser, const wcstring_list_t &argv, io_stre
|
|||||||
return proc_status_t::empty();
|
return proc_status_t::empty();
|
||||||
}
|
}
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
|
FLOGF(warning, "builtin %ls returned invalid exit code %d", cmdname.c_str(), code);
|
||||||
// If the code is below 0, constructing a proc_status_t
|
// If the code is below 0, constructing a proc_status_t
|
||||||
// would assert() out, which is a terrible failure mode
|
// would assert() out, which is a terrible failure mode
|
||||||
// So instead, what we do is we get a positive code,
|
// So instead, what we do is we get a positive code,
|
||||||
// and we avoid 0.
|
// and we avoid 0.
|
||||||
code = abs((256 + code) % 256);
|
code = abs((256 + code) % 256);
|
||||||
if (code == 0) code = 255;
|
if (code == 0) code = 255;
|
||||||
FLOGF(warning, "builtin %ls returned invalid exit code %d", cmdname.c_str(), code);
|
|
||||||
}
|
}
|
||||||
return proc_status_t::from_exit_code(code);
|
return proc_status_t::from_exit_code(code);
|
||||||
}
|
}
|
||||||
|
@ -26,22 +26,22 @@ echo $status
|
|||||||
# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||||
|
|
||||||
$fish -c 'exit -5'
|
$fish -c 'exit -5'
|
||||||
# CHECKERR: warning: builtin exit returned invalid exit code 251
|
# CHECKERR: warning: builtin exit returned invalid exit code -5
|
||||||
echo $status
|
echo $status
|
||||||
# CHECK: 251
|
# CHECK: 251
|
||||||
|
|
||||||
$fish -c 'exit -1'
|
$fish -c 'exit -1'
|
||||||
# CHECKERR: warning: builtin exit returned invalid exit code 255
|
# CHECKERR: warning: builtin exit returned invalid exit code -1
|
||||||
echo $status
|
echo $status
|
||||||
# CHECK: 255
|
# CHECK: 255
|
||||||
|
|
||||||
# (we avoid 0, so this is turned into 255 again)
|
# (we avoid 0, so this is turned into 255 again)
|
||||||
$fish -c 'exit -256'
|
$fish -c 'exit -256'
|
||||||
# CHECKERR: warning: builtin exit returned invalid exit code 255
|
# CHECKERR: warning: builtin exit returned invalid exit code -256
|
||||||
echo $status
|
echo $status
|
||||||
# CHECK: 255
|
# CHECK: 255
|
||||||
|
|
||||||
$fish -c 'exit -512'
|
$fish -c 'exit -512'
|
||||||
# CHECKERR: warning: builtin exit returned invalid exit code 255
|
# CHECKERR: warning: builtin exit returned invalid exit code -512
|
||||||
echo $status
|
echo $status
|
||||||
# CHECK: 255
|
# CHECK: 255
|
||||||
|
Loading…
x
Reference in New Issue
Block a user