diff options
author | Jilles Tjoelker <jilles@FreeBSD.org> | 2009-11-22 18:23:30 +0000 |
---|---|---|
committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2009-11-22 18:23:30 +0000 |
commit | 9922c6d2d5e3158b241cc5e4e638b4d3f6f6187a (patch) | |
tree | d42fd7d5720d96daa7589c733afd3cc29c10f330 /bin/sh/error.c | |
parent | b94f6865f9cbf1328ac57d9ea342bf735fc2b4b6 (diff) | |
download | src-9922c6d2d5e3158b241cc5e4e638b4d3f6f6187a.tar.gz src-9922c6d2d5e3158b241cc5e4e638b4d3f6f6187a.zip |
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.
Notes
Notes:
svn path=/head/; revision=199660
Diffstat (limited to 'bin/sh/error.c')
-rw-r--r-- | bin/sh/error.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/bin/sh/error.c b/bin/sh/error.c index 0c981a3eff92..72061b8a1bef 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) |