From fe3e3b3b503a5872b0971caf69a88173aad0c0a8 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 12 Oct 2024 09:00:24 +0200 Subject: [PATCH] Fix potential assertion failure on SIGTERM If SIGTERM is delivered to a background thread, a function call to sanitize the reader state would crash in assert_is_main_thread(). In this case we are about to exit so there's no need to fix the reader state. Skip it on background threads. --- src/input_common.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/input_common.rs b/src/input_common.rs index 46c51a3dd..3904ffd2f 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -12,7 +12,7 @@ use crate::key::{ Key, Modifiers, }; use crate::reader::{reader_current_data, reader_test_and_clear_interrupted}; -use crate::threads::iothread_port; +use crate::threads::{iothread_port, is_main_thread}; use crate::universal_notifier::default_notifier; use crate::wchar::{encode_byte_to_char, prelude::*}; use crate::wutil::encoding::{mbrtowc, mbstate_t, zero_mbstate}; @@ -493,7 +493,9 @@ pub(crate) fn terminal_protocols_disable_ifn() { if IS_TMUX.load() { let _ = write_to_fd("\x1b[?1004l".as_bytes(), STDOUT_FILENO); } - reader_current_data().map(|data| data.save_screen_state()); + if is_main_thread() { + reader_current_data().map(|data| data.save_screen_state()); + } TERMINAL_PROTOCOLS.store(false, Ordering::Release); }