Use sigaction instead of signal to preserve handler flags (thanks Matthew!)

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40815
This commit is contained in:
Sam Lantinga 2004-02-12 16:29:24 +00:00
parent b2cf21a244
commit 12fa222cec
2 changed files with 73 additions and 18 deletions

View file

@ -127,47 +127,63 @@ static int SDL_fatal_signals[] = {
void SDL_InstallParachute(void)
{
/* Set a handler for any fatal signal not already handled */
int i;
#ifdef HAVE_SIGACTION
struct sigaction action;
for ( i=0; SDL_fatal_signals[i]; ++i ) {
sigaction(SDL_fatal_signals[i], NULL, &action);
if ( action.sa_handler == SIG_DFL ) {
action.sa_handler = SDL_Parachute;
sigaction(SDL_fatal_signals[i], &action, NULL);
}
}
#ifdef SIGALRM
/* Set SIGALRM to be ignored -- necessary on Solaris */
sigaction(SIGALRM, NULL, &action);
if ( action.sa_handler == SIG_DFL ) {
action.sa_handler = SIG_IGN;
sigaction(SDL_fatal_signals[i], &action, NULL);
}
#endif
#else
void (*ohandler)(int);
/* Set a handler for any fatal signal not already handled */
for ( i=0; SDL_fatal_signals[i]; ++i ) {
ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
if ( ohandler != SIG_DFL ) {
signal(SDL_fatal_signals[i], ohandler);
}
}
#ifdef SIGALRM
/* Set SIGALRM to be ignored -- necessary on Solaris */
{
struct sigaction action, oaction;
/* Set SIG_IGN action */
memset(&action, 0, (sizeof action));
action.sa_handler = SIG_IGN;
sigaction(SIGALRM, &action, &oaction);
/* Reset original action if it was already being handled */
if ( oaction.sa_handler != SIG_DFL ) {
sigaction(SIGALRM, &oaction, NULL);
}
}
#endif
#endif /* HAVE_SIGACTION */
return;
}
void SDL_UninstallParachute(void)
{
/* Remove a handler for any fatal signal handled */
int i;
#ifdef HAVE_SIGACTION
struct sigaction action;
for ( i=0; SDL_fatal_signals[i]; ++i ) {
sigaction(SDL_fatal_signals[i], NULL, &action);
if ( action.sa_handler == SDL_Parachute ) {
action.sa_handler = SIG_DFL;
sigaction(SDL_fatal_signals[i], &action, NULL);
}
}
#else
void (*ohandler)(int);
/* Remove a handler for any fatal signal handled */
for ( i=0; SDL_fatal_signals[i]; ++i ) {
ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
if ( ohandler != SDL_Parachute ) {
signal(SDL_fatal_signals[i], ohandler);
}
}
#endif /* HAVE_SIGACTION */
}
#endif /* NO_SIGNAL_H */