Mercurial > sdl-ios-xcode
annotate src/SDL_fatal.c @ 3984:b74530a1dad6 SDL-1.2
Better fix for bug 419
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 28 Jun 2007 05:35:50 +0000 |
parents | d910939febfa |
children | 782fd950bd46 c121d94672cb a1b03ba2fcd0 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 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 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* General fatal signal handling code for SDL */ | |
25 | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
26 #ifdef HAVE_SIGNAL_H |
0 | 27 |
28 #include <signal.h> | |
29 | |
30 #include "SDL.h" | |
31 #include "SDL_fatal.h" | |
32 | |
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 | |
35 the program crashes. | |
36 */ | |
37 | |
38 static void SDL_Parachute(int sig) | |
39 { | |
40 signal(sig, SIG_DFL); | |
41 SDL_Quit(); | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
42 raise(sig); |
0 | 43 } |
44 | |
45 static int SDL_fatal_signals[] = { | |
46 SIGSEGV, | |
47 #ifdef SIGBUS | |
48 SIGBUS, | |
49 #endif | |
50 #ifdef SIGFPE | |
51 SIGFPE, | |
52 #endif | |
53 #ifdef SIGQUIT | |
54 SIGQUIT, | |
55 #endif | |
56 0 | |
57 }; | |
58 | |
59 void SDL_InstallParachute(void) | |
60 { | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
61 /* Set a handler for any fatal signal not already handled */ |
0 | 62 int i; |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
63 #ifdef HAVE_SIGACTION |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
64 struct sigaction action; |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
65 |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
72 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
73 #ifdef SIGALRM |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
74 /* 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
|
75 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
|
76 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
|
77 action.sa_handler = SIG_IGN; |
861
863da1c38c7e
Oops, ignore SIGALRM, not 0
Sam Lantinga <slouken@libsdl.org>
parents:
822
diff
changeset
|
78 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
|
79 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
80 #endif |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
81 #else |
0 | 82 void (*ohandler)(int); |
83 | |
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); | |
88 } | |
89 } | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
90 #endif /* HAVE_SIGACTION */ |
0 | 91 return; |
92 } | |
93 | |
94 void SDL_UninstallParachute(void) | |
95 { | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
96 /* Remove a handler for any fatal signal handled */ |
0 | 97 int i; |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
98 #ifdef HAVE_SIGACTION |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
99 struct sigaction action; |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
100 |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
107 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
108 #else |
0 | 109 void (*ohandler)(int); |
110 | |
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); | |
115 } | |
116 } | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
117 #endif /* HAVE_SIGACTION */ |
0 | 118 } |
119 | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
120 #else |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
121 |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
122 /* No signals on this platform, nothing to do.. */ |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
123 |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
124 void SDL_InstallParachute(void) |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
125 { |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
126 return; |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
127 } |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
128 |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
129 void SDL_UninstallParachute(void) |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
130 { |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
131 return; |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
132 } |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
133 |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
134 #endif /* HAVE_SIGNAL_H */ |