From 449c6856758f19102fd32934922ad7d606682d29 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Tue, 7 May 2024 21:32:24 +0200 Subject: [PATCH] uucore+timeout: accept signals of any casing --- src/uu/kill/src/kill.rs | 3 +-- src/uucore/src/lib/features/signals.rs | 5 +++-- tests/by-util/test_timeout.rs | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 6048acfb9..1e60847c0 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -200,8 +200,7 @@ fn list(signals: &Vec) { } fn parse_signal_value(signal_name: &str) -> UResult { - let signal_name_upcase = signal_name.to_uppercase(); - let optional_signal_value = signal_by_name_or_value(&signal_name_upcase); + let optional_signal_value = signal_by_name_or_value(signal_name); match optional_signal_value { Some(x) => Ok(x), None => Err(USimpleError::new( diff --git a/src/uucore/src/lib/features/signals.rs b/src/uucore/src/lib/features/signals.rs index 8c9ca6195..41dda3e9f 100644 --- a/src/uucore/src/lib/features/signals.rs +++ b/src/uucore/src/lib/features/signals.rs @@ -340,14 +340,15 @@ pub static ALL_SIGNALS: [&str; 37] = [ ]; pub fn signal_by_name_or_value(signal_name_or_value: &str) -> Option { - if let Ok(value) = signal_name_or_value.parse() { + let signal_name_upcase = signal_name_or_value.to_uppercase(); + if let Ok(value) = signal_name_upcase.parse() { if is_signal(value) { return Some(value); } else { return None; } } - let signal_name = signal_name_or_value.trim_start_matches("SIG"); + let signal_name = signal_name_upcase.trim_start_matches("SIG"); ALL_SIGNALS.iter().position(|&s| s == signal_name) } diff --git a/tests/by-util/test_timeout.rs b/tests/by-util/test_timeout.rs index 896065a20..1ba6445c8 100644 --- a/tests/by-util/test_timeout.rs +++ b/tests/by-util/test_timeout.rs @@ -97,12 +97,14 @@ fn test_preserve_status() { fn test_preserve_status_even_when_send_signal() { // When sending CONT signal, process doesn't get killed or stopped. // So, expected result is success and code 0. - new_ucmd!() - .args(&["-s", "CONT", "--preserve-status", ".1", "sleep", "5"]) - .succeeds() - .code_is(0) - .no_stderr() - .no_stdout(); + for cont_spelling in ["CONT", "cOnT", "SIGcont"] { + new_ucmd!() + .args(&["-s", cont_spelling, "--preserve-status", ".1", "sleep", "2"]) + .succeeds() + .code_is(0) + .no_stderr() + .no_stdout(); + } } #[test]