Skip to content

Commit

Permalink
Allow SIGINT in non-interactive mode
Browse files Browse the repository at this point in the history
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 fish-shell#5253
  • Loading branch information
ridiculousfish committed Nov 23, 2018
1 parent 900943e commit f226682
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/signal.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f226682

Please sign in to comment.