Mercurial > sdl-ios-xcode
annotate src/SDL_fatal.c @ 1371:e2641c13bf33
Added a reminder on where to put libSDL.so
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 18 Feb 2006 07:21:42 +0000 |
parents | 450721ad5436 |
children | d910939febfa |
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 */ |
22 | |
23 /* General fatal signal handling code for SDL */ | |
24 | |
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
|
25 #include "SDL_config.h" |
0 | 26 |
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
|
27 #ifdef HAVE_SIGNAL_H |
0 | 28 |
29 #include <signal.h> | |
30 | |
31 #include "SDL.h" | |
32 #include "SDL_fatal.h" | |
33 | |
34 /* This installs some signal handlers for the more common fatal signals, | |
35 so that if the programmer is lazy, the app doesn't die so horribly if | |
36 the program crashes. | |
37 */ | |
38 | |
39 static void SDL_Parachute(int sig) | |
40 { | |
41 signal(sig, SIG_DFL); | |
42 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
|
43 raise(sig); |
0 | 44 } |
45 | |
46 static int SDL_fatal_signals[] = { | |
47 SIGSEGV, | |
48 #ifdef SIGBUS | |
49 SIGBUS, | |
50 #endif | |
51 #ifdef SIGFPE | |
52 SIGFPE, | |
53 #endif | |
54 #ifdef SIGQUIT | |
55 SIGQUIT, | |
56 #endif | |
57 0 | |
58 }; | |
59 | |
60 void SDL_InstallParachute(void) | |
61 { | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
62 /* Set a handler for any fatal signal not already handled */ |
0 | 63 int i; |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
64 #ifdef HAVE_SIGACTION |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
65 struct sigaction action; |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
66 |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
73 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
74 #ifdef SIGALRM |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
75 /* 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
|
76 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
|
77 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
|
78 action.sa_handler = SIG_IGN; |
861
863da1c38c7e
Oops, ignore SIGALRM, not 0
Sam Lantinga <slouken@libsdl.org>
parents:
822
diff
changeset
|
79 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
|
80 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
81 #endif |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
82 #else |
0 | 83 void (*ohandler)(int); |
84 | |
85 for ( i=0; SDL_fatal_signals[i]; ++i ) { | |
86 ohandler = signal(SDL_fatal_signals[i], SDL_Parachute); | |
87 if ( ohandler != SIG_DFL ) { | |
88 signal(SDL_fatal_signals[i], ohandler); | |
89 } | |
90 } | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
91 #endif /* HAVE_SIGACTION */ |
0 | 92 return; |
93 } | |
94 | |
95 void SDL_UninstallParachute(void) | |
96 { | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
97 /* Remove a handler for any fatal signal handled */ |
0 | 98 int i; |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
99 #ifdef HAVE_SIGACTION |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
100 struct sigaction action; |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
101 |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
108 } |
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
109 #else |
0 | 110 void (*ohandler)(int); |
111 | |
112 for ( i=0; SDL_fatal_signals[i]; ++i ) { | |
113 ohandler = signal(SDL_fatal_signals[i], SIG_DFL); | |
114 if ( ohandler != SDL_Parachute ) { | |
115 signal(SDL_fatal_signals[i], ohandler); | |
116 } | |
117 } | |
814
5a417d2a8603
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
118 #endif /* HAVE_SIGACTION */ |
0 | 119 } |
120 | |
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
|
121 #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
|
122 |
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 /* 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
|
124 |
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 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
|
126 { |
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 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
|
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 |
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 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
|
131 { |
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 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
|
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 |
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
|
135 #endif /* HAVE_SIGNAL_H */ |