Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
authorSam Lantinga <slouken@libsdl.org>
Thu, 12 Feb 2004 16:29:24 +0000
changeset 8145a417d2a8603
parent 813 6a2c6717b386
child 815 6176f9a0d61a
Use sigaction instead of signal to preserve handler flags (thanks Matthew!)
configure.in
src/SDL_fatal.c
     1.1 --- a/configure.in	Thu Feb 12 16:05:30 2004 +0000
     1.2 +++ b/configure.in	Thu Feb 12 16:29:24 2004 +0000
     1.3 @@ -763,6 +763,7 @@
     1.4  [  --enable-video-fbcon    use framebuffer console video driver [default=yes]],
     1.5                    , enable_video_fbcon=yes)
     1.6      if test x$enable_video = xyes -a x$enable_video_fbcon = xyes; then
     1.7 +        CFLAGS="$CFLAGS -D__KERNEL_STRICT_NAMES"
     1.8          AC_MSG_CHECKING(for framebuffer console support)
     1.9          video_fbcon=no
    1.10          AC_TRY_COMPILE([
    1.11 @@ -1387,6 +1388,31 @@
    1.12      fi
    1.13  }
    1.14  
    1.15 +dnl See if we can use sigaction() instead of signal()
    1.16 +CheckSIGACTION()
    1.17 +{
    1.18 +    dnl Check for sigaction support
    1.19 +    AC_ARG_ENABLE(sigaction,
    1.20 +[  --enable-sigaction      use sigaction instead of signal [default=yes]],
    1.21 +                  , enable_sigaction=yes)
    1.22 +    if test x$enable_sigaction = xyes; then
    1.23 +        AC_MSG_CHECKING(sigaction)
    1.24 +        have_sigaction=no
    1.25 +        AC_TRY_COMPILE([
    1.26 +         #include <signal.h>
    1.27 +        ],[
    1.28 +         struct sigaction junk;
    1.29 +         sigaction(0, &junk, &junk);
    1.30 +        ],[
    1.31 +        have_sigaction=yes
    1.32 +        ])
    1.33 +        AC_MSG_RESULT($have_sigaction)
    1.34 +        if test x$have_sigaction = xyes; then
    1.35 +            CFLAGS="$CFLAGS -DHAVE_SIGACTION"
    1.36 +        fi
    1.37 +    fi
    1.38 +}
    1.39 +
    1.40  dnl Determine whether the compiler can produce Win32 executables
    1.41  CheckWIN32()
    1.42  {
    1.43 @@ -1775,6 +1801,7 @@
    1.44          CheckOpenGL
    1.45          CheckInputEvents
    1.46          CheckPTHREAD
    1.47 +        CheckSIGACTION
    1.48          CheckAltivec
    1.49          # Set up files for the main() stub
    1.50          if test "x$video_qtopia" = "xyes"; then
    1.51 @@ -1851,6 +1878,7 @@
    1.52          CheckAAlib
    1.53          CheckOpenGL
    1.54          CheckPTHREAD
    1.55 +        CheckSIGACTION
    1.56          # Set up files for the audio library
    1.57          # We use the OSS and ALSA API's, not the Sun audio API
    1.58          #if test x$enable_audio = xyes; then
    1.59 @@ -1895,6 +1923,7 @@
    1.60          CheckAAlib
    1.61          CheckOpenGL
    1.62          CheckPTHREAD
    1.63 +        CheckSIGACTION
    1.64          CheckUSBHID
    1.65          # Set up files for the audio library
    1.66          # We use the OSS and ALSA API's, not the Sun audio API
    1.67 @@ -1931,6 +1960,7 @@
    1.68          CheckAAlib
    1.69          CheckOpenGL
    1.70          CheckPTHREAD
    1.71 +        CheckSIGACTION
    1.72          CheckUSBHID
    1.73          # Set up files for the audio library
    1.74          if test x$enable_audio = xyes; then
    1.75 @@ -1971,6 +2001,7 @@
    1.76          CheckAAlib
    1.77          CheckOpenGL
    1.78          CheckPTHREAD
    1.79 +        CheckSIGACTION
    1.80          CheckUSBHID
    1.81          # Set up files for the audio library
    1.82          if test x$enable_audio = xyes; then
    1.83 @@ -2012,6 +2043,7 @@
    1.84          CheckAAlib
    1.85          CheckOpenGL
    1.86          CheckPTHREAD
    1.87 +        CheckSIGACTION
    1.88          # Set up files for the audio library
    1.89          if test x$enable_audio = xyes; then
    1.90              CFLAGS="$CFLAGS -DSUNAUDIO_SUPPORT"
    1.91 @@ -2053,6 +2085,7 @@
    1.92          CheckAAlib
    1.93          CheckOpenGL
    1.94          CheckPTHREAD
    1.95 +        CheckSIGACTION
    1.96          # Set up files for the audio library
    1.97          if test x$enable_audio = xyes; then
    1.98              CFLAGS="$CFLAGS -DSUNAUDIO_SUPPORT"
    1.99 @@ -2091,6 +2124,7 @@
   1.100          CheckAAlib
   1.101          CheckOpenGL
   1.102          CheckPTHREAD
   1.103 +        CheckSIGACTION
   1.104          # We use the dmedia audio API, not the Sun audio API
   1.105          #if test x$enable_audio = xyes; then
   1.106          #    CFLAGS="$CFLAGS -DSUNAUDIO_SUPPORT"
   1.107 @@ -2141,6 +2175,7 @@
   1.108          CheckAAlib
   1.109          CheckOpenGL
   1.110          CheckPTHREAD
   1.111 +        CheckSIGACTION
   1.112          # Set up files for the audio library
   1.113          if test x$enable_audio = xyes; then
   1.114              CFLAGS="$CFLAGS -DSUNAUDIO_SUPPORT"
   1.115 @@ -2180,6 +2215,7 @@
   1.116          CheckAAlib
   1.117          CheckOpenGL
   1.118          CheckPTHREAD
   1.119 +        CheckSIGACTION
   1.120          # Set up files for the audio library
   1.121          if test x$enable_audio = xyes; then
   1.122              AUDIO_SUBDIRS="$AUDIO_SUBDIRS paudio"
   1.123 @@ -2216,6 +2252,7 @@
   1.124          CheckAAlib
   1.125          CheckOpenGL
   1.126          CheckPTHREAD
   1.127 +        CheckSIGACTION
   1.128          SDL_LIBS="$SDL_LIBS -lrt"
   1.129          # Set up files for the audio library
   1.130          if test x$enable_audio = xyes; then
   1.131 @@ -2255,6 +2292,7 @@
   1.132          CheckX11
   1.133          CheckOpenGL
   1.134          CheckPTHREAD
   1.135 +        CheckSIGACTION
   1.136          # Set up files for the audio library
   1.137          if test x$enable_audio = xyes; then
   1.138              CFLAGS="$CFLAGS -DQNXNTOAUDIO_SUPPORT"
   1.139 @@ -2440,6 +2478,7 @@
   1.140          CheckQUARTZ
   1.141          CheckMacGL
   1.142          CheckPTHREAD
   1.143 +        CheckSIGACTION
   1.144          # Set up files for the audio library
   1.145          if test x$enable_audio = xyes; then
   1.146              AUDIO_SUBDIRS="$AUDIO_SUBDIRS macrom"
     2.1 --- a/src/SDL_fatal.c	Thu Feb 12 16:05:30 2004 +0000
     2.2 +++ b/src/SDL_fatal.c	Thu Feb 12 16:29:24 2004 +0000
     2.3 @@ -127,47 +127,63 @@
     2.4  
     2.5  void SDL_InstallParachute(void)
     2.6  {
     2.7 +	/* Set a handler for any fatal signal not already handled */
     2.8  	int i;
     2.9 +#ifdef HAVE_SIGACTION
    2.10 +	struct sigaction action;
    2.11 +
    2.12 +	for ( i=0; SDL_fatal_signals[i]; ++i ) {
    2.13 +		sigaction(SDL_fatal_signals[i], NULL, &action);
    2.14 +		if ( action.sa_handler == SIG_DFL ) {
    2.15 +			action.sa_handler = SDL_Parachute;
    2.16 +			sigaction(SDL_fatal_signals[i], &action, NULL);
    2.17 +		}
    2.18 +	}
    2.19 +#ifdef SIGALRM
    2.20 +	/* Set SIGALRM to be ignored -- necessary on Solaris */
    2.21 +	sigaction(SIGALRM, NULL, &action);
    2.22 +	if ( action.sa_handler == SIG_DFL ) {
    2.23 +		action.sa_handler = SIG_IGN;
    2.24 +		sigaction(SDL_fatal_signals[i], &action, NULL);
    2.25 +	}
    2.26 +#endif
    2.27 +#else
    2.28  	void (*ohandler)(int);
    2.29  
    2.30 -	/* Set a handler for any fatal signal not already handled */
    2.31  	for ( i=0; SDL_fatal_signals[i]; ++i ) {
    2.32  		ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
    2.33  		if ( ohandler != SIG_DFL ) {
    2.34  			signal(SDL_fatal_signals[i], ohandler);
    2.35  		}
    2.36  	}
    2.37 -#ifdef SIGALRM
    2.38 -	/* Set SIGALRM to be ignored -- necessary on Solaris */
    2.39 -	{
    2.40 -		struct sigaction action, oaction;
    2.41 -
    2.42 -		/* Set SIG_IGN action */
    2.43 -		memset(&action, 0, (sizeof action));
    2.44 -		action.sa_handler = SIG_IGN;
    2.45 -		sigaction(SIGALRM, &action, &oaction);
    2.46 -
    2.47 -		/* Reset original action if it was already being handled */
    2.48 -		if ( oaction.sa_handler != SIG_DFL ) {
    2.49 -			sigaction(SIGALRM, &oaction, NULL);
    2.50 -		}
    2.51 -	}
    2.52 -#endif
    2.53 +#endif /* HAVE_SIGACTION */
    2.54  	return;
    2.55  }
    2.56  
    2.57  void SDL_UninstallParachute(void)
    2.58  {
    2.59 +	/* Remove a handler for any fatal signal handled */
    2.60  	int i;
    2.61 +#ifdef HAVE_SIGACTION
    2.62 +	struct sigaction action;
    2.63 +
    2.64 +	for ( i=0; SDL_fatal_signals[i]; ++i ) {
    2.65 +		sigaction(SDL_fatal_signals[i], NULL, &action);
    2.66 +		if ( action.sa_handler == SDL_Parachute ) {
    2.67 +			action.sa_handler = SIG_DFL;
    2.68 +			sigaction(SDL_fatal_signals[i], &action, NULL);
    2.69 +		}
    2.70 +	}
    2.71 +#else
    2.72  	void (*ohandler)(int);
    2.73  
    2.74 -	/* Remove a handler for any fatal signal handled */
    2.75  	for ( i=0; SDL_fatal_signals[i]; ++i ) {
    2.76  		ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
    2.77  		if ( ohandler != SDL_Parachute ) {
    2.78  			signal(SDL_fatal_signals[i], ohandler);
    2.79  		}
    2.80  	}
    2.81 +#endif /* HAVE_SIGACTION */
    2.82  }
    2.83  
    2.84  #endif /* NO_SIGNAL_H */