Date: Fri, 08 Jul 2005 22:43:48 +0200 (CEST)
authorSam Lantinga <slouken@libsdl.org>
Sun, 21 Aug 2005 06:18:54 +0000
changeset 112328ac87a38c17
parent 1122 e253d5448fce
child 1124 4a061326d752
Date: Fri, 08 Jul 2005 22:43:48 +0200 (CEST)
From: Jiri Svoboda
Subject: [SDL] signal handling bug

I encountered the following bug:
SDL doesn't reset signal handlers for SIGTERM and SIGINT, after calling SDL_Quit these remain hooked to the handler in SDL_quit.c, being translated into SDL_QUIT events.

Consequently an application that issues a SDL_Quit and remains running will ignore any SIGTERM or SIGINT., and specifically CTRL-C presses.
src/events/SDL_active.c
src/events/SDL_events.c
src/events/SDL_events_c.h
src/events/SDL_keyboard.c
src/events/SDL_mouse.c
src/events/SDL_quit.c
     1.1 --- a/src/events/SDL_active.c	Sat Aug 20 21:39:06 2005 +0000
     1.2 +++ b/src/events/SDL_active.c	Sun Aug 21 06:18:54 2005 +0000
     1.3 @@ -46,6 +46,9 @@
     1.4  	/* That's it! */
     1.5  	return(0);
     1.6  }
     1.7 +void SDL_AppActiveQuit(void)
     1.8 +{
     1.9 +}
    1.10  
    1.11  Uint8 SDL_GetAppState(void)
    1.12  {
     2.1 --- a/src/events/SDL_events.c	Sat Aug 20 21:39:06 2005 +0000
     2.2 +++ b/src/events/SDL_events.c	Sun Aug 21 06:18:54 2005 +0000
     2.3 @@ -196,6 +196,12 @@
     2.4  	/* Halt the event thread, if running */
     2.5  	SDL_StopEventThread();
     2.6  
     2.7 +	/* Shutdown event handlers */
     2.8 +	SDL_AppActiveQuit();
     2.9 +	SDL_KeyboardQuit();
    2.10 +	SDL_MouseQuit();
    2.11 +	SDL_QuitQuit();
    2.12 +
    2.13  	/* Clean out EventQ */
    2.14  	SDL_EventQ.head = 0;
    2.15  	SDL_EventQ.tail = 0;
     3.1 --- a/src/events/SDL_events_c.h	Sat Aug 20 21:39:06 2005 +0000
     3.2 +++ b/src/events/SDL_events_c.h	Sun Aug 21 06:18:54 2005 +0000
     3.3 @@ -43,6 +43,12 @@
     3.4  extern int  SDL_MouseInit(void);
     3.5  extern int  SDL_QuitInit(void);
     3.6  
     3.7 +/* Event handler quit routines */
     3.8 +extern void SDL_AppActiveQuit(void);
     3.9 +extern void SDL_KeyboardQuit(void);
    3.10 +extern void SDL_MouseQuit(void);
    3.11 +extern void SDL_QuitQuit(void);
    3.12 +
    3.13  /* The event filter function */
    3.14  extern SDL_EventFilter SDL_EventOK;
    3.15  
     4.1 --- a/src/events/SDL_keyboard.c	Sat Aug 20 21:39:06 2005 +0000
     4.2 +++ b/src/events/SDL_keyboard.c	Sun Aug 21 06:18:54 2005 +0000
     4.3 @@ -321,6 +321,9 @@
     4.4  	/* Done.  Whew. */
     4.5  	return(0);
     4.6  }
     4.7 +void SDL_KeyboardQuit(void)
     4.8 +{
     4.9 +}
    4.10  
    4.11  /* We lost the keyboard, so post key up messages for all pressed keys */
    4.12  void SDL_ResetKeyboard(void)
     5.1 --- a/src/events/SDL_mouse.c	Sat Aug 20 21:39:06 2005 +0000
     5.2 +++ b/src/events/SDL_mouse.c	Sun Aug 21 06:18:54 2005 +0000
     5.3 @@ -58,6 +58,9 @@
     5.4  	/* That's it! */
     5.5  	return(0);
     5.6  }
     5.7 +void SDL_MouseQuit(void)
     5.8 +{
     5.9 +}
    5.10  
    5.11  /* We lost the mouse, so post button up messages for all pressed buttons */
    5.12  void SDL_ResetMouse(void)
     6.1 --- a/src/events/SDL_quit.c	Sat Aug 20 21:39:06 2005 +0000
     6.2 +++ b/src/events/SDL_quit.c	Sun Aug 21 06:18:54 2005 +0000
     6.3 @@ -54,7 +54,7 @@
     6.4  	void (*ohandler)(int);
     6.5  
     6.6  	/* Both SIGINT and SIGTERM are translated into quit interrupts */
     6.7 -	ohandler = signal(SIGINT,  SDL_HandleSIG);
     6.8 +	ohandler = signal(SIGINT, SDL_HandleSIG);
     6.9  	if ( ohandler != SIG_DFL )
    6.10  		signal(SIGINT, ohandler);
    6.11  	ohandler = signal(SIGTERM, SDL_HandleSIG);
    6.12 @@ -65,6 +65,19 @@
    6.13  	/* That's it! */
    6.14  	return(0);
    6.15  }
    6.16 +void SDL_QuitQuit(void)
    6.17 +{
    6.18 +#ifndef NO_SIGNAL_H
    6.19 +	void (*ohandler)(int);
    6.20 +
    6.21 +	ohandler = signal(SIGINT, SIG_DFL);
    6.22 +	if ( ohandler != SDL_HandleSIG )
    6.23 +		signal(SIGINT, ohandler);
    6.24 +	ohandler = signal(SIGTERM, SIG_DFL);
    6.25 +	if ( ohandler != SDL_HandleSIG )
    6.26 +		signal(SIGTERM, ohandler);
    6.27 +#endif /* NO_SIGNAL_H */
    6.28 +}
    6.29  
    6.30  /* This function returns 1 if it's okay to close the application window */
    6.31  int SDL_PrivateQuit(void)