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
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 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
30
31
32
33
34
35
36
37
#include <signal.h>
#include "SDL.h"
#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.
*/
May 28, 2006
May 28, 2006
38
static void
May 29, 2006
May 29, 2006
39
SDL_Parachute(int sig)
Apr 26, 2001
Apr 26, 2001
40
{
May 29, 2006
May 29, 2006
41
42
43
signal(sig, SIG_DFL);
SDL_Quit();
raise(sig);
Apr 26, 2001
Apr 26, 2001
44
45
46
}
static int SDL_fatal_signals[] = {
May 28, 2006
May 28, 2006
47
SIGSEGV,
Apr 26, 2001
Apr 26, 2001
48
#ifdef SIGBUS
May 28, 2006
May 28, 2006
49
SIGBUS,
Apr 26, 2001
Apr 26, 2001
50
51
#endif
#ifdef SIGFPE
May 28, 2006
May 28, 2006
52
SIGFPE,
Apr 26, 2001
Apr 26, 2001
53
54
#endif
#ifdef SIGQUIT
May 28, 2006
May 28, 2006
55
SIGQUIT,
Apr 26, 2001
Apr 26, 2001
56
#endif
May 28, 2006
May 28, 2006
57
0
Apr 26, 2001
Apr 26, 2001
58
59
};
May 28, 2006
May 28, 2006
60
void
May 29, 2006
May 29, 2006
61
SDL_InstallParachute(void)
Apr 26, 2001
Apr 26, 2001
62
{
May 28, 2006
May 28, 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
May 28, 2006
May 28, 2006
66
67
68
struct sigaction action;
for (i = 0; SDL_fatal_signals[i]; ++i) {
May 29, 2006
May 29, 2006
69
sigaction(SDL_fatal_signals[i], NULL, &action);
May 28, 2006
May 28, 2006
70
71
if (action.sa_handler == SIG_DFL) {
action.sa_handler = SDL_Parachute;
May 29, 2006
May 29, 2006
72
sigaction(SDL_fatal_signals[i], &action, NULL);
May 28, 2006
May 28, 2006
73
74
}
}
Apr 26, 2001
Apr 26, 2001
75
#ifdef SIGALRM
May 28, 2006
May 28, 2006
76
/* Set SIGALRM to be ignored -- necessary on Solaris */
May 29, 2006
May 29, 2006
77
sigaction(SIGALRM, NULL, &action);
May 28, 2006
May 28, 2006
78
79
if (action.sa_handler == SIG_DFL) {
action.sa_handler = SIG_IGN;
May 29, 2006
May 29, 2006
80
sigaction(SIGALRM, &action, NULL);
May 28, 2006
May 28, 2006
81
}
Feb 12, 2004
Feb 12, 2004
82
83
#endif
#else
May 28, 2006
May 28, 2006
84
85
86
void (*ohandler) (int);
for (i = 0; SDL_fatal_signals[i]; ++i) {
May 29, 2006
May 29, 2006
87
ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
May 28, 2006
May 28, 2006
88
if (ohandler != SIG_DFL) {
May 29, 2006
May 29, 2006
89
signal(SDL_fatal_signals[i], ohandler);
May 28, 2006
May 28, 2006
90
91
}
}
Feb 12, 2004
Feb 12, 2004
92
#endif /* HAVE_SIGACTION */
May 28, 2006
May 28, 2006
93
return;
Apr 26, 2001
Apr 26, 2001
94
95
}
May 28, 2006
May 28, 2006
96
void
May 29, 2006
May 29, 2006
97
SDL_UninstallParachute(void)
Apr 26, 2001
Apr 26, 2001
98
{
May 28, 2006
May 28, 2006
99
100
/* Remove a handler for any fatal signal handled */
int i;
Feb 12, 2004
Feb 12, 2004
101
#ifdef HAVE_SIGACTION
May 28, 2006
May 28, 2006
102
103
104
struct sigaction action;
for (i = 0; SDL_fatal_signals[i]; ++i) {
May 29, 2006
May 29, 2006
105
sigaction(SDL_fatal_signals[i], NULL, &action);
May 28, 2006
May 28, 2006
106
107
if (action.sa_handler == SDL_Parachute) {
action.sa_handler = SIG_DFL;
May 29, 2006
May 29, 2006
108
sigaction(SDL_fatal_signals[i], &action, NULL);
May 28, 2006
May 28, 2006
109
110
}
}
Feb 12, 2004
Feb 12, 2004
111
#else
May 28, 2006
May 28, 2006
112
113
114
void (*ohandler) (int);
for (i = 0; SDL_fatal_signals[i]; ++i) {
May 29, 2006
May 29, 2006
115
ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
May 28, 2006
May 28, 2006
116
if (ohandler != SDL_Parachute) {
May 29, 2006
May 29, 2006
117
signal(SDL_fatal_signals[i], ohandler);
May 28, 2006
May 28, 2006
118
119
}
}
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.. */
May 28, 2006
May 28, 2006
127
void
May 29, 2006
May 29, 2006
128
SDL_InstallParachute(void)
Feb 6, 2006
Feb 6, 2006
129
{
May 28, 2006
May 28, 2006
130
return;
Feb 6, 2006
Feb 6, 2006
131
132
}
May 28, 2006
May 28, 2006
133
void
May 29, 2006
May 29, 2006
134
SDL_UninstallParachute(void)
Feb 6, 2006
Feb 6, 2006
135
{
May 28, 2006
May 28, 2006
136
return;
Feb 6, 2006
Feb 6, 2006
137
138
139
}
#endif /* HAVE_SIGNAL_H */
May 28, 2006
May 28, 2006
140
/* vi: set ts=4 sw=4 expandtab: */