2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 /* General fatal signal handling code for SDL */
31 #include "SDL_fatal.h"
33 /* This installs some signal handlers for the more common fatal signals,
34 so that if the programmer is lazy, the app doesn't die so horribly if
38 static void SDL_Parachute(int sig)
45 static int SDL_fatal_signals[] = {
59 void SDL_InstallParachute(void)
61 /* Set a handler for any fatal signal not already handled */
64 struct sigaction action;
66 for ( i=0; SDL_fatal_signals[i]; ++i ) {
67 sigaction(SDL_fatal_signals[i], NULL, &action);
68 if ( action.sa_handler == SIG_DFL ) {
69 action.sa_handler = SDL_Parachute;
70 sigaction(SDL_fatal_signals[i], &action, NULL);
74 /* Set SIGALRM to be ignored -- necessary on Solaris */
75 sigaction(SIGALRM, NULL, &action);
76 if ( action.sa_handler == SIG_DFL ) {
77 action.sa_handler = SIG_IGN;
78 sigaction(SIGALRM, &action, NULL);
82 void (*ohandler)(int);
84 for ( i=0; SDL_fatal_signals[i]; ++i ) {
85 ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
86 if ( ohandler != SIG_DFL ) {
87 signal(SDL_fatal_signals[i], ohandler);
90 #endif /* HAVE_SIGACTION */
94 void SDL_UninstallParachute(void)
96 /* Remove a handler for any fatal signal handled */
99 struct sigaction action;
101 for ( i=0; SDL_fatal_signals[i]; ++i ) {
102 sigaction(SDL_fatal_signals[i], NULL, &action);
103 if ( action.sa_handler == SDL_Parachute ) {
104 action.sa_handler = SIG_DFL;
105 sigaction(SDL_fatal_signals[i], &action, NULL);
109 void (*ohandler)(int);
111 for ( i=0; SDL_fatal_signals[i]; ++i ) {
112 ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
113 if ( ohandler != SDL_Parachute ) {
114 signal(SDL_fatal_signals[i], ohandler);
117 #endif /* HAVE_SIGACTION */
122 /* No signals on this platform, nothing to do.. */
124 void SDL_InstallParachute(void)
129 void SDL_UninstallParachute(void)
134 #endif /* HAVE_SIGNAL_H */