From 18c85d5022f7abfea07724eaea0f6e3d77aaf733 Mon Sep 17 00:00:00 2001 From: zethra Date: Fri, 28 Oct 2016 14:43:55 -0400 Subject: [PATCH 1/4] Added tcgetpgrp and tcsetpgrp --- src/unistd.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/unistd.rs b/src/unistd.rs index a1953115f6..951722cd8e 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -68,6 +68,17 @@ pub fn getpgid(pid: Option) -> Result { Errno::result(res) } +#[inline] +pub fn tcgetgrp(fd: c_int) -> Result { + let res = unsafe { libc::tcgetpgrp(fd) }; + Errno::result(res) +} +#[inline] +pub fn tcsetpgrp(fd: c_int, pgrp: pid_t) -> Result { + let res = unsafe { libc::tcsetpgrp(fd, pgrp) }; + Errno::result(res) +} + #[cfg(any(target_os = "linux", target_os = "android"))] #[inline] pub fn gettid() -> pid_t { From baf6b8d520fe11aa88d202415f637c01c1ba7044 Mon Sep 17 00:00:00 2001 From: zethra Date: Tue, 8 Nov 2016 10:23:14 -0500 Subject: [PATCH 2/4] Added documention to tcgetpgrp and tcsetpgrp --- src/unistd.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/unistd.rs b/src/unistd.rs index 771a50fba9..838b11eb74 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -129,6 +129,28 @@ pub fn setsid() -> Result { Errno::result(unsafe { libc::setsid() }) } + +/// Get the terminal foreground process group (see +/// [tcgetpgrp(3)](http://man7.org/linux/man-pages/man3/tcgetpgrp.3.html)). +/// +/// Get the group process id (GPID) of the foreground process group on the +/// terminal associated to file descriptor (FD). +#[inline] +pub fn tcgetgrp(fd: c_int) -> Result { + let res = unsafe { libc::tcgetpgrp(fd) }; + Errno::result(res) +} +/// Set the terminal foreground process group (see +/// [tcgetpgrp(3)](http://man7.org/linux/man-pages/man3/tcgetpgrp.3.html)). +/// +/// Get the group process id (PGID) to the foreground process group on the +/// terminal associated to file descriptor (FD). +#[inline] +pub fn tcsetpgrp(fd: c_int, pgrp: pid_t) -> Result { + let res = unsafe { libc::tcsetpgrp(fd, pgrp) }; + Errno::result(res) +} + /// Get the caller's thread ID (see /// [gettid(2)](http://man7.org/linux/man-pages/man2/gettid.2.html). /// From f7ad7f8bcb675261bdc9e0efa121a8ce8271d238 Mon Sep 17 00:00:00 2001 From: zethra Date: Tue, 8 Nov 2016 10:26:06 -0500 Subject: [PATCH 3/4] Updated CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c87b045eac..fa5ebb3831 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ([#448](/~https://github.com/nix-rust/nix/pull/448)) - Added `getpgid` in `::nix::unistd` ([#433](/~https://github.com/nix-rust/nix/pull/433)) +- Added `tcgetpgrp` and `tcsetpgrp` in `::nix::unistd` + ([#451](/~https://github.com/nix-rust/nix/pull/451)) ### Changed - The minimum supported version of rustc is now 1.7.0. From 013e7c8bd2e14b0a61ca265d1aae3a1e25640dea Mon Sep 17 00:00:00 2001 From: zethra Date: Tue, 8 Nov 2016 10:30:31 -0500 Subject: [PATCH 4/4] Added .map(drop) as requested --- src/unistd.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unistd.rs b/src/unistd.rs index 9bdc587693..e97bcdb9d3 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -146,9 +146,9 @@ pub fn tcgetgrp(fd: c_int) -> Result { /// Get the group process id (PGID) to the foreground process group on the /// terminal associated to file descriptor (FD). #[inline] -pub fn tcsetpgrp(fd: c_int, pgrp: pid_t) -> Result { +pub fn tcsetpgrp(fd: c_int, pgrp: pid_t) -> Result<()> { let res = unsafe { libc::tcsetpgrp(fd, pgrp) }; - Errno::result(res) + Errno::result(res).map(drop) } /// Get the caller's thread ID (see