mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 04:41:14 -03:00
Rework how signals trigger cancellation
When fish receives a "cancellation inducing" signal (SIGINT in particular)
it has to unwind execution - for example while loops or whatever else that
is executing. There are two ways this may come about:
1. The fish process received the signal
2. A child process received the signal
An example of the second case is:
some_command | some_function
Here `some_command` is the tty owner and so will receive control-C, but
then fish has to cancel function execution.
Prior to this change, these were handled uniformly: both would just set a
cancellation signal inside the parser. However in the future we will have
multiple parsers and it may not be obvious which one to set the flag in.
So instead distinguish these cases: if a process receives SIGINT we mark
the signal in its job group, and if fish receives it we set a global
variable.
This commit is contained in:
12
src/parser.h
12
src/parser.h
@@ -220,10 +220,7 @@ struct eval_res_t {
|
||||
|
||||
class parser_t : public std::enable_shared_from_this<parser_t> {
|
||||
friend class parse_execution_context_t;
|
||||
|
||||
private:
|
||||
/// If not zero, the signal triggering cancellation.
|
||||
volatile sig_atomic_t cancellation_signal = 0;
|
||||
/// The current execution context.
|
||||
std::unique_ptr<parse_execution_context_t> execution_context;
|
||||
/// The jobs associated with this parser.
|
||||
@@ -269,12 +266,6 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
|
||||
/// Get the "principal" parser, whatever that is.
|
||||
static parser_t &principal_parser();
|
||||
|
||||
/// Indicates that we should stop execution due to the given signal.
|
||||
static void cancel_requested(int sig);
|
||||
|
||||
/// Clear any cancel.
|
||||
void clear_cancel() { cancellation_signal = 0; }
|
||||
|
||||
/// Global event blocks.
|
||||
event_blockage_list_t global_event_blocks;
|
||||
|
||||
@@ -386,9 +377,6 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
|
||||
void get_backtrace(const wcstring &src, const parse_error_list_t &errors,
|
||||
wcstring &output) const;
|
||||
|
||||
/// \return the signal triggering cancellation, or 0 if none.
|
||||
int get_cancel_signal() const { return cancellation_signal; }
|
||||
|
||||
/// Output profiling data to the given filename.
|
||||
void emit_profiling(const char *path) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user