annotate src/SDL_fatal.c @ 1367:e440d5c488c1

Fixes for BeOS and Solaris builds
author Sam Lantinga <slouken@libsdl.org>
date Fri, 17 Feb 2006 08:43:23 +0000
parents 450721ad5436
children d910939febfa
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 /* General fatal signal handling code for SDL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <signal.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include "SDL.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include "SDL_fatal.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 /* This installs some signal handlers for the more common fatal signals,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 so that if the programmer is lazy, the app doesn't die so horribly if
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 the program crashes.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 static void SDL_Parachute(int sig)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 signal(sig, SIG_DFL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 static int SDL_fatal_signals[] = {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 SIGSEGV,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 #ifdef SIGBUS
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 SIGBUS,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 #ifdef SIGFPE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 SIGFPE,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 #ifdef SIGQUIT
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 SIGQUIT,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 void SDL_InstallParachute(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 void (*ohandler)(int);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 for ( i=0; SDL_fatal_signals[i]; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86 ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 if ( ohandler != SIG_DFL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 signal(SDL_fatal_signals[i], ohandler);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 void SDL_UninstallParachute(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110 void (*ohandler)(int);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112 for ( i=0; SDL_fatal_signals[i]; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113 ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114 if ( ohandler != SDL_Parachute ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 signal(SDL_fatal_signals[i], ohandler);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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 */