diff --git a/docs/changelog.rst b/docs/changelog.rst index 4a281ce6b..da8eb572f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -65,6 +65,8 @@ Detailed list of changes - When using the :code:`include` directive in :file:`kitty.conf` make the environment variable :envvar:`KITTY_OS` available for OS specific config +- Wayland: Fix signal handling not working with some GPU drivers (:iss:`4636`) + 0.26.5 [2022-11-07] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 1baf36bf5..89441b470 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -124,10 +124,6 @@ set_maximum_wait(monotonic_t val) { static void mask_variadic_signals(int sentinel, ...) { - // only need to mask signals when using SIGNAL_FD as signal actions are inherited by threads - // and only on Linux do we have reports of signals not being handled presumably because libwayland starts - // a thread behind our backs. See https://github.com/kovidgoyal/kitty/issues/4636 -#ifdef HAS_SIGNAL_FD sigset_t signals; sigemptyset(&signals); va_list valist; @@ -138,9 +134,17 @@ mask_variadic_signals(int sentinel, ...) { sigaddset(&signals, sig); } va_end(valist); +#ifdef HAS_SIGNAL_FD sigprocmask(SIG_BLOCK, &signals, NULL); #else - (void)sentinel; + struct sigaction act = {.sa_handler=SIG_IGN, .sa_flags=SA_RESTART, .sa_mask = signals}; + va_start(valist, sentinel); + while (true) { + int sig = va_arg(valist, int); + if (sig == sentinel) break; + sigaction(sig, &act, NULL); + } + va_end(valist); #endif } diff --git a/kitty/main.py b/kitty/main.py index 62f59d26b..1bc3cdbe8 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -103,7 +103,6 @@ def init_glfw_module(glfw_module: str, debug_keyboard: bool = False, debug_rende def init_glfw(opts: Options, debug_keyboard: bool = False, debug_rendering: bool = False) -> str: - mask_kitty_signals_process_wide() glfw_module = 'cocoa' if is_macos else ('wayland' if is_wayland(opts) else 'x11') init_glfw_module(glfw_module, debug_keyboard, debug_rendering) return glfw_module @@ -464,6 +463,11 @@ def _main() -> None: log_error('Failed to set locale, ignoring') with suppress(AttributeError): # python compiled without threading sys.setswitchinterval(1000.0) # we have only a single python thread + + # mask the signals now as on some platforms the display backend starts + # threads. These threads must not handle the masked signals, to ensure + # kitty can handle them. See https://github.com/kovidgoyal/kitty/issues/4636 + mask_kitty_signals_process_wide() init_glfw(opts, cli_opts.debug_keyboard, cli_opts.debug_rendering) if cli_opts.watcher: from .window import global_watchers