Update to perform cloexec in kernel

This commit is contained in:
Jeremy Soller 2017-04-16 12:54:14 -06:00
parent 58b1e57d22
commit cd5332c973
7 changed files with 41 additions and 7 deletions

View file

@ -11,7 +11,7 @@ use std::str;
use syscall::data::Packet;
use syscall::error::{Error, Result, EBADF, EINVAL, ENOENT, EPIPE, EWOULDBLOCK};
use syscall::flag::O_NONBLOCK;
use syscall::flag::{F_GETFL, F_SETFL, O_ACCMODE, O_NONBLOCK};
use syscall::scheme::SchemeMut;
pub struct PtyScheme {
@ -102,6 +102,18 @@ impl SchemeMut for PtyScheme {
Err(Error::new(EBADF))
}
fn fcntl(&mut self, id: usize, cmd: usize, arg: usize) -> Result<usize> {
if let Some(pipe) = self.ptys.0.get_mut(&id) {
return pipe.fcntl(cmd, arg);
}
if let Some(pipe) = self.ptys.1.get_mut(&id) {
return pipe.fcntl(cmd, arg);
}
Err(Error::new(EBADF))
}
fn fevent(&mut self, id: usize, _flags: usize) -> Result<usize> {
if self.ptys.0.contains_key(&id) || self.ptys.1.contains_key(&id) {
Ok(id)
@ -203,6 +215,17 @@ impl PtyMaster {
Ok(i)
}
fn fcntl(&mut self, cmd: usize, arg: usize) -> Result<usize> {
match cmd {
F_GETFL => Ok(self.flags),
F_SETFL => {
self.flags = arg & ! O_ACCMODE;
Ok(0)
},
_ => Err(Error::new(EINVAL))
}
}
}
/// Read side of a pipe
@ -286,6 +309,17 @@ impl PtySlave {
Err(Error::new(EPIPE))
}
}
fn fcntl(&mut self, cmd: usize, arg: usize) -> Result<usize> {
match cmd {
F_GETFL => Ok(self.flags),
F_SETFL => {
self.flags = arg & ! O_ACCMODE;
Ok(0)
},
_ => Err(Error::new(EINVAL))
}
}
}
fn main(){