2001-04-26 16:45:43 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2011-02-11 22:37:15 -08:00
|
|
|
Copyright (C) 1997-2011 Sam Lantinga
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2006-02-01 06:32:25 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2001-04-26 16:45:43 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2006-02-01 06:32:25 +00:00
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-02-01 06:32:25 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2006-02-01 06:32:25 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
Sam Lantinga
|
2001-12-14 12:38:15 +00:00
|
|
|
slouken@libsdl.org
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
/* General fatal signal handling code for SDL */
|
|
|
|
|
2006-02-06 08:28:51 +00:00
|
|
|
#ifdef HAVE_SIGNAL_H
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
2010-01-13 05:24:03 +00:00
|
|
|
#include "SDL.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
#include "SDL_fatal.h"
|
|
|
|
|
|
|
|
/* This installs some signal handlers for the more common fatal signals,
|
|
|
|
so that if the programmer is lazy, the app doesn't die so horribly if
|
|
|
|
the program crashes.
|
|
|
|
*/
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
static void
|
|
|
|
SDL_Parachute(int sig)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
signal(sig, SIG_DFL);
|
|
|
|
SDL_Quit();
|
|
|
|
raise(sig);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 04:37:27 +00:00
|
|
|
static const int SDL_fatal_signals[] = {
|
2006-07-10 21:04:37 +00:00
|
|
|
SIGSEGV,
|
2001-04-26 16:45:43 +00:00
|
|
|
#ifdef SIGBUS
|
2006-07-10 21:04:37 +00:00
|
|
|
SIGBUS,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
2006-07-10 21:04:37 +00:00
|
|
|
SIGFPE,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
2006-07-10 21:04:37 +00:00
|
|
|
SIGQUIT,
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2006-07-10 21:04:37 +00:00
|
|
|
0
|
2001-04-26 16:45:43 +00:00
|
|
|
};
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_InstallParachute(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Set a handler for any fatal signal not already handled */
|
|
|
|
int i;
|
2004-02-12 16:29:24 +00:00
|
|
|
#ifdef HAVE_SIGACTION
|
2006-07-10 21:04:37 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#ifdef SIGALRM
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Set SIGALRM to be ignored -- necessary on Solaris */
|
|
|
|
sigaction(SIGALRM, NULL, &action);
|
|
|
|
if (action.sa_handler == SIG_DFL) {
|
|
|
|
action.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGALRM, &action, NULL);
|
|
|
|
}
|
2004-02-12 16:29:24 +00:00
|
|
|
#endif
|
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2004-02-12 16:29:24 +00:00
|
|
|
#endif /* HAVE_SIGACTION */
|
2006-07-10 21:04:37 +00:00
|
|
|
return;
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_UninstallParachute(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Remove a handler for any fatal signal handled */
|
|
|
|
int i;
|
2004-02-12 16:29:24 +00:00
|
|
|
#ifdef HAVE_SIGACTION
|
2006-07-10 21:04:37 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2004-02-12 16:29:24 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2004-02-12 16:29:24 +00:00
|
|
|
#endif /* HAVE_SIGACTION */
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2006-02-06 08:28:51 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* No signals on this platform, nothing to do.. */
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_InstallParachute(void)
|
2006-02-06 08:28:51 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
return;
|
2006-02-06 08:28:51 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_UninstallParachute(void)
|
2006-02-06 08:28:51 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
return;
|
2006-02-06 08:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_SIGNAL_H */
|
2006-07-10 21:04:37 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|