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 4193

Summary: [patch] Fix SDL Linux evdev leaving keyboard dead after nonclean application exit
Product: SDL Reporter: Tadek Kijkowski <tkijkowski>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2 CC: icculus, sezeroz
Version: HG 2.0   
Hardware: All   
OS: Linux   
Attachments: Patch for SDL_evdev_kbd.c

Description Tadek Kijkowski 2018-06-08 21:54:41 UTC
Created attachment 3258 [details]
Patch for SDL_evdev_kbd.c

In release 2.0.6, when Linux evdev keyboard support has been moved to a separate source file, a feature was added to disable normal keyboard event processing to prevent "spilling" keystrokes to background virtual console.

This feature has one unpleasant side effect: if application fails to call `SDL_Exit` before termination or crashes with fatal signal, console is left in unusable state with keyboard not working and no possibility to switch virtual console. If user has a chance, he can login remotely and restore keyboard with `kbd_mode`, otherwise the only option is to reboot the machine.

This patch fixes that problem by intercepting fatal signals (with `sigaction`) and process termination (with `atexit`), to restore keyboard state, if it wasn't properly restored with `SDL_Exit`.

The function registered with `atexit` also restores original signal handlers, to prevent leaving invalid handlers after SDL library is unloaded, if it was loaded dynamically with `dlopen`.

No signal handlers or `atexit` function are installed if SDL boolean hint `SDL_HINT_NO_SIGNAL_HANDLERS` is `SDL_TRUE`.

Additionally, if environment variable `SDL_INPUT_LINUX_KEEP_KBD` exists, keyboard initialization function completely skips disabling keyboard. This can be useful for debugging.
Comment 1 Ryan C. Gordon 2018-08-08 14:20:36 UTC
This patch is now https://hg.libsdl.org/SDL/rev/18ea018e00a0, thanks!

--ryan.