diff --git a/src/nano.c b/src/nano.c index 89c57744..2466108f 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1055,8 +1055,6 @@ bool scoop_stdin(void) { struct sigaction oldaction, newaction; /* Original and temporary handlers for SIGINT. */ - bool setup_failed = FALSE; - /* Whether setting up the temporary SIGINT handler failed. */ FILE *stream; int thetty; @@ -1074,18 +1072,6 @@ bool scoop_stdin(void) enable_signals(); #endif - /* Set things up so that SIGINT will cancel the reading. */ - if (sigaction(SIGINT, NULL, &newaction) == -1) { - setup_failed = TRUE; - perror("sigaction"); - } else { - newaction.sa_handler = make_a_note; - if (sigaction(SIGINT, &newaction, &oldaction) == -1) { - setup_failed = TRUE; - perror("sigaction"); - } - } - /* Open standard input. */ stream = fopen("/dev/stdin", "rb"); if (stream == NULL) { @@ -1097,6 +1083,11 @@ bool scoop_stdin(void) return FALSE; } + /* Set up a signal handler so that ^C will stop the reading. */ + newaction.sa_handler = make_a_note; + newaction.sa_flags = 0; + sigaction(SIGINT, &newaction, &oldaction); + /* Read the input into a new buffer. */ make_new_buffer(); read_file(stream, 0, "stdin", TRUE); @@ -1116,10 +1107,8 @@ bool scoop_stdin(void) if (!input_was_aborted) tcgetattr(0, &oldterm); - /* If it was changed, restore the handler for SIGINT. */ - if (!setup_failed && sigaction(SIGINT, &oldaction, NULL) == -1) - perror("sigaction"); - + /* Restore the original ^C handler, the terminal setup, and curses mode. */ + sigaction(SIGINT, &oldaction, NULL); terminal_init(); doupdate(); diff --git a/src/text.c b/src/text.c index 262ecde9..66b1cff3 100644 --- a/src/text.c +++ b/src/text.c @@ -951,8 +951,6 @@ bool execute_command(const char *command) const char *shellenv; struct sigaction oldaction, newaction; /* Original and temporary handlers for SIGINT. */ - bool setup_failed = FALSE; - /* Whether setting up the temporary SIGINT handler failed. */ /* Create a pipe to read the command's output from, and, if needed, * a pipe to feed the command's input through. */ @@ -1046,17 +1044,10 @@ bool execute_command(const char *command) * SIGINT when Ctrl-C is pressed. */ enable_signals(); - /* Set things up so that Ctrl-C will terminate the forked process. */ - if (sigaction(SIGINT, NULL, &newaction) == -1) { - setup_failed = TRUE; - nperror("sigaction"); - } else { - newaction.sa_handler = cancel_the_command; - if (sigaction(SIGINT, &newaction, &oldaction) == -1) { - setup_failed = TRUE; - nperror("sigaction"); - } - } + /* Set up a signal handler so that ^C will terminate the forked process. */ + newaction.sa_handler = cancel_the_command; + newaction.sa_flags = 0; + sigaction(SIGINT, &newaction, &oldaction); stream = fdopen(from_fd[0], "rb"); if (stream == NULL) @@ -1075,9 +1066,8 @@ bool execute_command(const char *command) if (should_pipe && (wait(NULL) == -1)) nperror("wait"); - /* If it was changed, restore the handler for SIGINT. */ - if (!setup_failed && sigaction(SIGINT, &oldaction, NULL) == -1) - nperror("sigaction"); + /* Restore the original handler for SIGINT. */ + sigaction(SIGINT, &oldaction, NULL); /* Restore the terminal to its desired state, and disable * interpretation of the special control keys again. */