bash-custom-action/bash-4.1-intr.dif

124 lines
2.8 KiB
Plaintext

--- parse.y
+++ parse.y 2010-01-20 13:51:39.000000000 +0000
@@ -1434,10 +1434,11 @@ yy_readline_get ()
current_readline_prompt : "");
terminate_immediately = 0;
- if (signal_is_ignored (SIGINT) == 0 && old_sigint)
+ if (signal_is_ignored (SIGINT) == 0)
{
interrupt_immediately--;
- set_signal_handler (SIGINT, old_sigint);
+ if (old_sigint)
+ set_signal_handler (SIGINT, old_sigint);
}
#if 0
--- xmalloc.c
+++ xmalloc.c 2010-02-15 15:36:40.113797875 +0000
@@ -35,6 +35,11 @@
# include "ansi_stdlib.h"
#endif /* HAVE_STDLIB_H */
+/* Determine which kind of system this is. */
+#include <signal.h>
+extern int interrupt_immediately;
+extern int signal_is_trapped __P((int));
+
#include "error.h"
#include "bashintl.h"
@@ -94,6 +99,34 @@ allocerr (func, bytes)
#endif /* !HAVE_SBRK */
}
+static void
+block_signals (setp, osetp)
+ sigset_t *setp, *osetp;
+{
+#ifdef HAVE_POSIX_SIGNALS
+ sigfillset (setp);
+ sigemptyset (osetp);
+ sigprocmask (SIG_BLOCK, setp, osetp);
+#else
+# if defined (HAVE_BSD_SIGNALS)
+ *osetp = sigsetmask (-1);
+# endif
+#endif
+}
+
+static void
+unblock_signals (setp, osetp)
+ sigset_t *setp, *osetp;
+{
+#ifdef HAVE_POSIX_SIGNALS
+ sigprocmask (SIG_SETMASK, osetp, (sigset_t *)NULL);
+#else
+# if defined (HAVE_BSD_SIGNALS)
+ sigsetmask (*osetp);
+# endif
+#endif
+}
+
/* Return a pointer to free()able block of memory large enough
to hold BYTES number of bytes. If the memory cannot be allocated,
print an error message and abort. */
@@ -102,15 +135,28 @@ xmalloc (bytes)
size_t bytes;
{
PTR_T temp;
+ sigset_t set, oset;
+ int blocked_sigs;
#if defined (DEBUG)
if (bytes == 0)
internal_warning("xmalloc: size argument is 0");
#endif
+ /* Block all signals in case we are executed from a signal handler. */
+ blocked_sigs = 0;
+ if (interrupt_immediately || signal_is_trapped (SIGINT) || signal_is_trapped (SIGCHLD))
+ {
+ block_signals (&set, &oset);
+ blocked_sigs = 1;
+ }
+
FINDBRK();
temp = malloc (bytes);
+ if (blocked_sigs)
+ unblock_signals (&set, &oset);
+
if (temp == 0)
allocerr ("xmalloc", bytes);
@@ -123,15 +169,28 @@ xrealloc (pointer, bytes)
size_t bytes;
{
PTR_T temp;
+ sigset_t set, oset;
+ int blocked_sigs;
#if defined (DEBUG)
if (bytes == 0)
internal_warning("xrealloc: size argument is 0");
#endif
+ /* Block all signals in case we are executed from a signal handler. */
+ blocked_sigs = 0;
+ if (interrupt_immediately || signal_is_trapped (SIGINT) || signal_is_trapped (SIGCHLD))
+ {
+ block_signals (&set, &oset);
+ blocked_sigs = 1;
+ }
+
FINDBRK();
temp = pointer ? realloc (pointer, bytes) : malloc (bytes);
+ if (blocked_sigs)
+ unblock_signals (&set, &oset);
+
if (temp == 0)
allocerr ("xrealloc", bytes);