summaryrefslogtreecommitdiffstats
path: root/bin/sh/error.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2009-11-22 18:23:30 +0000
committerjilles <jilles@FreeBSD.org>2009-11-22 18:23:30 +0000
commit760264169e554e3e2ae8312f8f192d1ad95c7854 (patch)
treed42fd7d5720d96daa7589c733afd3cc29c10f330 /bin/sh/error.c
parentba91da3aff4fb68aa0ec546f7eeb21855b267fc7 (diff)
downloadFreeBSD-src-760264169e554e3e2ae8312f8f192d1ad95c7854.zip
FreeBSD-src-760264169e554e3e2ae8312f8f192d1ad95c7854.tar.gz
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.
Diffstat (limited to 'bin/sh/error.c')
-rw-r--r--bin/sh/error.c15
1 files changed, 13 insertions, 2 deletions
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)
OpenPOWER on IntegriCloud