From f212518d3ed8b02253be393e1dbd93a32d7e3439 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 12 Oct 2018 23:58:14 -0700 Subject: [PATCH] Allow SIGINT in non-interactive mode Prior to this fix, fish would swallow SIGINT in non-interactive mode. This meant that scripts could only be Ctrl-C'd if fish was executing an external command. Unblock SIGINT in non-interactive mode. Fixes #5253 --- src/signal.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/signal.cpp b/src/signal.cpp index 90d008abd..47c5bf410 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -12,6 +12,7 @@ #include "common.h" #include "event.h" #include "fallback.h" // IWYU pragma: keep +#include "parser.h" #include "proc.h" #include "reader.h" #include "wutil.h" // IWYU pragma: keep @@ -233,6 +234,12 @@ static void handle_int(int sig, siginfo_t *info, void *context) { default_handler(sig, info, context); } +/// Non-interactive ^C handler. +static void handle_int_notinteractive(int sig, siginfo_t *info, void *context) { + parser_t::skip_all_blocks(); + default_handler(sig, info, context); +} + /// sigchld handler. Does notification and calls the handler in proc.c. static void handle_chld(int sig, siginfo_t *info, void *context) { job_handle_signal(sig, info, context); @@ -317,11 +324,12 @@ static void set_non_interactive_handlers() { act.sa_flags = 0; sigemptyset(&act.sa_mask); - // Non-interactive. Ignore interrupt, check exit status of processes to determine result - // instead. act.sa_handler = SIG_IGN; - sigaction(SIGINT, &act, 0); sigaction(SIGQUIT, &act, 0); + + act.sa_sigaction = &handle_int_notinteractive; + act.sa_flags = SA_SIGINFO; + sigaction(SIGINT, &act, NULL); } /// Sets up appropriate signal handlers.