[PATCH] do not break application's signal handler installed with SA_SIGINFO

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.

Attached are two patches for sdl-1.2 and sdl-1.3 to solve this problem–
Gleb.
-------------- next part --------------
diff -r 67d3be4ec9f2 src/events/SDL_quit.c
— a/src/events/SDL_quit.c Thu Feb 24 17:42:45 2011 -0800
+++ b/src/events/SDL_quit.c Mon Mar 14 13:56:03 2011 +0200
@@ -45,7 +45,19 @@
/* 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 */
    @@ -62,7 +74,19 @@
    }
    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);
    -------------- next part --------------
    diff -r 4cf1ad60ad47 src/events/SDL_quit.c
    — a/src/events/SDL_quit.c Sun Mar 13 19:06:43 2011 -0700
    +++ b/src/events/SDL_quit.c Mon Mar 14 13:56:00 2011 +0200
    @@ -47,7 +47,19 @@
    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 @@
    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);

Thank you very much for your patch for SDL 1.3!

Do you give me permission to release your code with SDL 1.3 and future
versions of SDL under both the LGPL and a closed-source commercial
license?

See ya!On Mon, Mar 14, 2011 at 5:10 AM, Gleb Natapov wrote:

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.

Attached are two patches for sdl-1.2 and sdl-1.3 to solve this problem


Gleb.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

Thank you very much for your patch for SDL 1.3!

Do you give me permission to release your code with SDL 1.3 and future
versions of SDL under both the LGPL and a closed-source commercial
license?

Yes, I give you the permission for 1.3 and 1.2 version of the patch.On Tue, Mar 15, 2011 at 09:38:12PM -0700, Sam Lantinga wrote:

See ya!

On Mon, Mar 14, 2011 at 5:10 AM, Gleb Natapov <@Gleb_Natapov> wrote:

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.

Attached are two patches for sdl-1.2 and sdl-1.3 to solve this problem


Gleb.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gleb.

Thanks! Your patches are in. :)On Tue, Mar 15, 2011 at 10:21 PM, Gleb Natapov wrote:

On Tue, Mar 15, 2011 at 09:38:12PM -0700, Sam Lantinga wrote:

Thank you very much for your patch for SDL 1.3!

Do you give me permission to release your code with SDL 1.3 and future
versions of SDL under both the LGPL and a closed-source commercial
license?

Yes, I give you the permission for 1.3 and 1.2 version of the patch.

See ya!

On Mon, Mar 14, 2011 at 5:10 AM, Gleb Natapov wrote:

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.

Attached are two patches for sdl-1.2 and sdl-1.3 to solve this problem


Gleb.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gleb.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

FYI, I’m getting the following warnings with your patch:
SDL_quit.c: In function ‘SDL_QuitInit’:
SDL_quit.c:53: warning: comparison of distinct pointer types lacks a cast
SDL_quit.c:58: warning: comparison of distinct pointer types lacks a cast

I think it’s complaining about the comparison of sa_sigaction and SIG_DFLOn Mon, Mar 14, 2011 at 5:10 AM, Gleb Natapov wrote:

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.

Attached are two patches for sdl-1.2 and sdl-1.3 to solve this problem


Gleb.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks

FYI, I’m getting the following warnings with your patch:
SDL_quit.c: In function ‘SDL_QuitInit’:
SDL_quit.c:53: warning: comparison of distinct pointer types lacks a cast
SDL_quit.c:58: warning: comparison of distinct pointer types lacks a cast

I think it’s complaining about the comparison of sa_sigaction and SIG_DFL

I’ll check. What OS is this? I didn’t get this warning.On Tue, Mar 15, 2011 at 11:05:41PM -0700, Sam Lantinga wrote:

On Mon, Mar 14, 2011 at 5:10 AM, Gleb Natapov <@Gleb_Natapov> wrote:

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.

Attached are two patches for sdl-1.2 and sdl-1.3 to solve this problem


Gleb.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gleb.

FYI, I’m getting the following warnings with your patch:
SDL_quit.c: In function ‘SDL_QuitInit’:
SDL_quit.c:53: warning: comparison of distinct pointer types lacks a cast
SDL_quit.c:58: warning: comparison of distinct pointer types lacks a cast

