mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-16 23:12:45 +08:00
Pass $status to process-exit event handlers in all cases
Previously, an event handler would receive -1 if the process exited due to a signal. Instead pass the same value as $status.
This commit is contained in:
parent
82fd8fe9fb
commit
962b0f8b90
|
@ -26,6 +26,7 @@ Scripting improvements
|
||||||
- Better errors when a command in a command substitution wasn't found or is not allowed.
|
- Better errors when a command in a command substitution wasn't found or is not allowed.
|
||||||
- ``fish_indent`` allows to write inline variable assignments on multiple lines (ending in a backslash), instead of joining them into one line (:issue:`7955`).
|
- ``fish_indent`` allows to write inline variable assignments on multiple lines (ending in a backslash), instead of joining them into one line (:issue:`7955`).
|
||||||
- fish gained a ``--no-config`` option to disable reading config.fish. This applies both to the user's and the admin's config.fish (typically in /etc/fish/config.fish) and also sets $fish_function_path to just the functions shipped with fish and disables universal variables and history. (:issue:`7921`, :issue:`1256`).
|
- fish gained a ``--no-config`` option to disable reading config.fish. This applies both to the user's and the admin's config.fish (typically in /etc/fish/config.fish) and also sets $fish_function_path to just the functions shipped with fish and disables universal variables and history. (:issue:`7921`, :issue:`1256`).
|
||||||
|
- ``process-exit`` event handlers now receive the same value as ``$status`` in all cases, instead of receiving -1 when the exit was due to a signal.
|
||||||
|
|
||||||
Interactive improvements
|
Interactive improvements
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
|
@ -135,12 +135,10 @@ static void print_ignored_signals() {
|
||||||
|
|
||||||
static void print_stop_cont() {
|
static void print_stop_cont() {
|
||||||
signal(SIGTSTP, [](int) {
|
signal(SIGTSTP, [](int) {
|
||||||
auto __attribute__((unused)) _ = write(STDOUT_FILENO, "SIGTSTP\n", strlen("SIGTSTP\n"));
|
(void)write(STDOUT_FILENO, "SIGTSTP\n", strlen("SIGTSTP\n"));
|
||||||
kill(getpid(), SIGSTOP);
|
kill(getpid(), SIGSTOP);
|
||||||
});
|
});
|
||||||
signal(SIGCONT, [](int) {
|
signal(SIGCONT, [](int) { (void)write(STDOUT_FILENO, "SIGCONT\n", strlen("SIGCONT\n")); });
|
||||||
auto __attribute__((unused)) _ = write(STDOUT_FILENO, "SIGCONT\n", strlen("SIGCONT\n"));
|
|
||||||
});
|
|
||||||
char buff[1];
|
char buff[1];
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (read(STDIN_FILENO, buff, sizeof buff) >= 0) {
|
if (read(STDIN_FILENO, buff, sizeof buff) >= 0) {
|
||||||
|
@ -149,6 +147,11 @@ static void print_stop_cont() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void sigkill_self() {
|
||||||
|
kill(getpid(), SIGKILL);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
static void show_help();
|
static void show_help();
|
||||||
|
|
||||||
/// A thing that fish_test_helper can do.
|
/// A thing that fish_test_helper can do.
|
||||||
|
@ -180,6 +183,7 @@ static fth_command_t s_commands[] = {
|
||||||
{"print_ignored_signals", print_ignored_signals,
|
{"print_ignored_signals", print_ignored_signals,
|
||||||
"Print to stdout the name(s) of ignored signals"},
|
"Print to stdout the name(s) of ignored signals"},
|
||||||
{"print_stop_cont", print_stop_cont, "Print when we get SIGTSTP and SIGCONT, exiting on input"},
|
{"print_stop_cont", print_stop_cont, "Print when we get SIGTSTP and SIGCONT, exiting on input"},
|
||||||
|
{"sigkill_self", sigkill_self, "Send SIGKILL to self"},
|
||||||
{"help", show_help, "Print list of fish_test_helper commands"},
|
{"help", show_help, "Print list of fish_test_helper commands"},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -554,8 +554,8 @@ static bool try_clean_process_in_job(parser_t &parser, process_t *p, job_t *j,
|
||||||
|
|
||||||
// Add an exit event if the process did not come from a job handler.
|
// Add an exit event if the process did not come from a job handler.
|
||||||
if (!j->from_event_handler()) {
|
if (!j->from_event_handler()) {
|
||||||
exit_events->push_back(proc_create_event(L"PROCESS_EXIT", event_type_t::exit, p->pid,
|
exit_events->push_back(
|
||||||
s.normal_exited() ? s.exit_code() : -1));
|
proc_create_event(L"PROCESS_EXIT", event_type_t::exit, p->pid, s.status_value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore SIGPIPE. We issue it ourselves to the pipe writer when the pipe reader dies.
|
// Ignore SIGPIPE. We issue it ourselves to the pipe writer when the pipe reader dies.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# RUN: %fish -C 'set -l fish %fish' %s
|
# RUN: env fish_test_helper=%fish_test_helper %fish -C 'set -l fish %fish' %s
|
||||||
|
|
||||||
$fish -c 'function main; exit 4; true; end; main'
|
$fish -c 'function main; exit 4; true; end; main'
|
||||||
echo $status
|
echo $status
|
||||||
|
@ -47,13 +47,19 @@ command false | command true
|
||||||
# CHECK: PROCESS_EXIT 0
|
# CHECK: PROCESS_EXIT 0
|
||||||
# CHECK: JOB_EXIT 0
|
# CHECK: JOB_EXIT 0
|
||||||
|
|
||||||
|
# Signals are reported correctly.
|
||||||
|
# SIGKILL $status is 128 + 9 = 137
|
||||||
|
$fish_test_helper sigkill_self
|
||||||
|
# CHECK: PROCESS_EXIT 137
|
||||||
|
# CHECK: JOB_EXIT 0
|
||||||
|
|
||||||
function test_blocks
|
function test_blocks
|
||||||
block -l
|
block -l
|
||||||
command echo "This is the process whose exit event shuld be blocked"
|
command echo "This is the process whose exit event should be blocked"
|
||||||
echo "This should come before the event handler"
|
echo "This should come before the event handler"
|
||||||
end
|
end
|
||||||
test_blocks
|
test_blocks
|
||||||
# CHECK: This is the process whose exit event shuld be blocked
|
# CHECK: This is the process whose exit event should be blocked
|
||||||
# CHECK: This should come before the event handler
|
# CHECK: This should come before the event handler
|
||||||
|
|
||||||
echo "Now event handler should have run"
|
echo "Now event handler should have run"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user