src/SDL_fatal.c
changeset 814 5a417d2a8603
parent 769 b8d311d90021
child 822 abb915adb1b0
     1.1 --- a/src/SDL_fatal.c	Thu Feb 12 16:05:30 2004 +0000
     1.2 +++ b/src/SDL_fatal.c	Thu Feb 12 16:29:24 2004 +0000
     1.3 @@ -127,47 +127,63 @@
     1.4  
     1.5  void SDL_InstallParachute(void)
     1.6  {
     1.7 +	/* Set a handler for any fatal signal not already handled */
     1.8  	int i;
     1.9 +#ifdef HAVE_SIGACTION
    1.10 +	struct sigaction action;
    1.11 +
    1.12 +	for ( i=0; SDL_fatal_signals[i]; ++i ) {
    1.13 +		sigaction(SDL_fatal_signals[i], NULL, &action);
    1.14 +		if ( action.sa_handler == SIG_DFL ) {
    1.15 +			action.sa_handler = SDL_Parachute;
    1.16 +			sigaction(SDL_fatal_signals[i], &action, NULL);
    1.17 +		}
    1.18 +	}
    1.19 +#ifdef SIGALRM
    1.20 +	/* Set SIGALRM to be ignored -- necessary on Solaris */
    1.21 +	sigaction(SIGALRM, NULL, &action);
    1.22 +	if ( action.sa_handler == SIG_DFL ) {
    1.23 +		action.sa_handler = SIG_IGN;
    1.24 +		sigaction(SDL_fatal_signals[i], &action, NULL);
    1.25 +	}
    1.26 +#endif
    1.27 +#else
    1.28  	void (*ohandler)(int);
    1.29  
    1.30 -	/* Set a handler for any fatal signal not already handled */
    1.31  	for ( i=0; SDL_fatal_signals[i]; ++i ) {
    1.32  		ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
    1.33  		if ( ohandler != SIG_DFL ) {
    1.34  			signal(SDL_fatal_signals[i], ohandler);
    1.35  		}
    1.36  	}
    1.37 -#ifdef SIGALRM
    1.38 -	/* Set SIGALRM to be ignored -- necessary on Solaris */
    1.39 -	{
    1.40 -		struct sigaction action, oaction;
    1.41 -
    1.42 -		/* Set SIG_IGN action */
    1.43 -		memset(&action, 0, (sizeof action));
    1.44 -		action.sa_handler = SIG_IGN;
    1.45 -		sigaction(SIGALRM, &action, &oaction);
    1.46 -
    1.47 -		/* Reset original action if it was already being handled */
    1.48 -		if ( oaction.sa_handler != SIG_DFL ) {
    1.49 -			sigaction(SIGALRM, &oaction, NULL);
    1.50 -		}
    1.51 -	}
    1.52 -#endif
    1.53 +#endif /* HAVE_SIGACTION */
    1.54  	return;
    1.55  }
    1.56  
    1.57  void SDL_UninstallParachute(void)
    1.58  {
    1.59 +	/* Remove a handler for any fatal signal handled */
    1.60  	int i;
    1.61 +#ifdef HAVE_SIGACTION
    1.62 +	struct sigaction action;
    1.63 +
    1.64 +	for ( i=0; SDL_fatal_signals[i]; ++i ) {
    1.65 +		sigaction(SDL_fatal_signals[i], NULL, &action);
    1.66 +		if ( action.sa_handler == SDL_Parachute ) {
    1.67 +			action.sa_handler = SIG_DFL;
    1.68 +			sigaction(SDL_fatal_signals[i], &action, NULL);
    1.69 +		}
    1.70 +	}
    1.71 +#else
    1.72  	void (*ohandler)(int);
    1.73  
    1.74 -	/* Remove a handler for any fatal signal handled */
    1.75  	for ( i=0; SDL_fatal_signals[i]; ++i ) {
    1.76  		ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
    1.77  		if ( ohandler != SDL_Parachute ) {
    1.78  			signal(SDL_fatal_signals[i], ohandler);
    1.79  		}
    1.80  	}
    1.81 +#endif /* HAVE_SIGACTION */
    1.82  }
    1.83  
    1.84  #endif /* NO_SIGNAL_H */