Added a hint to prevent SDL from installing signal handlers.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 24 Mar 2015 14:29:25 -0400
changeset 94340a695c9c3c71
parent 9433 bd062398b648
child 9435 0979c3e31211
Added a hint to prevent SDL from installing signal handlers.

Fixes Bugzilla #2431.
include/SDL_hints.h
src/events/SDL_quit.c
     1.1 --- a/include/SDL_hints.h	Tue Mar 24 13:52:01 2015 -0400
     1.2 +++ b/include/SDL_hints.h	Tue Mar 24 14:29:25 2015 -0400
     1.3 @@ -547,6 +547,18 @@
     1.4  #define SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT   "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT"
     1.5  
     1.6  /**
     1.7 + *  \brief Tell SDL not to handle SIGINT.
     1.8 + *
     1.9 + * This hint only applies to Unix-like platforms.
    1.10 + *
    1.11 + * The variable can be set to the following values:
    1.12 + *   "0"       - SDL will install a SIGINT handler, and when it catches the
    1.13 + *               signal, conver it into an SDL_QUIT event.
    1.14 + *   "1"       - SDL will not install a SIGINT handler.
    1.15 + */
    1.16 +#define SDL_HINT_DISABLE_SIGINT_HANDLER   "SDL_DISABLE_SIGINT_HANDLER"
    1.17 +
    1.18 +/**
    1.19   *  \brief  An enumeration of hint priorities
    1.20   */
    1.21  typedef enum
     2.1 --- a/src/events/SDL_quit.c	Tue Mar 24 13:52:01 2015 -0400
     2.2 +++ b/src/events/SDL_quit.c	Tue Mar 24 14:29:25 2015 -0400
     2.3 @@ -19,6 +19,7 @@
     2.4    3. This notice may not be removed or altered from any source distribution.
     2.5  */
     2.6  #include "../SDL_internal.h"
     2.7 +#include "SDL_hints.h"
     2.8  
     2.9  /* General quit handling code for SDL */
    2.10  
    2.11 @@ -30,6 +31,8 @@
    2.12  #include "SDL_events_c.h"
    2.13  
    2.14  
    2.15 +static SDL_bool disable_signals = SDL_FALSE;
    2.16 +
    2.17  #ifdef HAVE_SIGNAL_H
    2.18  static void
    2.19  SDL_HandleSIG(int sig)
    2.20 @@ -46,6 +49,12 @@
    2.21  int
    2.22  SDL_QuitInit(void)
    2.23  {
    2.24 +    const char *hint = SDL_GetHint(SDL_HINT_DISABLE_SIGINT_HANDLER);
    2.25 +    disable_signals = hint && (SDL_atoi(hint) == 1);
    2.26 +    if (disable_signals) {
    2.27 +        return 0;
    2.28 +    }
    2.29 +
    2.30  #ifdef HAVE_SIGACTION
    2.31      struct sigaction action;
    2.32      sigaction(SIGINT, NULL, &action);
    2.33 @@ -80,12 +89,16 @@
    2.34  #endif /* HAVE_SIGNAL_H */
    2.35  
    2.36      /* That's it! */
    2.37 -    return (0);
    2.38 +    return 0;
    2.39  }
    2.40  
    2.41  void
    2.42  SDL_QuitQuit(void)
    2.43  {
    2.44 +    if (disable_signals) {
    2.45 +        return;
    2.46 +    }
    2.47 +
    2.48  #ifdef HAVE_SIGACTION
    2.49      struct sigaction action;
    2.50      sigaction(SIGINT, NULL, &action);