From 9b4a787be7bd9b30cabfa008e28a342073117f0f Mon Sep 17 00:00:00 2001 From: Jadi Date: Sun, 14 Apr 2024 15:43:15 +0330 Subject: [PATCH] kill: return 1 and gnu style stderr in case of no pid (#6225) * kill: return 1 and gnu style stderr in case of no pid closes #6221 * Update src/uu/kill/src/kill.rs Co-authored-by: Ben Wiederhake --------- Co-authored-by: Ben Wiederhake --- src/uu/kill/src/kill.rs | 12 ++++++++++-- tests/by-util/test_kill.rs | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 751449462..a641ff0c8 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -64,8 +64,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .try_into() .map_err(|e| std::io::Error::from_raw_os_error(e as i32))?; let pids = parse_pids(&pids_or_signals)?; - kill(sig, &pids); - Ok(()) + if pids.is_empty() { + Err(USimpleError::new( + 1, + "no process ID specified\n\ + Try --help for more information.", + )) + } else { + kill(sig, &pids); + Ok(()) + } } Mode::Table => { table(); diff --git a/tests/by-util/test_kill.rs b/tests/by-util/test_kill.rs index a9a94ba5c..61d18686a 100644 --- a/tests/by-util/test_kill.rs +++ b/tests/by-util/test_kill.rs @@ -204,3 +204,11 @@ fn test_kill_with_signal_prefixed_name_new_form() { .succeeds(); assert_eq!(target.wait_for_signal(), Some(libc::SIGKILL)); } + +#[test] +fn test_kill_no_pid_provided() { + // spell-checker:disable-line + new_ucmd!() + .fails() + .stderr_contains("no process ID specified"); +}