1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

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 15:43:15 +03:30 committed by GitHub
parent aaaf4c3f91
commit 9b4a787be7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

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();

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");
}