Correctly propagate signals from cancelled jobs into parse_execution_context

This concerns code like the following:

    while true ; sleep 100; end

Here 'while' is a "simple block execution" and does not create a new job,
or get a pgid. Each 'sleep' however is an external command execution, and
is treated as a distinct job. (bash is the same way). So `while` and
`sleep` are always in different job groups.

The problem comes about if 'sleep' is cancelled through SIGINT or SIGQUIT.
Prior to 2a4c545b21, if *any* process got a SIGINT or SIGQUIT, then fish
would mark a global "stop executing" variable. This obviously prevents
background execution of fish functions.

In 2a4c545b21, this was changed so only the job's group gets marked as
cancelled. However in the case of one job group spawning another, we
weren't propagating the signal.

This adds a signal to parse_execution_context which the parser checks after
execution. It's not ideal since now we have three different places where
signals can be recorded. However it fixes this regression which is too
important to leave unfixed for long.

Fixes #7259
This commit is contained in:
ridiculousfish
2020-08-12 21:35:37 -07:00
parent 1cf835e6e9
commit 82fed6fc2f
4 changed files with 51 additions and 5 deletions

View File

@@ -226,12 +226,9 @@ process_type_t parse_execution_context_t::process_type_for_command(
}
maybe_t<end_execution_reason_t> parse_execution_context_t::check_end_execution() const {
if (ctx.check_cancel() || shell_is_exiting()) {
if (this->cancel_signal || ctx.check_cancel() || shell_is_exiting()) {
return end_execution_reason_t::cancelled;
}
if (nullptr == parser) {
return none();
}
const auto &ld = parser->libdata();
if (ld.returning) {
return end_execution_reason_t::control_flow;
@@ -1343,6 +1340,14 @@ end_execution_reason_t parse_execution_context_t::run_1_job(const ast::job_t &jo
remove_job(*this->parser, job.get());
}
// Check if the job's group got a SIGINT or SIGQUIT.
// If so we need to mark that ourselves so as to cancel the rest of the execution.
// See #7259.
int cancel_sig = job->group->get_cancel_signal();
if (cancel_sig == SIGINT || cancel_sig == SIGQUIT) {
this->cancel_signal = cancel_sig;
}
// Update universal variables on external conmmands.
// TODO: justify this, why not on every command?
if (job_contained_external_command) {