comparison src/SDL_fatal.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents d910939febfa
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
33 /* This installs some signal handlers for the more common fatal signals, 33 /* This installs some signal handlers for the more common fatal signals,
34 so that if the programmer is lazy, the app doesn't die so horribly if 34 so that if the programmer is lazy, the app doesn't die so horribly if
35 the program crashes. 35 the program crashes.
36 */ 36 */
37 37
38 static void SDL_Parachute(int sig) 38 static void
39 SDL_Parachute (int sig)
39 { 40 {
40 signal(sig, SIG_DFL); 41 signal (sig, SIG_DFL);
41 SDL_Quit(); 42 SDL_Quit ();
42 raise(sig); 43 raise (sig);
43 } 44 }
44 45
45 static int SDL_fatal_signals[] = { 46 static int SDL_fatal_signals[] = {
46 SIGSEGV, 47 SIGSEGV,
47 #ifdef SIGBUS 48 #ifdef SIGBUS
48 SIGBUS, 49 SIGBUS,
49 #endif 50 #endif
50 #ifdef SIGFPE 51 #ifdef SIGFPE
51 SIGFPE, 52 SIGFPE,
52 #endif 53 #endif
53 #ifdef SIGQUIT 54 #ifdef SIGQUIT
54 SIGQUIT, 55 SIGQUIT,
55 #endif 56 #endif
56 0 57 0
57 }; 58 };
58 59
59 void SDL_InstallParachute(void) 60 void
61 SDL_InstallParachute (void)
60 { 62 {
61 /* Set a handler for any fatal signal not already handled */ 63 /* Set a handler for any fatal signal not already handled */
62 int i; 64 int i;
63 #ifdef HAVE_SIGACTION 65 #ifdef HAVE_SIGACTION
64 struct sigaction action; 66 struct sigaction action;
65 67
66 for ( i=0; SDL_fatal_signals[i]; ++i ) { 68 for (i = 0; SDL_fatal_signals[i]; ++i) {
67 sigaction(SDL_fatal_signals[i], NULL, &action); 69 sigaction (SDL_fatal_signals[i], NULL, &action);
68 if ( action.sa_handler == SIG_DFL ) { 70 if (action.sa_handler == SIG_DFL) {
69 action.sa_handler = SDL_Parachute; 71 action.sa_handler = SDL_Parachute;
70 sigaction(SDL_fatal_signals[i], &action, NULL); 72 sigaction (SDL_fatal_signals[i], &action, NULL);
71 } 73 }
72 } 74 }
73 #ifdef SIGALRM 75 #ifdef SIGALRM
74 /* Set SIGALRM to be ignored -- necessary on Solaris */ 76 /* Set SIGALRM to be ignored -- necessary on Solaris */
75 sigaction(SIGALRM, NULL, &action); 77 sigaction (SIGALRM, NULL, &action);
76 if ( action.sa_handler == SIG_DFL ) { 78 if (action.sa_handler == SIG_DFL) {
77 action.sa_handler = SIG_IGN; 79 action.sa_handler = SIG_IGN;
78 sigaction(SIGALRM, &action, NULL); 80 sigaction (SIGALRM, &action, NULL);
79 } 81 }
80 #endif 82 #endif
81 #else 83 #else
82 void (*ohandler)(int); 84 void (*ohandler) (int);
83 85
84 for ( i=0; SDL_fatal_signals[i]; ++i ) { 86 for (i = 0; SDL_fatal_signals[i]; ++i) {
85 ohandler = signal(SDL_fatal_signals[i], SDL_Parachute); 87 ohandler = signal (SDL_fatal_signals[i], SDL_Parachute);
86 if ( ohandler != SIG_DFL ) { 88 if (ohandler != SIG_DFL) {
87 signal(SDL_fatal_signals[i], ohandler); 89 signal (SDL_fatal_signals[i], ohandler);
88 } 90 }
89 } 91 }
90 #endif /* HAVE_SIGACTION */ 92 #endif /* HAVE_SIGACTION */
91 return; 93 return;
92 } 94 }
93 95
94 void SDL_UninstallParachute(void) 96 void
97 SDL_UninstallParachute (void)
95 { 98 {
96 /* Remove a handler for any fatal signal handled */ 99 /* Remove a handler for any fatal signal handled */
97 int i; 100 int i;
98 #ifdef HAVE_SIGACTION 101 #ifdef HAVE_SIGACTION
99 struct sigaction action; 102 struct sigaction action;
100 103
101 for ( i=0; SDL_fatal_signals[i]; ++i ) { 104 for (i = 0; SDL_fatal_signals[i]; ++i) {
102 sigaction(SDL_fatal_signals[i], NULL, &action); 105 sigaction (SDL_fatal_signals[i], NULL, &action);
103 if ( action.sa_handler == SDL_Parachute ) { 106 if (action.sa_handler == SDL_Parachute) {
104 action.sa_handler = SIG_DFL; 107 action.sa_handler = SIG_DFL;
105 sigaction(SDL_fatal_signals[i], &action, NULL); 108 sigaction (SDL_fatal_signals[i], &action, NULL);
106 } 109 }
107 } 110 }
108 #else 111 #else
109 void (*ohandler)(int); 112 void (*ohandler) (int);
110 113
111 for ( i=0; SDL_fatal_signals[i]; ++i ) { 114 for (i = 0; SDL_fatal_signals[i]; ++i) {
112 ohandler = signal(SDL_fatal_signals[i], SIG_DFL); 115 ohandler = signal (SDL_fatal_signals[i], SIG_DFL);
113 if ( ohandler != SDL_Parachute ) { 116 if (ohandler != SDL_Parachute) {
114 signal(SDL_fatal_signals[i], ohandler); 117 signal (SDL_fatal_signals[i], ohandler);
115 } 118 }
116 } 119 }
117 #endif /* HAVE_SIGACTION */ 120 #endif /* HAVE_SIGACTION */
118 } 121 }
119 122
120 #else 123 #else
121 124
122 /* No signals on this platform, nothing to do.. */ 125 /* No signals on this platform, nothing to do.. */
123 126
124 void SDL_InstallParachute(void) 127 void
128 SDL_InstallParachute (void)
125 { 129 {
126 return; 130 return;
127 } 131 }
128 132
129 void SDL_UninstallParachute(void) 133 void
134 SDL_UninstallParachute (void)
130 { 135 {
131 return; 136 return;
132 } 137 }
133 138
134 #endif /* HAVE_SIGNAL_H */ 139 #endif /* HAVE_SIGNAL_H */
140 /* vi: set ts=4 sw=4 expandtab: */