mirror of
https://gitee.com/openharmony/third_party_rust_nix
synced 2025-02-20 16:43:34 +00:00
feat: Add killpg
This commit is contained in:
parent
426c2921bb
commit
8d0188435b
@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
Android and Linux. ([#1016](https://github.com/nix-rust/nix/pull/1016))
|
||||
- Add `ALG_SET_IV`, `ALG_SET_OP` and `ALG_SET_AEAD_ASSOCLEN` control messages and `AF_ALG`
|
||||
socket types on Linux and Android ([#1031](https://github.com/nix-rust/nix/pull/1031))
|
||||
- Add killpg
|
||||
([#1034](https://github.com/nix-rust/nix/pull/1034))
|
||||
|
||||
### Changed
|
||||
- `PollFd` event flags renamed to `PollFlags` ([#1024](https://github.com/nix-rust/nix/pull/1024/))
|
||||
|
@ -680,6 +680,22 @@ pub fn kill<T: Into<Option<Signal>>>(pid: ::unistd::Pid, signal: T) -> Result<()
|
||||
Errno::result(res).map(drop)
|
||||
}
|
||||
|
||||
/// Send a signal to a process group [(see
|
||||
/// killpg(3))](http://pubs.opengroup.org/onlinepubs/9699919799/functions/killpg.html).
|
||||
///
|
||||
/// If `pgrp` less then or equal 1, the behavior is platform-specific.
|
||||
/// If `signal` is `None`, `killpg` will only preform error checking and won't
|
||||
/// send any signal.
|
||||
pub fn killpg<T: Into<Option<Signal>>>(pgrp: ::unistd::Pid, signal: T) -> Result<()> {
|
||||
let res = unsafe { libc::killpg(pgrp.into(),
|
||||
match signal.into() {
|
||||
Some(s) => s as libc::c_int,
|
||||
None => 0,
|
||||
}) };
|
||||
|
||||
Errno::result(res).map(drop)
|
||||
}
|
||||
|
||||
pub fn raise(signal: Signal) -> Result<()> {
|
||||
let res = unsafe { libc::raise(signal as libc::c_int) };
|
||||
|
||||
|
@ -9,6 +9,12 @@ fn test_kill_none() {
|
||||
kill(getpid(), None).expect("Should be able to send signal to myself.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_killpg_none() {
|
||||
killpg(getpgrp(), None)
|
||||
.expect("Should be able to send signal to my process group.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_old_sigaction_flags() {
|
||||
extern "C" fn handler(_: ::libc::c_int) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user