diff --git a/src/events/SDL_quit.c b/src/events/SDL_quit.c index c74a43473..2108693d5 100644 --- a/src/events/SDL_quit.c +++ b/src/events/SDL_quit.c @@ -47,7 +47,19 @@ SDL_HandleSIG(int sig) int SDL_QuitInit(void) { -#ifdef HAVE_SIGNAL_H +#ifdef HAVE_SIGACTION + struct sigaction action; + sigaction(SIGINT, NULL, &action); + if ( action.sa_handler == SIG_DFL && action.sa_sigaction == SIG_DFL ) { + action.sa_handler = SDL_HandleSIG; + sigaction(SIGINT, &action, NULL); + } + sigaction(SIGTERM, NULL, &action); + if ( action.sa_handler == SIG_DFL && action.sa_sigaction == SIG_DFL ) { + action.sa_handler = SDL_HandleSIG; + sigaction(SIGTERM, &action, NULL); + } +#elif HAVE_SIGNAL_H void (*ohandler) (int); /* Both SIGINT and SIGTERM are translated into quit interrupts */ @@ -66,7 +78,19 @@ SDL_QuitInit(void) void SDL_QuitQuit(void) { -#ifdef HAVE_SIGNAL_H +#ifdef HAVE_SIGACTION + struct sigaction action; + sigaction(SIGINT, NULL, &action); + if ( action.sa_handler == SDL_HandleSIG ) { + action.sa_handler = SIG_DFL; + sigaction(SIGINT, &action, NULL); + } + sigaction(SIGTERM, NULL, &action); + if ( action.sa_handler == SDL_HandleSIG ) { + action.sa_handler = SIG_DFL; + sigaction(SIGTERM, &action, NULL); + } +#elif HAVE_SIGNAL_H void (*ohandler) (int); ohandler = signal(SIGINT, SIG_DFL);