summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryant Mairs <bryant@mai.rs>2017-06-29 20:44:04 -0700
committerBryant Mairs <bryant@mai.rs>2017-07-10 20:49:42 -0700
commit55d68d9f734a911dcb5cb6fd53636be19f75acc2 (patch)
tree98104d8da39b82aa94f73eac44b2221f9ea72db5
parent3b66681f5330b091f260899f358a5cd1973d22bf (diff)
downloadnix-55d68d9f734a911dcb5cb6fd53636be19f75acc2.zip
Add tcgetsid()
-rw-r--r--src/sys/termios.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 2a815158..8651a84d 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -50,6 +50,8 @@ use std::convert::From;
use std::mem;
use std::os::unix::io::RawFd;
+use ::unistd::Pid;
+
/// Stores settings for the termios API
///
/// This is a wrapper around the `libc::termios` struct that provides a safe interface for the
@@ -883,3 +885,11 @@ pub fn tcflush(fd: RawFd, action: FlushArg) -> Result<()> {
pub fn tcsendbreak(fd: RawFd, duration: c_int) -> Result<()> {
Errno::result(unsafe { libc::tcsendbreak(fd, duration) }).map(drop)
}
+
+/// Get the session controlled by the given terminal (see
+/// [tcgetsid(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetsid.html)).
+pub fn tcgetsid(fd: RawFd) -> Result<Pid> {
+ let res = unsafe { libc::tcgetsid(fd) };
+
+ Errno::result(res).map(Pid::from_raw)
+}