Commit 032a45c5 authored by Jeremy Soller's avatar Jeremy Soller

Open stdio without cloexec

parent 6c1f4767
......@@ -3,16 +3,23 @@
extern crate syscall;
use std::env;
use std::fs::{File, OpenOptions, read_dir};
use std::fs::{File, read_dir};
use std::io::{Read, Error, Result};
use std::os::unix::io::AsRawFd;
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::path::Path;
use std::process::Command;
use syscall::flag::{O_RDONLY, O_WRONLY};
fn switch_stdio(stdio: &str) -> Result<()> {
let stdin = OpenOptions::new().read(true).open(stdio)?;
let stdout = OpenOptions::new().write(true).open(stdio)?;
let stderr = OpenOptions::new().write(true).open(stdio)?;
let stdin = unsafe { File::from_raw_fd(
syscall::open(stdio, O_RDONLY).map_err(|err| Error::from_raw_os_error(err.errno))?
) };
let stdout = unsafe { File::from_raw_fd(
syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))?
) };
let stderr = unsafe { File::from_raw_fd(
syscall::open(stdio, O_WRONLY).map_err(|err| Error::from_raw_os_error(err.errno))?
) };
syscall::dup2(stdin.as_raw_fd(), 0, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?;
syscall::dup2(stdout.as_raw_fd(), 1, &[]).map_err(|err| Error::from_raw_os_error(err.errno))?;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment