From 7c2388fbfc5ba1fcdcea14634a5d7181483fa9a2 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 15 Feb 2025 07:57:06 +0100 Subject: [PATCH] Fix bracketed paste potentially not being disabled on SIGTERM When we enable/disable terminal protocols, we use atomic operations because of issues like 1. halfway through enabling, we might be interrupted by a signal handler. 2. our SIGTERM handler runs the (idempotent) disabling sequences, so the operations must be async-signal safe. The flags to keep track of whether things like kitty keyboard protocol are enabled are "mirrored" between the enabling and disabling logic: - the enabling logic marks it as enabled *before* enabling anything - the disabling logic marks it as disabled *after* everything has been disabled This ensures that we are well-behaved in issue 1; we will always (perhaps redundantly) disable the kitty keyboard protocol. We forgot to use the same ordering for bracketed paste. If we get SIGTERM after this line BRACKETED_PASTE.store(false, Ordering::Release); we might exit with bracketed paste still turned on. --- src/input_common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input_common.rs b/src/input_common.rs index 0802c33bd..b4d4cdb91 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -552,11 +552,11 @@ pub(crate) fn terminal_protocols_disable_ifn() { }) }); if BRACKETED_PASTE.load(Ordering::Acquire) { - BRACKETED_PASTE.store(false, Ordering::Release); let _ = write_loop(&STDOUT_FILENO, b"\x1b[?2004l"); if IS_TMUX.load() { let _ = write_loop(&STDOUT_FILENO, "\x1b[?1004l".as_bytes()); } + BRACKETED_PASTE.store(false, Ordering::Release); did_write.store(true); } if !TERMINAL_PROTOCOLS.load(Ordering::Acquire) {