bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fatal-signal improvement


From: Bruno Haible
Subject: fatal-signal improvement
Date: Sun, 31 Aug 2008 16:07:16 +0200
User-agent: KMail/1.5.4

This commit makes it possible for an application to install a handler for a
fatal signal (e.g. SIGPIPE) and use the 'fatal-signal' module nevertheless.


2008-08-31  Bruno Haible  <address@hidden>

        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.

*** lib/fatal-signal.c.orig     2008-08-31 16:00:32.000000000 +0200
--- lib/fatal-signal.c  2008-08-31 12:43:43.000000000 +0200
***************
*** 125,143 ****
  static size_t actions_allocated = SIZEOF (static_actions);
  
  
  /* 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);
  }
  
  
--- 125,149 ----
  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;
  
    for (i = 0; i < num_fatal_signals; i++)
      if (fatal_signals[i] >= 0)
!       {
!       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,190 ****
    sigemptyset (&action.sa_mask);
    for (i = 0; i < num_fatal_signals; i++)
      if (fatal_signals[i] >= 0)
!       sigaction (fatal_signals[i], &action, NULL);
  }
  
  
--- 190,202 ----
    sigemptyset (&action.sa_mask);
    for (i = 0; i < num_fatal_signals; i++)
      if (fatal_signals[i] >= 0)
!       {
!       int sig = fatal_signals[i];
! 
!       if (!(sig < sizeof (saved_sigactions) / sizeof (sigactions[0])))
!         abort ();
!       sigaction (sig, &action, &saved_sigactions[sig]);
!       }
  }
  
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]