Skip to content

Commit 9b4a787

Browse files
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>
1 parent aaaf4c3 commit 9b4a787

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/uu/kill/src/kill.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
6464
.try_into()
6565
.map_err(|e| std::io::Error::from_raw_os_error(e as i32))?;
6666
let pids = parse_pids(&pids_or_signals)?;
67-
kill(sig, &pids);
68-
Ok(())
67+
if pids.is_empty() {
68+
Err(USimpleError::new(
69+
1,
70+
"no process ID specified\n\
71+
Try --help for more information.",
72+
))
73+
} else {
74+
kill(sig, &pids);
75+
Ok(())
76+
}
6977
}
7078
Mode::Table => {
7179
table();

tests/by-util/test_kill.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,11 @@ fn test_kill_with_signal_prefixed_name_new_form() {
204204
.succeeds();
205205
assert_eq!(target.wait_for_signal(), Some(libc::SIGKILL));
206206
}
207+
208+
#[test]
209+
fn test_kill_no_pid_provided() {
210+
// spell-checker:disable-line
211+
new_ucmd!()
212+
.fails()
213+
.stderr_contains("no process ID specified");
214+
}

0 commit comments

Comments
 (0)