File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed
Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -137,8 +137,8 @@ pub fn uu_app() -> Command {
137137}
138138
139139fn 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 ( '-' ) {
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments