From 9f48fc6285c265daa42c875b39185969d1f702e7 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 23 Dec 2019 13:49:40 +0100 Subject: [PATCH] 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 --- src/exec.cpp | 9 ++------- src/fish.cpp | 6 ++---- tests/checks/signal.fish | 14 +++++++++++++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/exec.cpp b/src/exec.cpp index c5d4a414e..02b510bad 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -737,10 +737,8 @@ static proc_performer_t get_performer_for_process(process_t *p, const job_t *job switch (res) { case eval_result_t::ok: case eval_result_t::error: - return proc_status_t::from_exit_code(parser.get_last_status()); case eval_result_t::cancelled: - // TODO: we should reflect the actual signal which was received. - return proc_status_t::from_signal(SIGINT); + return proc_status_t::from_exit_code(parser.get_last_status()); case eval_result_t::control_flow: default: 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 : parser.get_last_status()); case eval_result_t::error: - return proc_status_t::from_exit_code(parser.get_last_status()); - case eval_result_t::cancelled: - // TODO: we should reflect the actual signal which was received. - return proc_status_t::from_signal(SIGINT); + return proc_status_t::from_exit_code(parser.get_last_status()); default: case eval_result_t::control_flow: DIE("eval_result_t::control_flow should not be returned from eval_node"); diff --git a/src/fish.cpp b/src/fish.cpp index 8b013c52e..f9d7e2f38 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -249,16 +249,14 @@ static int read_init(const struct config_paths_t &paths) { } int run_command_list(std::vector *cmds, const io_chain_t &io) { - int res = 1; parser_t &parser = parser_t::principal_parser(); for (const auto &cmd : *cmds) { const wcstring cmd_wcs = str2wcstring(cmd); - eval_result_t eval_res = parser.eval(cmd_wcs, io); - res = (eval_res == eval_result_t::ok ? 0 : 1); + parser.eval(cmd_wcs, io); } - return res; + return 0; } /// Parse the argument list, return the index of the first non-flag arguments. diff --git a/tests/checks/signal.fish b/tests/checks/signal.fish index 00bd45ac7..504fff97d 100644 --- a/tests/checks/signal.fish +++ b/tests/checks/signal.fish @@ -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 echo ALRM received