Repository navigation
libobs: Keep the Wayland keymap if one won't load - #2976
Conversation
|
Coordinator tick: the Tier 2 Linux lanes are red in the new test itself, and the fix it expects is not in this PR yet. Both lanes fail identically ( 4 of the 5 cases crash; only the good-keymap case passes. That is the master behaviour your commit message describes ( Also worth a look before you mark it ready: the Leaving the PR in draft. Ping me when the handler fix is in and the lanes are green, or reply here if the master-side fix belongs in a separate PR ahead of this one — in that case split the test off onto the fix's branch so the merge queue does not see a permanently red Tier 2. |
A new cmocka test, test_wayland_keymap, compiles in the real Wayland hotkey platform and hands its wl_keyboard.keymap handler keymaps through a memfd, as the compositor does. It expects a keymap that doesn't compile, a no_keymap event and a missing xkb context to leave the last good keymap in place, or none when there was none. On master the handler drops the old keymap and state first and then dereferences the NULL keymap (xkb_state_new), so four of the five cases crash. Refs #2975.
platform_keyboard_keymap() dropped the old keymap and state before it looked at the new keymap, so a keymap libxkbcommon couldn't compile crashed OBS in xkb_state_new(NULL), at startup or on a layout change. It also compiled the fd of a no_keymap event, and compiled with no xkb context when libxkbcommon found no keyboard data. Ignore any format but XKB_V1, and do nothing without a context. When compilation fails, keep the previous keymap and state and log a warning, so hotkeys go on with the last layout that loaded. Fixes #2975.
2d372fd to
4748929
Compare
zackees
left a comment
There was a problem hiding this comment.
Reviewed. The handler fix matches what the RED test needs, and PR CI is green (40/40 checks).
Correctness:
format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1 || !plat->xkb_contextreturns early and closes the fd, so theno_keymapcase never compiles a keymap and the no-context case (the #2437 situation) no longer reachesxkb_keymap_new_from_string(NULL, ...).!xkb_keymapnow returns before droppingplat->xkb_keymap/plat->xkb_state, which is the crash:xkb_state_new(NULL)on the old pointers. Keeping the previous keymap and state is the right behaviour, and the warning names the path.rebuild_keymap_data()is only reached with a compiled keymap, sokey_to_sym/obs_to_keyare not cleared for a rejected layout.- Test covers both orderings (broken after good, broken first then good) and asserts pointer identity, not just non-NULL, so it would catch a re-compile of the old text.
Nits, non-blocking:
no_xkb_contextmanufactures the missing context by unref'ing it, which is fine here, but it does not exercisexkb_context_new()actually failing; the comment says so and the case still pins the handler's guard, so I am not asking for a change.- The features-ledger line is accurate and dated.
Queueing it now.
Fixes #2975
What and why
On Wayland, the hotkey platform's
wl_keyboard.keymaphandler (platform_keyboard_keymap()inlibobs/obs-nix-wayland.c.h) dropped the old keymap and state before it looked at the new one. When the compositor sends a keymap libxkbcommon can't compile, at startup or on any layout change,xkb_keymap_new_from_string()returns NULL andxkb_state_new(NULL)crashes OBS. The handler also compiled the fd of ano_keymapevent, and compiled against a NULL xkb context when libxkbcommon found no keyboard data (the situation of #2437).The handler now ignores any format but
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1and does nothing without a context (closing the fd either way). When compilation fails it keeps the previous keymap and state and logs[wayland] could not compile the compositor's keymap, keeping the previous one, so hotkeys go on with the last layout that loaded, or stay without one if none ever loaded (as they already do before the first keymap arrives).Found reading the code; no upstream issue. Upstream OBS has the same handler.
RED → GREEN
test_wayland_keymap, which compiles in the real Wayland hotkey platform and hands its keymap handler keymaps through a memfd, as the compositor does. On master 4 of its 5 cases crash:broken_keymap_keeps_previous,broken_first_keymap,no_keymap_format_is_ignoredandno_xkb_contexteach fail withTest failed with exception: Segmentation fault(11);good_keymap_loadspasses.test_wayland_keymappasses 5/5 against the C build, hybridlibobsandlibobs-c-reference, and under ASan/UBSan with no reports. The cmocka suite: C build 630 tests, hybrid 630 and C reference 630, the Wayland tests (test_wayland_keymap,test_wayland_multiseat,test_wayland_hotkeys,test_wayland_volume_keys) passing in each. The only failures under parallel load were the pulse, v4l2, X11 hotplug and core shutdown tests, and each passes alone (the two that need X under Xvfb). Skips: 8 on the C and hybrid runs, 9 on the C reference (the extra one,test_pulse_default_follow, skips alone in every mode on this host). Exported symbols are identical on the C build, hybrid and C reference (1767 each). Local gates:--test-diff origin/master, lint and cross pass. The full runs were on 0acb92bc3, the same change before a rebase onto the macOS libcurl commit (infra: record the measured macOS system libcurl in the Brotli carve-out (#2907) #2977); after it, on 4748929,test_wayland_keymappasses again on all three libraries, the export sets are still identical, and lint and theport_comparisonbench test pass. The local gate stamp needs Docker for its Tier 2 lane, which this machine cannot use, so the head is unstamped and PR CI runs the full suite.obs-studio-rust-gui --multion a headless sway (its own HOME, no audio) starts on Wayland (Platform: Wayland), takes sway's keymap with no warning, runs for 20 s and shuts down cleanly (Freeing OBS context data). No compositor at hand sends a keymap that fails to compile, so that path, and its log line, is shown by the test:Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)