I think it’s complaining about the comparison of sa_sigaction and SIG_DFL

I’ll check. What OS is this? I didn’t get this warning.

Actually I got it. It runs away from the screen very fast. Will fix.On Wed, Mar 16, 2011 at 10:26:15AM +0200, Gleb Natapov wrote:

On Tue, Mar 15, 2011 at 11:05:41PM -0700, Sam Lantinga wrote:

On Mon, Mar 14, 2011 at 5:10 AM, Gleb Natapov <@Gleb_Natapov> wrote:

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.

Attached are two patches for sdl-1.2 and sdl-1.3 to solve this problem


Gleb.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gleb.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Gleb.

FYI, I’m getting the following warnings with your patch:
SDL_quit.c: In function ‘SDL_QuitInit’:
SDL_quit.c:53: warning: comparison of distinct pointer types lacks a cast
SDL_quit.c:58: warning: comparison of distinct pointer types lacks a cast

I think it’s complaining about the comparison of sa_sigaction and SIG_DFL

I’ll check. What OS is this? I didn’t get this warning.

Actually I got it. It runs away from the screen very fast. Will fix.

See attached patches please. Or do you prefer incremental patches
against previously posted?On Wed, Mar 16, 2011 at 10:35:12AM +0200, Gleb Natapov wrote:

On Wed, Mar 16, 2011 at 10:26:15AM +0200, Gleb Natapov wrote:

On Tue, Mar 15, 2011 at 11:05:41PM -0700, Sam Lantinga wrote:

On Mon, Mar 14, 2011 at 5:10 AM, Gleb Natapov <@Gleb_Natapov> wrote:


Gleb.
-------------- next part --------------
diff -r b214b7ce9b00 src/events/SDL_quit.c
— a/src/events/SDL_quit.c Tue Mar 15 21:36:36 2011 -0700
+++ b/src/events/SDL_quit.c Wed Mar 16 11:34:14 2011 +0200
@@ -48,12 +48,12 @@
#ifdef HAVE_SIGACTION
struct sigaction action;
sigaction(SIGINT, NULL, &action);

  • if ( action.sa_handler == SIG_DFL && action.sa_sigaction == SIG_DFL ) {
  • if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)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 ) {
  • if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)SIG_DFL ) {
    action.sa_handler = SDL_HandleSIG;
    sigaction(SIGTERM, &action, NULL);
    }
    -------------- next part --------------
    diff -r ef1db08c40ac src/events/SDL_quit.c
    — a/src/events/SDL_quit.c Tue Mar 15 23:26:22 2011 -0700
    +++ b/src/events/SDL_quit.c Wed Mar 16 11:34:05 2011 +0200
    @@ -50,12 +50,12 @@
    #ifdef HAVE_SIGACTION
    struct sigaction action;
    sigaction(SIGINT, NULL, &action);
  • if ( action.sa_handler == SIG_DFL && action.sa_sigaction == SIG_DFL ) {
  • if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)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 ) {
  • if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)SIG_DFL ) {
    action.sa_handler = SDL_HandleSIG;
    sigaction(SIGTERM, &action, NULL);
    }

Normally incremental patches are better, but the change was simple, so this
is fine.

Thanks!On Wed, Mar 16, 2011 at 2:46 AM, Gleb Natapov wrote:

On Wed, Mar 16, 2011 at 10:35:12AM +0200, Gleb Natapov wrote:

On Wed, Mar 16, 2011 at 10:26:15AM +0200, Gleb Natapov wrote:

On Tue, Mar 15, 2011 at 11:05:41PM -0700, Sam Lantinga wrote:

FYI, I’m getting the following warnings with your patch:
SDL_quit.c: In function ‘SDL_QuitInit’:
SDL_quit.c:53: warning: comparison of distinct pointer types lacks a
cast

SDL_quit.c:58: warning: comparison of distinct pointer types lacks a
cast

I think it’s complaining about the comparison of sa_sigaction and
SIG_DFL

I’ll check. What OS is this? I didn’t get this warning.

Actually I got it. It runs away from the screen very fast. Will fix.

On Mon, Mar 14, 2011 at 5:10 AM, Gleb Natapov wrote:
See attached patches please. Or do you prefer incremental patches
against previously posted?


Gleb.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and CEO, Galaxy Gameworks