Removing old dangerous signal catching code.
authorSam Lantinga <slouken@libsdl.org>
Fri, 28 Jun 2013 22:49:03 -0700
changeset 7336b0ef4d043c7b
parent 7335 13b67be8e3af
child 7337 5ba1fafc6a94
Removing old dangerous signal catching code.
* None of the supported platforms are hosed if the program crashes without cleaning up the graphics display connection.
* It's very likely to be unsafe to call SDL_Quit() at an arbitrary point from an arbitrary thread.
* Catching signals can prevent applications from getting correct stack traces from crashes.
src/SDL_fatal.c
     1.1 --- a/src/SDL_fatal.c	Fri Jun 28 22:44:49 2013 -0700
     1.2 +++ b/src/SDL_fatal.c	Fri Jun 28 22:49:03 2013 -0700
     1.3 @@ -20,108 +20,6 @@
     1.4  */
     1.5  #include "SDL_config.h"
     1.6  
     1.7 -/* General fatal signal handling code for SDL */
     1.8 -
     1.9 -#ifdef HAVE_SIGNAL_H
    1.10 -
    1.11 -#include <signal.h>
    1.12 -
    1.13 -#include "SDL.h"
    1.14 -#include "SDL_fatal.h"
    1.15 -
    1.16 -/* This installs some signal handlers for the more common fatal signals,
    1.17 -   so that if the programmer is lazy, the app doesn't die so horribly if
    1.18 -   the program crashes.
    1.19 -*/
    1.20 -
    1.21 -static void
    1.22 -SDL_Parachute(int sig)
    1.23 -{
    1.24 -    signal(sig, SIG_DFL);
    1.25 -    SDL_Quit();
    1.26 -    raise(sig);
    1.27 -}
    1.28 -
    1.29 -static const int SDL_fatal_signals[] = {
    1.30 -    SIGSEGV,
    1.31 -#ifdef SIGBUS
    1.32 -    SIGBUS,
    1.33 -#endif
    1.34 -#ifdef SIGFPE
    1.35 -    SIGFPE,
    1.36 -#endif
    1.37 -#ifdef SIGQUIT
    1.38 -    SIGQUIT,
    1.39 -#endif
    1.40 -    0
    1.41 -};
    1.42 -
    1.43 -void
    1.44 -SDL_InstallParachute(void)
    1.45 -{
    1.46 -    /* Set a handler for any fatal signal not already handled */
    1.47 -    int i;
    1.48 -#ifdef HAVE_SIGACTION
    1.49 -    struct sigaction action;
    1.50 -
    1.51 -    for (i = 0; SDL_fatal_signals[i]; ++i) {
    1.52 -        sigaction(SDL_fatal_signals[i], NULL, &action);
    1.53 -        if (action.sa_handler == SIG_DFL) {
    1.54 -            action.sa_handler = SDL_Parachute;
    1.55 -            sigaction(SDL_fatal_signals[i], &action, NULL);
    1.56 -        }
    1.57 -    }
    1.58 -#ifdef SIGALRM
    1.59 -    /* Set SIGALRM to be ignored -- necessary on Solaris */
    1.60 -    sigaction(SIGALRM, NULL, &action);
    1.61 -    if (action.sa_handler == SIG_DFL) {
    1.62 -        action.sa_handler = SIG_IGN;
    1.63 -        sigaction(SIGALRM, &action, NULL);
    1.64 -    }
    1.65 -#endif
    1.66 -#else
    1.67 -    void (*ohandler) (int);
    1.68 -
    1.69 -    for (i = 0; SDL_fatal_signals[i]; ++i) {
    1.70 -        ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
    1.71 -        if (ohandler != SIG_DFL) {
    1.72 -            signal(SDL_fatal_signals[i], ohandler);
    1.73 -        }
    1.74 -    }
    1.75 -#endif /* HAVE_SIGACTION */
    1.76 -    return;
    1.77 -}
    1.78 -
    1.79 -void
    1.80 -SDL_UninstallParachute(void)
    1.81 -{
    1.82 -    /* Remove a handler for any fatal signal handled */
    1.83 -    int i;
    1.84 -#ifdef HAVE_SIGACTION
    1.85 -    struct sigaction action;
    1.86 -
    1.87 -    for (i = 0; SDL_fatal_signals[i]; ++i) {
    1.88 -        sigaction(SDL_fatal_signals[i], NULL, &action);
    1.89 -        if (action.sa_handler == SDL_Parachute) {
    1.90 -            action.sa_handler = SIG_DFL;
    1.91 -            sigaction(SDL_fatal_signals[i], &action, NULL);
    1.92 -        }
    1.93 -    }
    1.94 -#else
    1.95 -    void (*ohandler) (int);
    1.96 -
    1.97 -    for (i = 0; SDL_fatal_signals[i]; ++i) {
    1.98 -        ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
    1.99 -        if (ohandler != SDL_Parachute) {
   1.100 -            signal(SDL_fatal_signals[i], ohandler);
   1.101 -        }
   1.102 -    }
   1.103 -#endif /* HAVE_SIGACTION */
   1.104 -}
   1.105 -
   1.106 -#else
   1.107 -
   1.108 -/* No signals on this platform, nothing to do.. */
   1.109  
   1.110  void
   1.111  SDL_InstallParachute(void)
   1.112 @@ -135,5 +33,4 @@
   1.113      return;
   1.114  }
   1.115  
   1.116 -#endif /* HAVE_SIGNAL_H */
   1.117  /* vi: set ts=4 sw=4 expandtab: */