From 760264169e554e3e2ae8312f8f192d1ad95c7854 Mon Sep 17 00:00:00 2001 From: jilles Date: Sun, 22 Nov 2009 18:23:30 +0000 Subject: Fix various things about SIGINT handling: * exception handlers are now run with interrupts disabled, which avoids many race conditions * fix some cases where SIGINT only aborts one command and continues the script, in particular if a SIGINT causes an EINTR error which trumped the interrupt. Example: sh -c 'echo < /some/fifo; echo This should not be printed' The fifo should not have writers. When pressing ctrl+c to abort the open, the shell used to continue with the next command. Example: sh -c '/bin/echo < /some/fifo; echo This should not be printed' Similar. Note, however, that this particular case did not and does not work in interactive mode with job control enabled. --- bin/sh/error.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'bin/sh/error.c') diff --git a/bin/sh/error.c b/bin/sh/error.c index 0c981a3..72061b8 100644 --- a/bin/sh/error.c +++ b/bin/sh/error.c @@ -73,11 +73,15 @@ static void exverror(int, const char *, va_list) __printf0like(2, 0); * Called to raise an exception. Since C doesn't include exceptions, we * just do a longjmp to the exception handler. The type of exception is * stored in the global variable "exception". + * + * Interrupts are disabled; they should be reenabled when the exception is + * caught. */ void exraise(int e) { + INTOFF; if (handler == NULL) abort(); exception = e; @@ -138,8 +142,15 @@ onint(void) static void exverror(int cond, const char *msg, va_list ap) { - CLEAR_PENDING_INT; - INTOFF; + /* + * An interrupt trumps an error. Certain places catch error + * exceptions or transform them to a plain nonzero exit code + * in child processes, and if an error exception can be handled, + * an interrupt can be handled as well. + * + * exraise() will disable interrupts for the exception handler. + */ + FORCEINTON; #ifdef DEBUG if (msg) -- cgit v1.1