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 - [patch] Fix SDL Linux evdev leaving keyboard dead after nonclean application exit
Summary: [patch] Fix SDL Linux evdev leaving keyboard dead after nonclean application ...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: HG 2.0
Hardware: All Linux
: P2 minor
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-08 21:54 UTC by Tadek Kijkowski
Modified: 2018-08-08 14:20 UTC (History)
2 users (show)

See Also:


Attachments
Patch for SDL_evdev_kbd.c (6.00 KB, patch)
2018-06-08 21:54 UTC, Tadek Kijkowski
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.