Added a hint to prevent SDL from installing signal handlers. Fixes Bugzilla #2431.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index a3508ff..2ffeb3b 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -547,6 +547,18 @@ extern "C" {
#define SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT"
/**
+ * \brief Tell SDL not to handle SIGINT.
+ *
+ * This hint only applies to Unix-like platforms.
+ *
+ * The variable can be set to the following values:
+ * "0" - SDL will install a SIGINT handler, and when it catches the
+ * signal, conver it into an SDL_QUIT event.
+ * "1" - SDL will not install a SIGINT handler.
+ */
+#define SDL_HINT_DISABLE_SIGINT_HANDLER "SDL_DISABLE_SIGINT_HANDLER"
+
+/**
* \brief An enumeration of hint priorities
*/
typedef enum
diff --git a/src/events/SDL_quit.c b/src/events/SDL_quit.c
index db7af98..c1ece1c 100644
--- a/src/events/SDL_quit.c
+++ b/src/events/SDL_quit.c
@@ -19,6 +19,7 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
+#include "SDL_hints.h"
/* General quit handling code for SDL */
@@ -30,6 +31,8 @@
#include "SDL_events_c.h"
+static SDL_bool disable_signals = SDL_FALSE;
+
#ifdef HAVE_SIGNAL_H
static void
SDL_HandleSIG(int sig)
@@ -46,6 +49,12 @@ SDL_HandleSIG(int sig)
int
SDL_QuitInit(void)
{
+ const char *hint = SDL_GetHint(SDL_HINT_DISABLE_SIGINT_HANDLER);
+ disable_signals = hint && (SDL_atoi(hint) == 1);
+ if (disable_signals) {
+ return 0;
+ }
+
#ifdef HAVE_SIGACTION
struct sigaction action;
sigaction(SIGINT, NULL, &action);
@@ -80,12 +89,16 @@ SDL_QuitInit(void)
#endif /* HAVE_SIGNAL_H */
/* That's it! */
- return (0);
+ return 0;
}
void
SDL_QuitQuit(void)
{
+ if (disable_signals) {
+ return;
+ }
+
#ifdef HAVE_SIGACTION
struct sigaction action;
sigaction(SIGINT, NULL, &action);