Skip to content

Commit cae9402

Browse files
committed
kill -1 should trigger an error
uutils#9699
1 parent 45f81bb commit cae9402

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/uu/kill/src/kill.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ pub fn uu_app() -> Command {
137137
}
138138

139139
fn handle_obsolete(args: &mut Vec<String>) -> Option<usize> {
140-
// Sanity check
141-
if args.len() > 2 {
140+
// Sanity check - need at least the program name and one argument
141+
if args.len() >= 2 {
142142
// Old signal can only be in the first argument position
143143
let slice = args[1].as_str();
144144
if let Some(signal) = slice.strip_prefix('-') {

tests/by-util/test_kill.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,27 @@ fn test_kill_with_signal_and_table() {
395395
.arg("-t")
396396
.fails();
397397
}
398+
399+
/// Test that `kill -1` (signal without PID) reports "no process ID" error
400+
/// instead of being misinterpreted as pid=-1 which would kill all processes.
401+
/// This matches GNU kill behavior.
402+
#[test]
403+
fn test_kill_signal_only_no_pid() {
404+
// Test with -1 (SIGHUP)
405+
new_ucmd!()
406+
.arg("-1")
407+
.fails()
408+
.stderr_contains("no process ID specified");
409+
410+
// Test with -9 (SIGKILL)
411+
new_ucmd!()
412+
.arg("-9")
413+
.fails()
414+
.stderr_contains("no process ID specified");
415+
416+
// Test with -TERM
417+
new_ucmd!()
418+
.arg("-TERM")
419+
.fails()
420+
.stderr_contains("no process ID specified");
421+
}

0 commit comments

Comments
 (0)