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.
This commit is contained in:
Clement Tsang
2026-07-11 00:39:10 -04:00
committed by GitHub
parent 892157794a
commit 69f6ce1553
2 changed files with 45 additions and 7 deletions
+6
View File
@@ -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
+39 -7
View File
@@ -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);
}
}