Skip to content

Commit

Permalink
Merge #851
Browse files Browse the repository at this point in the history
851: Added `getsid` in `::nix::unistd` r=asomers a=ggriffiniii

Resolves Issue #850
  • Loading branch information
bors[bot] committed Feb 6, 2018
2 parents 60aaa0d + 5e99945 commit 90e82ed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
11 changes: 11 additions & 0 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down
8 changes: 8 additions & 0 deletions test/test_unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 90e82ed

Please sign in to comment.