From cae94028afcfa19b78dfc1072d1a22d8b2c6ca38 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 18 Dec 2025 21:46:52 +0100 Subject: [PATCH] kill -1 should trigger an error https://github.com/uutils/coreutils/issues/9699 --- src/uu/kill/src/kill.rs | 4 ++-- tests/by-util/test_kill.rs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 809d59b7d..94aa81964 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -137,8 +137,8 @@ pub fn uu_app() -> Command { } fn handle_obsolete(args: &mut Vec) -> Option { - // Sanity check - if args.len() > 2 { + // Sanity check - need at least the program name and one argument + if args.len() >= 2 { // Old signal can only be in the first argument position let slice = args[1].as_str(); if let Some(signal) = slice.strip_prefix('-') { diff --git a/tests/by-util/test_kill.rs b/tests/by-util/test_kill.rs index 5fb8fb312..aad1982d6 100644 --- a/tests/by-util/test_kill.rs +++ b/tests/by-util/test_kill.rs @@ -395,3 +395,27 @@ fn test_kill_with_signal_and_table() { .arg("-t") .fails(); } + +/// Test that `kill -1` (signal without PID) reports "no process ID" error +/// instead of being misinterpreted as pid=-1 which would kill all processes. +/// This matches GNU kill behavior. +#[test] +fn test_kill_signal_only_no_pid() { + // Test with -1 (SIGHUP) + new_ucmd!() + .arg("-1") + .fails() + .stderr_contains("no process ID specified"); + + // Test with -9 (SIGKILL) + new_ucmd!() + .arg("-9") + .fails() + .stderr_contains("no process ID specified"); + + // Test with -TERM + new_ucmd!() + .arg("-TERM") + .fails() + .stderr_contains("no process ID specified"); +}