slouken@libsdl.org
#include "SDL_config.h"
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#include "SDL.h"
#include "SDL_fatal.h"
static void SDL_Parachute(int sig)
{
signal(sig, SIG_DFL);
SDL_Quit();
raise(sig);
}
static int SDL_fatal_signals[] = {
SIGSEGV,
#ifdef SIGBUS
SIGBUS,
#endif
#ifdef SIGFPE
SIGFPE,
#endif
#ifdef SIGQUIT
SIGQUIT,
#endif
0
};
void SDL_InstallParachute(void)
{
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
sigaction(SIGALRM, NULL, &action);
if ( action.sa_handler == SIG_DFL ) {
action.sa_handler = SIG_IGN;
sigaction(SIGALRM, &action, NULL);
}
#endif
#else
void (*ohandler)(int);
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);
}
}
#endif
return;
}
void SDL_UninstallParachute(void)
{
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);
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
}
#else
void SDL_InstallParachute(void)
{
return;
}
void SDL_UninstallParachute(void)
{
return;
}
#endif