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 <BenWiederhake.GitHub@gmx.de>

---------

Co-authored-by: Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
This commit is contained in:
Jadi
2024-04-14 14:13:15 +02:00
committed by GitHub
co-authored by Ben Wiederhake
parent aaaf4c3f91
commit 9b4a787be7
2 changed files with 18 additions and 2 deletions
+10 -2
View File
@@ -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();
+8
View File
@@ -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");
}