We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2431

Summary: SDL eats SIGINT by default
Product: SDL Reporter: Tiffany Bennett <tiffany>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: API change    
Priority: P2 CC: tiffany
Version: 2.0.1Keywords: triage-2.0.4
Hardware: x86_64   
OS: Linux   

Description Tiffany Bennett 2014-03-06 21:09:09 UTC
This is rather ugly behaviour which causes SDL to completely eat and ignore any ctrl+C sent to the application unless you explicitly look at the documentation and see that it generates SDL_QUIT, and handle SDL_QUIT.

In my case, I am leaving it to the caller to install signal handlers for ctrl+C, and it is not preferred behaviour to have SDL eating my ctrl+Cs for demos which I didn't bother to install cleanup code for.

At the very least, there should be a flag (perhaps reuse SDL_INIT_NOPARACHUTE?) to disable SDL attempting to install these signal handlers.

Steps to reproduce:

1. Create any application which does not include logic to handle SDL_QUIT.
2. Compile and run it.
3. Press ctrl+C

Expected result:

The application should terminate.

Actual result:

Nothing. SDL catches the signal, fires the SDL_QUIT event, which is ignored, and the application continues running as if nothing happened.
Comment 1 Ryan C. Gordon 2015-02-19 05:22:18 UTC
Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!
Comment 2 Ryan C. Gordon 2015-03-24 18:41:02 UTC
As of https://hg.libsdl.org/SDL/rev/0af69dab9bb6, you can use a hint to prevent SDL from touching the signal handlers.

From your program, before calling SDL_Init()...

    SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");

...it is safe to call this on any platform, but it only does something on Unix-like things.

You can also force this from the command line: set the "SDL_NO_SIGNAL_HANDLERS" environment variable to "1".

The default will continue to be to install the signal handler, but now you can explicitly prevent this if your app ignores SDL_QUIT or wants its own handler instead.

--ryan.