Fix status when function/block evaluation is cancelled

It looks like the last status already contains the signal that cancelled
execution.

Also make `fish -c something` always return the last exit status of
"something", instead of hardcoded 127 if exited or signalled.

Fixes #6444
This commit is contained in:
Johannes Altmanninger 2019-12-23 13:49:40 +01:00
parent 8ca936aea6
commit 9f48fc6285
3 changed files with 17 additions and 12 deletions

View File

@ -737,10 +737,8 @@ static proc_performer_t get_performer_for_process(process_t *p, const job_t *job
switch (res) { switch (res) {
case eval_result_t::ok: case eval_result_t::ok:
case eval_result_t::error: case eval_result_t::error:
return proc_status_t::from_exit_code(parser.get_last_status());
case eval_result_t::cancelled: case eval_result_t::cancelled:
// TODO: we should reflect the actual signal which was received. return proc_status_t::from_exit_code(parser.get_last_status());
return proc_status_t::from_signal(SIGINT);
case eval_result_t::control_flow: case eval_result_t::control_flow:
default: default:
DIE("eval_result_t::control_flow should not be returned from eval_node"); DIE("eval_result_t::control_flow should not be returned from eval_node");
@ -768,11 +766,8 @@ static proc_performer_t get_performer_for_process(process_t *p, const job_t *job
? EXIT_SUCCESS ? EXIT_SUCCESS
: parser.get_last_status()); : parser.get_last_status());
case eval_result_t::error: case eval_result_t::error:
return proc_status_t::from_exit_code(parser.get_last_status());
case eval_result_t::cancelled: case eval_result_t::cancelled:
// TODO: we should reflect the actual signal which was received. return proc_status_t::from_exit_code(parser.get_last_status());
return proc_status_t::from_signal(SIGINT);
default: default:
case eval_result_t::control_flow: case eval_result_t::control_flow:
DIE("eval_result_t::control_flow should not be returned from eval_node"); DIE("eval_result_t::control_flow should not be returned from eval_node");

View File

@ -249,16 +249,14 @@ static int read_init(const struct config_paths_t &paths) {
} }
int run_command_list(std::vector<std::string> *cmds, const io_chain_t &io) { int run_command_list(std::vector<std::string> *cmds, const io_chain_t &io) {
int res = 1;
parser_t &parser = parser_t::principal_parser(); parser_t &parser = parser_t::principal_parser();
for (const auto &cmd : *cmds) { for (const auto &cmd : *cmds) {
const wcstring cmd_wcs = str2wcstring(cmd); const wcstring cmd_wcs = str2wcstring(cmd);
eval_result_t eval_res = parser.eval(cmd_wcs, io); parser.eval(cmd_wcs, io);
res = (eval_res == eval_result_t::ok ? 0 : 1);
} }
return res; return 0;
} }
/// Parse the argument list, return the index of the first non-flag arguments. /// Parse the argument list, return the index of the first non-flag arguments.

View File

@ -1,4 +1,16 @@
# RUN: %fish %s # RUN: %fish -C 'set -l fish %fish' %s
$fish -c 'function main; exit 4; true; end; main'; echo $status
#CHECK: 4
$fish -c 'begin; exit 5; true; end'; echo $status
#CHECK: 5
$fish -c 'kill -SIGHUP %self'; echo $status
#CHECK: 129
$fish -c 'function main; kill -SIGTERM %self; true; end; main'; echo $status
#CHECK: 143
function alarm --on-signal ALRM function alarm --on-signal ALRM
echo ALRM received echo ALRM received