comparison src/SDL_fatal.c @ 814:5a417d2a8603

Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
author Sam Lantinga <slouken@libsdl.org>
date Thu, 12 Feb 2004 16:29:24 +0000
parents b8d311d90021
children abb915adb1b0
comparison
equal deleted inserted replaced
813:6a2c6717b386 814:5a417d2a8603
125 0 125 0
126 }; 126 };
127 127
128 void SDL_InstallParachute(void) 128 void SDL_InstallParachute(void)
129 { 129 {
130 /* Set a handler for any fatal signal not already handled */
130 int i; 131 int i;
132 #ifdef HAVE_SIGACTION
133 struct sigaction action;
134
135 for ( i=0; SDL_fatal_signals[i]; ++i ) {
136 sigaction(SDL_fatal_signals[i], NULL, &action);
137 if ( action.sa_handler == SIG_DFL ) {
138 action.sa_handler = SDL_Parachute;
139 sigaction(SDL_fatal_signals[i], &action, NULL);
140 }
141 }
142 #ifdef SIGALRM
143 /* Set SIGALRM to be ignored -- necessary on Solaris */
144 sigaction(SIGALRM, NULL, &action);
145 if ( action.sa_handler == SIG_DFL ) {
146 action.sa_handler = SIG_IGN;
147 sigaction(SDL_fatal_signals[i], &action, NULL);
148 }
149 #endif
150 #else
131 void (*ohandler)(int); 151 void (*ohandler)(int);
132 152
133 /* Set a handler for any fatal signal not already handled */
134 for ( i=0; SDL_fatal_signals[i]; ++i ) { 153 for ( i=0; SDL_fatal_signals[i]; ++i ) {
135 ohandler = signal(SDL_fatal_signals[i], SDL_Parachute); 154 ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
136 if ( ohandler != SIG_DFL ) { 155 if ( ohandler != SIG_DFL ) {
137 signal(SDL_fatal_signals[i], ohandler); 156 signal(SDL_fatal_signals[i], ohandler);
138 } 157 }
139 } 158 }
140 #ifdef SIGALRM 159 #endif /* HAVE_SIGACTION */
141 /* Set SIGALRM to be ignored -- necessary on Solaris */
142 {
143 struct sigaction action, oaction;
144
145 /* Set SIG_IGN action */
146 memset(&action, 0, (sizeof action));
147 action.sa_handler = SIG_IGN;
148 sigaction(SIGALRM, &action, &oaction);
149
150 /* Reset original action if it was already being handled */
151 if ( oaction.sa_handler != SIG_DFL ) {
152 sigaction(SIGALRM, &oaction, NULL);
153 }
154 }
155 #endif
156 return; 160 return;
157 } 161 }
158 162
159 void SDL_UninstallParachute(void) 163 void SDL_UninstallParachute(void)
160 { 164 {
165 /* Remove a handler for any fatal signal handled */
161 int i; 166 int i;
167 #ifdef HAVE_SIGACTION
168 struct sigaction action;
169
170 for ( i=0; SDL_fatal_signals[i]; ++i ) {
171 sigaction(SDL_fatal_signals[i], NULL, &action);
172 if ( action.sa_handler == SDL_Parachute ) {
173 action.sa_handler = SIG_DFL;
174 sigaction(SDL_fatal_signals[i], &action, NULL);
175 }
176 }
177 #else
162 void (*ohandler)(int); 178 void (*ohandler)(int);
163 179
164 /* Remove a handler for any fatal signal handled */
165 for ( i=0; SDL_fatal_signals[i]; ++i ) { 180 for ( i=0; SDL_fatal_signals[i]; ++i ) {
166 ohandler = signal(SDL_fatal_signals[i], SIG_DFL); 181 ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
167 if ( ohandler != SDL_Parachute ) { 182 if ( ohandler != SDL_Parachute ) {
168 signal(SDL_fatal_signals[i], ohandler); 183 signal(SDL_fatal_signals[i], ohandler);
169 } 184 }
170 } 185 }
186 #endif /* HAVE_SIGACTION */
171 } 187 }
172 188
173 #endif /* NO_SIGNAL_H */ 189 #endif /* NO_SIGNAL_H */