diff options
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 16 | ||||
| -rw-r--r-- | src/libstd/sys/windows/process.rs | 11 |
2 files changed, 12 insertions, 15 deletions
diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 41b9b3ef126..f776af29616 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -275,7 +275,7 @@ pub struct Process { pub enum Stdio { Inherit, - None, + Null, Raw(c_int), } @@ -416,7 +416,7 @@ impl Process { Stdio::Raw(fd.into_raw()) }) } - s @ Stdio::None | + s @ Stdio::Null | s @ Stdio::Inherit | s @ Stdio::Raw(_) => Ok(s), } @@ -430,12 +430,10 @@ impl Process { Stdio::Inherit => Ok(()), Stdio::Raw(fd) => cvt_r(|| libc::dup2(fd, dst)).map(|_| ()), - // If a stdio file descriptor is set to be ignored, we open up - // /dev/null into that file descriptor. Otherwise, the first - // file descriptor opened up in the child would be numbered as - // one of the stdio file descriptors, which is likely to wreak - // havoc. - Stdio::None => { + // Open up a reference to /dev/null with appropriate read/write + // permissions and then move it into the correct location via + // `dup2`. + Stdio::Null => { let mut opts = OpenOptions::new(); opts.read(dst == libc::STDIN_FILENO); opts.write(dst != libc::STDIN_FILENO); @@ -590,7 +588,7 @@ mod tests { let cat = t!(Process::spawn(&cmd, Stdio::Raw(stdin_read.raw()), Stdio::Raw(stdout_write.raw()), - Stdio::None)); + Stdio::Null)); drop(stdin_read); drop(stdout_write); diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index e5e4187d228..8a522a0a795 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -122,7 +122,7 @@ pub struct Process { pub enum Stdio { Inherit, - None, + Null, Raw(c::HANDLE), } @@ -386,11 +386,10 @@ impl Stdio { RawHandle::new(handle).duplicate(0, true, c::DUPLICATE_SAME_ACCESS) } - // Similarly to unix, we don't actually leave holes for the - // stdio file descriptors, but rather open up /dev/null - // equivalents. These equivalents are drawn from libuv's - // windows process spawning. - Stdio::None => { + // Open up a reference to NUL with appropriate read/write + // permissions as well as the ability to be inherited to child + // processes (as this is about to be inherited). + Stdio::Null => { let size = mem::size_of::<c::SECURITY_ATTRIBUTES>(); let mut sa = c::SECURITY_ATTRIBUTES { nLength: size as c::DWORD, |
