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

Latest commit

 

History

History
139 lines (118 loc) · 3.34 KB

SDL_fatal.c

File metadata and controls

139 lines (118 loc) · 3.34 KB
 
Apr 26, 2001
Apr 26, 2001
1
/*
Apr 8, 2011
Apr 8, 2011
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Apr 26, 2001
Apr 26, 2001
20
*/
Feb 21, 2006
Feb 21, 2006
21
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
22
23
24
/* General fatal signal handling code for SDL */
Feb 6, 2006
Feb 6, 2006
25
#ifdef HAVE_SIGNAL_H
Apr 26, 2001
Apr 26, 2001
26
27
28
#include <signal.h>
Jan 13, 2010
Jan 13, 2010
29
#include "SDL.h"
Apr 26, 2001
Apr 26, 2001
30
31
32
33
34
35
36
#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
37
38
static void
SDL_Parachute(int sig)
Apr 26, 2001
Apr 26, 2001
39
{
Jul 10, 2006
Jul 10, 2006
40
41
42
signal(sig, SIG_DFL);
SDL_Quit();
raise(sig);
Apr 26, 2001
Apr 26, 2001
43
44
}
Jun 3, 2009
Jun 3, 2009
45
static const int SDL_fatal_signals[] = {
Jul 10, 2006
Jul 10, 2006
46
SIGSEGV,
Apr 26, 2001
Apr 26, 2001
47
#ifdef SIGBUS
Jul 10, 2006
Jul 10, 2006
48
SIGBUS,
Apr 26, 2001
Apr 26, 2001
49
50
#endif
#ifdef SIGFPE
Jul 10, 2006
Jul 10, 2006
51
SIGFPE,
Apr 26, 2001
Apr 26, 2001
52
53
#endif
#ifdef SIGQUIT
Jul 10, 2006
Jul 10, 2006
54
SIGQUIT,
Apr 26, 2001
Apr 26, 2001
55
#endif
Jul 10, 2006
Jul 10, 2006
56
0
Apr 26, 2001
Apr 26, 2001
57
58
};
Jul 10, 2006
Jul 10, 2006
59
60
void
SDL_InstallParachute(void)
Apr 26, 2001
Apr 26, 2001
61
{
Jul 10, 2006
Jul 10, 2006
62
63
/* Set a handler for any fatal signal not already handled */
int i;
Feb 12, 2004
Feb 12, 2004
64
#ifdef HAVE_SIGACTION
Jul 10, 2006
Jul 10, 2006
65
66
67
68
69
70
71
72
73
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
74
#ifdef SIGALRM
Jul 10, 2006
Jul 10, 2006
75
76
77
78
79
80
/* 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
81
82
#endif
#else
Jul 10, 2006
Jul 10, 2006
83
84
85
86
87
88
89
90
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
91
#endif /* HAVE_SIGACTION */
Jul 10, 2006
Jul 10, 2006
92
return;
Apr 26, 2001
Apr 26, 2001
93
94
}
Jul 10, 2006
Jul 10, 2006
95
96
void
SDL_UninstallParachute(void)
Apr 26, 2001
Apr 26, 2001
97
{
Jul 10, 2006
Jul 10, 2006
98
99
/* Remove a handler for any fatal signal handled */
int i;
Feb 12, 2004
Feb 12, 2004
100
#ifdef HAVE_SIGACTION
Jul 10, 2006
Jul 10, 2006
101
102
103
104
105
106
107
108
109
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
110
#else
Jul 10, 2006
Jul 10, 2006
111
112
113
114
115
116
117
118
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
119
#endif /* HAVE_SIGACTION */
Apr 26, 2001
Apr 26, 2001
120
121
}
Feb 6, 2006
Feb 6, 2006
122
123
124
125
#else
/* No signals on this platform, nothing to do.. */
Jul 10, 2006
Jul 10, 2006
126
127
void
SDL_InstallParachute(void)
Feb 6, 2006
Feb 6, 2006
128
{
Jul 10, 2006
Jul 10, 2006
129
return;
Feb 6, 2006
Feb 6, 2006
130
131
}
Jul 10, 2006
Jul 10, 2006
132
133
void
SDL_UninstallParachute(void)
Feb 6, 2006
Feb 6, 2006
134
{
Jul 10, 2006
Jul 10, 2006
135
return;
Feb 6, 2006
Feb 6, 2006
136
137
138
}
#endif /* HAVE_SIGNAL_H */
Jul 10, 2006
Jul 10, 2006
139
/* vi: set ts=4 sw=4 expandtab: */