Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
140 lines (118 loc) · 3.27 KB

SDL_fatal.c

File metadata and controls

140 lines (118 loc) · 3.27 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Jan 24, 2010
Jan 24, 2010
3
Copyright (C) 1997-2010 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
/* General fatal signal handling code for SDL */
Feb 6, 2006
Feb 6, 2006
26
#ifdef HAVE_SIGNAL_H
Apr 26, 2001
Apr 26, 2001
27
28
29
#include <signal.h>
Jan 13, 2010
Jan 13, 2010
30
#include "SDL.h"
Apr 26, 2001
Apr 26, 2001
31
32
33
34
35
36
37
#include "SDL_fatal.h"
/* This installs some signal handlers for the more common fatal signals,
so that if the programmer is lazy, the app doesn't die so horribly if
the program crashes.
*/
Jul 10, 2006
Jul 10, 2006
38
39
static void
SDL_Parachute(int sig)
Apr 26, 2001
Apr 26, 2001
40
{
Jul 10, 2006
Jul 10, 2006
41
42
43
signal(sig, SIG_DFL);
SDL_Quit();
raise(sig);
Apr 26, 2001
Apr 26, 2001
44
45
}
Jun 3, 2009
Jun 3, 2009
46
static const int SDL_fatal_signals[] = {
Jul 10, 2006
Jul 10, 2006
47
SIGSEGV,
Apr 26, 2001
Apr 26, 2001
48
#ifdef SIGBUS
Jul 10, 2006
Jul 10, 2006
49
SIGBUS,
Apr 26, 2001
Apr 26, 2001
50
51
#endif
#ifdef SIGFPE
Jul 10, 2006
Jul 10, 2006
52
SIGFPE,
Apr 26, 2001
Apr 26, 2001
53
54
#endif
#ifdef SIGQUIT
Jul 10, 2006
Jul 10, 2006
55
SIGQUIT,
Apr 26, 2001
Apr 26, 2001
56
#endif
Jul 10, 2006
Jul 10, 2006
57
0
Apr 26, 2001
Apr 26, 2001
58
59
};
Jul 10, 2006
Jul 10, 2006
60
61
void
SDL_InstallParachute(void)
Apr 26, 2001
Apr 26, 2001
62
{
Jul 10, 2006
Jul 10, 2006
63
64
/* Set a handler for any fatal signal not already handled */
int i;
Feb 12, 2004
Feb 12, 2004
65
#ifdef HAVE_SIGACTION
Jul 10, 2006
Jul 10, 2006
66
67
68
69
70
71
72
73
74
struct sigaction action;
for (i = 0; SDL_fatal_signals[i]; ++i) {
sigaction(SDL_fatal_signals[i], NULL, &action);
if (action.sa_handler == SIG_DFL) {
action.sa_handler = SDL_Parachute;
sigaction(SDL_fatal_signals[i], &action, NULL);
}
}
Apr 26, 2001
Apr 26, 2001
75
#ifdef SIGALRM
Jul 10, 2006
Jul 10, 2006
76
77
78
79
80
81
/* Set SIGALRM to be ignored -- necessary on Solaris */
sigaction(SIGALRM, NULL, &action);
if (action.sa_handler == SIG_DFL) {
action.sa_handler = SIG_IGN;
sigaction(SIGALRM, &action, NULL);
}
Feb 12, 2004
Feb 12, 2004
82
83
#endif
#else
Jul 10, 2006
Jul 10, 2006
84
85
86
87
88
89
90
91
void (*ohandler) (int);
for (i = 0; SDL_fatal_signals[i]; ++i) {
ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
if (ohandler != SIG_DFL) {
signal(SDL_fatal_signals[i], ohandler);
}
}
Feb 12, 2004
Feb 12, 2004
92
#endif /* HAVE_SIGACTION */
Jul 10, 2006
Jul 10, 2006
93
return;
Apr 26, 2001
Apr 26, 2001
94
95
}
Jul 10, 2006
Jul 10, 2006
96
97
void
SDL_UninstallParachute(void)
Apr 26, 2001
Apr 26, 2001
98
{
Jul 10, 2006
Jul 10, 2006
99
100
/* Remove a handler for any fatal signal handled */
int i;
Feb 12, 2004
Feb 12, 2004
101
#ifdef HAVE_SIGACTION
Jul 10, 2006
Jul 10, 2006
102
103
104
105
106
107
108
109
110
struct sigaction action;
for (i = 0; SDL_fatal_signals[i]; ++i) {
sigaction(SDL_fatal_signals[i], NULL, &action);
if (action.sa_handler == SDL_Parachute) {
action.sa_handler = SIG_DFL;
sigaction(SDL_fatal_signals[i], &action, NULL);
}
}
Feb 12, 2004
Feb 12, 2004
111
#else
Jul 10, 2006
Jul 10, 2006
112
113
114
115
116
117
118
119
void (*ohandler) (int);
for (i = 0; SDL_fatal_signals[i]; ++i) {
ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
if (ohandler != SDL_Parachute) {
signal(SDL_fatal_signals[i], ohandler);
}
}
Feb 12, 2004
Feb 12, 2004
120
#endif /* HAVE_SIGACTION */
Apr 26, 2001
Apr 26, 2001
121
122
}
Feb 6, 2006
Feb 6, 2006
123
124
125
126
#else
/* No signals on this platform, nothing to do.. */
Jul 10, 2006
Jul 10, 2006
127
128
void
SDL_InstallParachute(void)
Feb 6, 2006
Feb 6, 2006
129
{
Jul 10, 2006
Jul 10, 2006
130
return;
Feb 6, 2006
Feb 6, 2006
131
132
}
Jul 10, 2006
Jul 10, 2006
133
134
void
SDL_UninstallParachute(void)
Feb 6, 2006
Feb 6, 2006
135
{
Jul 10, 2006
Jul 10, 2006
136
return;
Feb 6, 2006
Feb 6, 2006
137
138
139
}
#endif /* HAVE_SIGNAL_H */
Jul 10, 2006
Jul 10, 2006
140
/* vi: set ts=4 sw=4 expandtab: */