From 69f6ce1553cb698012eed776397bb0e759afb0df Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Sat, 11 Jul 2026 00:39:10 -0400 Subject: [PATCH] bug: fix bug with Linux signals 34 or higher being off by 2 (#2144) Fixes a bug with determining the signal for Linux since there was a logic bug. Oops. --- CHANGELOG.md | 6 +++ src/canvas/dialogs/process_kill_dialog.rs | 46 +++++++++++++++++++---- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7cd13d3..86dc2e5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,12 @@ That said, these are more guidelines rather than hard rules, though the project --- +## Unreleased + +### Bug Fixes + +- [#2144](https://github.com/ClementTsang/bottom/pull/2144): Fix bug with Linux signals 34 or higher being off by 2. + ## 0.14.4 - 2026-07-09 ### Bug Fixes diff --git a/src/canvas/dialogs/process_kill_dialog.rs b/src/canvas/dialogs/process_kill_dialog.rs index 832fdd38..c63811d2 100644 --- a/src/canvas/dialogs/process_kill_dialog.rs +++ b/src/canvas/dialogs/process_kill_dialog.rs @@ -247,13 +247,7 @@ impl ProcessKillDialog { if let Some(selected) = state.selected() && selected != 0 { - // On Linux, we need to skip 32 and 33. - let signal = - if cfg!(target_os = "linux") && (selected == 32 || selected == 33) { - selected + 2 - } else { - selected - }; + let signal = get_signal_from_index(selected); for pid in pids { if let Err(err) = process_killer::kill_process_given_pid(pid, signal) { @@ -894,3 +888,41 @@ impl ProcessKillDialog { } } } + +/// Return the signal number to send given the index on a list. +/// +/// On Linux, we need to skip 32 and 33, so we add 2 to the index if it's >= 32. +#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))] +fn get_signal_from_index(index: usize) -> usize { + if cfg!(target_os = "linux") && index >= 32 { + index + 2 + } else { + index + } +} + +#[cfg(test)] +mod tests { + #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))] + use super::*; + + #[test] + #[cfg(target_os = "linux")] + fn test_getting_signal_from_index_on_linux() { + assert_eq!(get_signal_from_index(0), 0); + assert_eq!(get_signal_from_index(31), 31); + assert_eq!(get_signal_from_index(32), 34); + assert_eq!(get_signal_from_index(33), 35); + assert_eq!(get_signal_from_index(34), 36); + } + + #[test] + #[cfg(any(target_os = "macos", target_os = "freebsd"))] + fn test_getting_signal_from_index_not_on_linux() { + assert_eq!(get_signal_from_index(0), 0); + assert_eq!(get_signal_from_index(31), 31); + assert_eq!(get_signal_from_index(32), 32); + assert_eq!(get_signal_from_index(33), 33); + assert_eq!(get_signal_from_index(34), 34); + } +}