Mercurial > hg > octave-lyh > gnulib-hg
changeset 10381:31614a69f913
Don't override previously installed signal handlers.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 31 Aug 2008 16:05:16 +0200 |
parents | 85d962720a4e |
children | 682dd60a37e4 |
files | ChangeLog lib/fatal-signal.c |
diffstat | 2 files changed, 26 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -125,19 +125,25 @@ 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 @@ 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]); + } }