From b1af712a3db9292c3758e6dba08e1cad433d81b0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 21 Aug 2005 06:18:54 +0000 Subject: [PATCH] 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 | 3 +++ src/events/SDL_events.c | 6 ++++++ src/events/SDL_events_c.h | 6 ++++++ src/events/SDL_keyboard.c | 3 +++ src/events/SDL_mouse.c | 3 +++ src/events/SDL_quit.c | 15 ++++++++++++++- 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/events/SDL_active.c b/src/events/SDL_active.c index 5c258a725..3f7c15250 100644 --- a/src/events/SDL_active.c +++ b/src/events/SDL_active.c @@ -46,6 +46,9 @@ int SDL_AppActiveInit(void) /* That's it! */ return(0); } +void SDL_AppActiveQuit(void) +{ +} Uint8 SDL_GetAppState(void) { diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 43ae04d4c..7a61e2bf5 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -196,6 +196,12 @@ void SDL_StopEventLoop(void) /* Halt the event thread, if running */ SDL_StopEventThread(); + /* Shutdown event handlers */ + SDL_AppActiveQuit(); + SDL_KeyboardQuit(); + SDL_MouseQuit(); + SDL_QuitQuit(); + /* Clean out EventQ */ SDL_EventQ.head = 0; SDL_EventQ.tail = 0; diff --git a/src/events/SDL_events_c.h b/src/events/SDL_events_c.h index 552a55999..e16984f21 100644 --- a/src/events/SDL_events_c.h +++ b/src/events/SDL_events_c.h @@ -43,6 +43,12 @@ extern int SDL_KeyboardInit(void); extern int SDL_MouseInit(void); extern int SDL_QuitInit(void); +/* Event handler quit routines */ +extern void SDL_AppActiveQuit(void); +extern void SDL_KeyboardQuit(void); +extern void SDL_MouseQuit(void); +extern void SDL_QuitQuit(void); + /* The event filter function */ extern SDL_EventFilter SDL_EventOK; diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index 8319d7f5b..a847fbd26 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -321,6 +321,9 @@ int SDL_KeyboardInit(void) /* Done. Whew. */ return(0); } +void SDL_KeyboardQuit(void) +{ +} /* We lost the keyboard, so post key up messages for all pressed keys */ void SDL_ResetKeyboard(void) diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index d77c9b78a..749831203 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -58,6 +58,9 @@ int SDL_MouseInit(void) /* That's it! */ return(0); } +void SDL_MouseQuit(void) +{ +} /* We lost the mouse, so post button up messages for all pressed buttons */ void SDL_ResetMouse(void) diff --git a/src/events/SDL_quit.c b/src/events/SDL_quit.c index d4b8d1a92..1689df946 100644 --- a/src/events/SDL_quit.c +++ b/src/events/SDL_quit.c @@ -54,7 +54,7 @@ int SDL_QuitInit(void) void (*ohandler)(int); /* Both SIGINT and SIGTERM are translated into quit interrupts */ - ohandler = signal(SIGINT, SDL_HandleSIG); + ohandler = signal(SIGINT, SDL_HandleSIG); if ( ohandler != SIG_DFL ) signal(SIGINT, ohandler); ohandler = signal(SIGTERM, SDL_HandleSIG); @@ -65,6 +65,19 @@ int SDL_QuitInit(void) /* That's it! */ return(0); } +void SDL_QuitQuit(void) +{ +#ifndef NO_SIGNAL_H + void (*ohandler)(int); + + ohandler = signal(SIGINT, SIG_DFL); + if ( ohandler != SDL_HandleSIG ) + signal(SIGINT, ohandler); + ohandler = signal(SIGTERM, SIG_DFL); + if ( ohandler != SDL_HandleSIG ) + signal(SIGTERM, ohandler); +#endif /* NO_SIGNAL_H */ +} /* This function returns 1 if it's okay to close the application window */ int SDL_PrivateQuit(void)