diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-06 04:37:12 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-06 04:37:12 +0000 |
commit | 90e82ed3d1bb03921f2b4c447f1a93fa1a4b33fc (patch) | |
tree | f11ca3295133a72a83c27d4a4b44fc214f54507d | |
parent | 60aaa0da2e880e6e094baed10a8a441a6d4a9c5f (diff) | |
parent | 5e999457689e4dabbc1720ea9ce684ef78286df0 (diff) | |
download | nix-90e82ed3d1bb03921f2b4c447f1a93fa1a4b33fc.zip |
Merge #851
851: Added `getsid` in `::nix::unistd` r=asomers a=ggriffiniii
Resolves Issue #850
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/unistd.rs | 11 | ||||
-rw-r--r-- | test/test_unistd.rs | 8 |
3 files changed, 21 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index dda99f98..2571a71e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added +- Added `getsid` in `::nix::unistd` + ([#850](https://github.com/nix-rust/nix/pull/850)) - Added `alarm`. ([#830](https://github.com/nix-rust/nix/pull/830)) diff --git a/src/unistd.rs b/src/unistd.rs index 5f3a3806..8022aa0b 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -264,6 +264,17 @@ pub fn setsid() -> Result<Pid> { Errno::result(unsafe { libc::setsid() }).map(Pid) } +/// Get the process group ID of a session leader +/// [getsid(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsid.html). +/// +/// Obtain the process group ID of the process that is the session leader of the process specified +/// by pid. If pid is zero, it specifies the calling process. +#[inline] +pub fn getsid(pid: Option<Pid>) -> Result<Pid> { + let res = unsafe { libc::getsid(pid.unwrap_or(Pid(0)).into()) }; + Errno::result(res).map(Pid) +} + /// Get the terminal foreground process group (see /// [tcgetpgrp(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetpgrp.html)). diff --git a/test/test_unistd.rs b/test/test_unistd.rs index d78b6ba8..fe33b1d0 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -108,6 +108,14 @@ fn test_getpid() { assert!(ppid > 0); } +#[test] +fn test_getsid() { + let none_sid: ::libc::pid_t = getsid(None).unwrap().into(); + let pid_sid: ::libc::pid_t = getsid(Some(getpid())).unwrap().into(); + assert!(none_sid > 0); + assert!(none_sid == pid_sid); +} + #[cfg(any(target_os = "linux", target_os = "android"))] mod linux_android { use nix::unistd::gettid; |