feat(macos): add actionable startup diagnostics and clean shutdown#2015
Merged
jtroo merged 1 commit intojtroo:mainfrom Apr 11, 2026
Merged
feat(macos): add actionable startup diagnostics and clean shutdown#2015jtroo merged 1 commit intojtroo:mainfrom
jtroo merged 1 commit intojtroo:mainfrom
Conversation
Install a `SIGABRT` handler at the top of `KbdIn::new` that writes a static stderr hint after libc++abi's own message, enumerating the real causes of a startup abort in order: not running as root (the number 1 cause, since the karabiner-driverkit IPC lives under the root-owned `/Library/Application Support/org.pqrs/tmp/rootonly/` and kanata itself must run as root), driver not installed / system extension not approved, or another exclusive grabber. Without this, the C++ dispatcher threads throw an uncaught `std::filesystem_error` on a posix_stat of the rootonly directory and libc++abi prints an unhelpful backtrace Gate the hint on a startup-phase flag: set it on handler install and clear it from the macOS event loop right after `wait_until_ready` returns, so only *startup* aborts emit the hint. Silently re-raise any later `SIGABRT` to avoid misleading users about unrelated teardown races. Keep the handler body async-signal-safe (`AtomicBool::load`, `write(2)`, `signal`, `raise`) Switch the macOS kill-chord path in `check_for_exit` from `std::process::exit` to `libc::_exit` (after flushing stdio) so exiting via `lctl+spc+esc` bypasses the pqrs shared dispatcher's C++ static destructors. That destructor kills its own worker threads while they still hold a `std::mutex`, which makes `pthread_mutex_destroy` return EINVAL, raise an uncaught `std::system_error`, and abort with `libc++abi: mutex lock failed: Invalid argument` right after the user's clean-exit log line. `_exit` jumps straight to the kernel exit syscall and skips the entire buggy teardown Address jtroo#1743
9f61786 to
bdf022f
Compare
Contributor
Author
|
@jtroo I resolved the conflict |
jtroo
approved these changes
Apr 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes. Use imperative present tense.
Install a
SIGABRThandler at the top ofKbdIn::newthat writes astatic stderr hint after libc++abi's own message, enumerating the real
causes of a startup abort in order: not running as root (the number
1 cause, since the karabiner-driverkit IPC lives under the root-owned
/Library/Application Support/org.pqrs/tmp/rootonly/and kanata itselfmust run as root), driver not installed / system extension not approved,
or another exclusive grabber. Without this, the C++ dispatcher threads
throw an uncaught
std::filesystem_erroron a posix_stat of therootonly directory and libc++abi prints an unhelpful backtrace
Gate the hint on a startup-phase flag: set it on handler install and
clear it from the macOS event loop right after
wait_until_readyreturns, so only startup aborts emit the hint. Silently re-raise
any later
SIGABRTto avoid misleading users about unrelated teardownraces. Keep the handler body async-signal-safe (
AtomicBool::load,write(2),signal,raise)Switch the macOS kill-chord path in
check_for_exitfromstd::process::exittolibc::_exit(after flushing stdio) soexiting via
lctl+spc+escbypasses the pqrs shared dispatcher's C++static destructors. That destructor kills its own worker threads while
they still hold a
std::mutex, which makespthread_mutex_destroyreturn EINVAL, raise an uncaught
std::system_error, and abort withlibc++abi: mutex lock failed: Invalid argumentright after the user'sclean-exit log line.
_exitjumps straight to the kernel exit syscalland skips the entire buggy teardown
Address #1743
Checklist