Mercurial > sdl-ios-xcode
annotate src/SDL_fatal.c @ 1226:d05306f0dc21
More dynamic X11 fixes...catches some code in Xlib headers that caused
dependencies...
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 04 Jan 2006 22:57:50 +0000 |
parents | 51a8702d8ecd |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
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 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
1
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
1152
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
861
diff
changeset
|
28 #ifdef _WIN32_WCE |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
861
diff
changeset
|
29 #define NO_SIGNAL_H |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
861
diff
changeset
|
30 #endif |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
861
diff
changeset
|
31 |
0 | 32 /* General fatal signal handling code for SDL */ |
33 | |
34 #ifdef NO_SIGNAL_H | |
35 | |
36 /* No signals on this platform, nothing to do.. */ | |
37 | |
38 void SDL_InstallParachute(void) | |
39 { | |
40 return; | |
41 } | |
42 | |
43 void SDL_UninstallParachute(void) | |
44 { | |
45 return; | |
46 } | |
47 | |
48 #else | |
49 | |
50 #include <stdlib.h> | |
51 #include <stdio.h> | |
52 #include <signal.h> | |
53 #include <string.h> | |
54 | |
55 #include "SDL.h" | |
56 #include "SDL_fatal.h" | |
57 | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
58 #ifdef __CYGWIN__ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
59 #define DISABLE_STDIO |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
60 #endif |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
61 |
0 | 62 /* This installs some signal handlers for the more common fatal signals, |
63 so that if the programmer is lazy, the app doesn't die so horribly if | |
64 the program crashes. | |
65 */ | |
66 | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
67 static void print_msg(const char *text) |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
68 { |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
69 #ifndef DISABLE_STDIO |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
70 fprintf(stderr, "%s", text); |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
71 #endif |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
72 } |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
73 |
0 | 74 static void SDL_Parachute(int sig) |
75 { | |
76 signal(sig, SIG_DFL); | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
77 print_msg("Fatal signal: "); |
0 | 78 switch (sig) { |
79 case SIGSEGV: | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
80 print_msg("Segmentation Fault"); |
0 | 81 break; |
82 #ifdef SIGBUS | |
83 #if SIGBUS != SIGSEGV | |
84 case SIGBUS: | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
85 print_msg("Bus Error"); |
0 | 86 break; |
87 #endif | |
88 #endif /* SIGBUS */ | |
89 #ifdef SIGFPE | |
90 case SIGFPE: | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
91 print_msg("Floating Point Exception"); |
0 | 92 break; |
93 #endif /* SIGFPE */ | |
94 #ifdef SIGQUIT | |
95 case SIGQUIT: | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
96 print_msg("Keyboard Quit"); |
0 | 97 break; |
98 #endif /* SIGQUIT */ | |
99 #ifdef SIGPIPE | |
100 case SIGPIPE: | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
101 print_msg("Broken Pipe"); |
0 | 102 break; |
103 #endif /* SIGPIPE */ | |
104 default: | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
105 #ifndef DISABLE_STDIO |
0 | 106 fprintf(stderr, "# %d", sig); |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
107 #endif |
0 | 108 break; |
109 } | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
110 print_msg(" (SDL Parachute Deployed)\n"); |
0 | 111 SDL_Quit(); |
112 exit(-sig); | |
113 } | |
114 | |
115 static int SDL_fatal_signals[] = { | |
116 SIGSEGV, | |
117 #ifdef SIGBUS | |
118 SIGBUS, | |
119 #endif | |
120 #ifdef SIGFPE | |
121 SIGFPE, | |
122 #endif | |
123 #ifdef SIGQUIT | |
124 SIGQUIT, | |
125 #endif | |
126 0 | |
127 }; | |
128 | |
129 void SDL_InstallParachute(void) | |
130 { | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
131 /* Set a handler for any fatal signal not already handled */ |
0 | 132 int i; |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
133 #ifdef HAVE_SIGACTION |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
134 struct sigaction action; |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
135 |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
136 for ( i=0; SDL_fatal_signals[i]; ++i ) { |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
137 sigaction(SDL_fatal_signals[i], NULL, &action); |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
138 if ( action.sa_handler == SIG_DFL ) { |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
139 action.sa_handler = SDL_Parachute; |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
140 sigaction(SDL_fatal_signals[i], &action, NULL); |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
141 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
142 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
143 #ifdef SIGALRM |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
144 /* Set SIGALRM to be ignored -- necessary on Solaris */ |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
145 sigaction(SIGALRM, NULL, &action); |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
146 if ( action.sa_handler == SIG_DFL ) { |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
147 action.sa_handler = SIG_IGN; |
861
863da1c38c7e
Oops, ignore SIGALRM, not 0
Sam Lantinga <slouken@libsdl.org>
parents:
822
diff
changeset
|
148 sigaction(SIGALRM, &action, NULL); |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
149 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
150 #endif |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
151 #else |
0 | 152 void (*ohandler)(int); |
153 | |
154 for ( i=0; SDL_fatal_signals[i]; ++i ) { | |
155 ohandler = signal(SDL_fatal_signals[i], SDL_Parachute); | |
156 if ( ohandler != SIG_DFL ) { | |
157 signal(SDL_fatal_signals[i], ohandler); | |
158 } | |
159 } | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
160 #endif /* HAVE_SIGACTION */ |
0 | 161 return; |
162 } | |
163 | |
164 void SDL_UninstallParachute(void) | |
165 { | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
166 /* Remove a handler for any fatal signal handled */ |
0 | 167 int i; |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
168 #ifdef HAVE_SIGACTION |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
169 struct sigaction action; |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
170 |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
171 for ( i=0; SDL_fatal_signals[i]; ++i ) { |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
172 sigaction(SDL_fatal_signals[i], NULL, &action); |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
173 if ( action.sa_handler == SDL_Parachute ) { |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
174 action.sa_handler = SIG_DFL; |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
175 sigaction(SDL_fatal_signals[i], &action, NULL); |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
176 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
177 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
178 #else |
0 | 179 void (*ohandler)(int); |
180 | |
181 for ( i=0; SDL_fatal_signals[i]; ++i ) { | |
182 ohandler = signal(SDL_fatal_signals[i], SIG_DFL); | |
183 if ( ohandler != SDL_Parachute ) { | |
184 signal(SDL_fatal_signals[i], ohandler); | |
185 } | |
186 } | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
187 #endif /* HAVE_SIGACTION */ |
0 | 188 } |
189 | |
190 #endif /* NO_SIGNAL_H */ |