Don't override previously installed signal handlers.
authorBruno Haible <bruno@clisp.org>
Sun, 31 Aug 2008 14:05:16 +0000 (16:05 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 31 Aug 2008 14:05:16 +0000 (16:05 +0200)
ChangeLog
lib/fatal-signal.c

index 932c18c..01c184d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-08-31  Bruno Haible  <bruno@clisp.org>
+
+       Don't override previously installed signal handlers.
+       * lib/fatal-signal.c (saved_sigactions): New variable.
+       (uninstall_handlers): Reset the signal to the saved handler, not
+       to SIG_DFL (except when ignored).
+       (install_handlers): Save the previous handlers.
+
 2008-08-30  Bruno Haible  <bruno@clisp.org>
 
        * gnulib-tool (func_reset_sigpipe): New function.
index 64b346d..6ec36a0 100644 (file)
@@ -125,19 +125,25 @@ static sig_atomic_t volatile actions_count = 0;
 static size_t actions_allocated = SIZEOF (static_actions);
 
 
+/* The saved signal handlers.
+   Size 32 would not be sufficient: On HP-UX, SIGXCPU = 33, SIGXFSZ = 34.  */
+static struct sigaction saved_sigactions[64];
+
+
 /* Uninstall the handlers.  */
 static inline void
 uninstall_handlers ()
 {
   size_t i;
-  struct sigaction action;
 
-  action.sa_handler = SIG_DFL;
-  action.sa_flags = 0;
-  sigemptyset (&action.sa_mask);
   for (i = 0; i < num_fatal_signals; i++)
     if (fatal_signals[i] >= 0)
-      sigaction (fatal_signals[i], &action, NULL);
+      {
+       int sig = fatal_signals[i];
+       if (saved_sigactions[sig].sa_handler == SIG_IGN)
+         saved_sigactions[sig].sa_handler = SIG_DFL;
+       sigaction (sig, &saved_sigactions[sig], NULL);
+      }
 }
 
 
@@ -184,7 +190,13 @@ install_handlers ()
   sigemptyset (&action.sa_mask);
   for (i = 0; i < num_fatal_signals; i++)
     if (fatal_signals[i] >= 0)
-      sigaction (fatal_signals[i], &action, NULL);
+      {
+       int sig = fatal_signals[i];
+
+       if (!(sig < sizeof (saved_sigactions) / sizeof (sigactions[0])))
+         abort ();
+       sigaction (sig, &action, &saved_sigactions[sig]);
+      }
 }