Skip to content

Commit 3ccd037

Browse files
bors[bot]DanSnow
andcommitted
Merge #1034
1034: Add killpg r=asomers a=DanSnow It's seem that #644 is inactively about 1 year. But I really want this API that can land in nix. Actually I not really understand how to check the availability of an API for other platform except Linux. But I saw that this API in `libc` is wrapping inside a `#[cfg(unix)]`. So I don't need to add any `#[cfg]` on this API, am I right? Resolved #644 Co-authored-by: DanSnow <[email protected]>
2 parents 426c292 + 8d01884 commit 3ccd037

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1111
Android and Linux. ([#1016](https://github.com/nix-rust/nix/pull/1016))
1212
- Add `ALG_SET_IV`, `ALG_SET_OP` and `ALG_SET_AEAD_ASSOCLEN` control messages and `AF_ALG`
1313
socket types on Linux and Android ([#1031](https://github.com/nix-rust/nix/pull/1031))
14+
- Add killpg
15+
([#1034](https://github.com/nix-rust/nix/pull/1034))
1416

1517
### Changed
1618
- `PollFd` event flags renamed to `PollFlags` ([#1024](https://github.com/nix-rust/nix/pull/1024/))

src/sys/signal.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,22 @@ pub fn kill<T: Into<Option<Signal>>>(pid: ::unistd::Pid, signal: T) -> Result<()
680680
Errno::result(res).map(drop)
681681
}
682682

683+
/// Send a signal to a process group [(see
684+
/// killpg(3))](http://pubs.opengroup.org/onlinepubs/9699919799/functions/killpg.html).
685+
///
686+
/// If `pgrp` less then or equal 1, the behavior is platform-specific.
687+
/// If `signal` is `None`, `killpg` will only preform error checking and won't
688+
/// send any signal.
689+
pub fn killpg<T: Into<Option<Signal>>>(pgrp: ::unistd::Pid, signal: T) -> Result<()> {
690+
let res = unsafe { libc::killpg(pgrp.into(),
691+
match signal.into() {
692+
Some(s) => s as libc::c_int,
693+
None => 0,
694+
}) };
695+
696+
Errno::result(res).map(drop)
697+
}
698+
683699
pub fn raise(signal: Signal) -> Result<()> {
684700
let res = unsafe { libc::raise(signal as libc::c_int) };
685701

test/sys/test_signal.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ fn test_kill_none() {
99
kill(getpid(), None).expect("Should be able to send signal to myself.");
1010
}
1111

12+
#[test]
13+
fn test_killpg_none() {
14+
killpg(getpgrp(), None)
15+
.expect("Should be able to send signal to my process group.");
16+
}
17+
1218
#[test]
1319
fn test_old_sigaction_flags() {
1420
extern "C" fn handler(_: ::libc::c_int) {}

0 commit comments

Comments
 (0)