Skip to content

Commit

Permalink
Do not break application's signal handler installed with SA_SIGINFO
Browse files Browse the repository at this point in the history
Gleb Natapov to sdl

If application installs SIGINT/SIGTERM signal handler with
sigaction(SA_SIGINFO) syscall before initializing SDL, after
initialization
of SDL signal handler will be reinstalled without SA_SIGINFO flag which
brings havoc when the signal handler is called. The breakage is done by
SDL_QuitInit()/SDL_QuitQuit() function. They use signal() to detect that
signal handler is already installed even in sigaction() is available.
  • Loading branch information
slouken committed Mar 16, 2011
1 parent 7bfdce4 commit 5636f3a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/events/SDL_quit.c
Expand Up @@ -45,7 +45,19 @@ static void SDL_HandleSIG(int sig)
/* Public functions */
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 */
Expand All @@ -62,7 +74,19 @@ int 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);
Expand Down

0 comments on commit 5636f3a

Please sign in to comment.