From e0264ff192a6dcca1a9fa15a740f7ddb9890d74c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 4 Dec 2013 08:51:47 -0800 Subject: Don't dup the stdio file descriptors. This is just an implementation detail of using libuv, so move the libuv-specific logic into librustuv. --- src/libstd/io/native/mod.rs | 4 +++- src/libstd/io/stdio.rs | 14 ++------------ 2 files changed, 5 insertions(+), 13 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/native/mod.rs b/src/libstd/io/native/mod.rs index cec0de00ec2..c92f480728e 100644 --- a/src/libstd/io/native/mod.rs +++ b/src/libstd/io/native/mod.rs @@ -206,7 +206,9 @@ impl rtio::IoFactory for IoFactory { } fn tty_open(&mut self, fd: c_int, _readable: bool) -> IoResult<~RtioTTY> { if unsafe { libc::isatty(fd) } != 0 { - Ok(~file::FileDesc::new(fd, true) as ~RtioTTY) + // Don't ever close the stdio file descriptors, nothing good really + // comes of that. + Ok(~file::FileDesc::new(fd, fd > libc::STDERR_FILENO) as ~RtioTTY) } else { Err(IoError { kind: io::MismatchedFileTypeForOperation, diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index fe0385c9a95..466a65a227e 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -31,8 +31,7 @@ use libc; use option::{Option, Some, None}; use result::{Ok, Err}; use io::buffered::LineBufferedWriter; -use rt::rtio::{IoFactory, RtioTTY, RtioFileStream, with_local_io, - CloseAsynchronously}; +use rt::rtio::{IoFactory, RtioTTY, RtioFileStream, with_local_io, DontClose}; use super::{Reader, Writer, io_error, IoError, OtherIoError, standard_error, EndOfFile}; @@ -71,18 +70,9 @@ enum StdSource { fn src(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T { with_local_io(|io| { - let fd = unsafe { libc::dup(fd) }; match io.tty_open(fd, readable) { Ok(tty) => Some(f(TTY(tty))), - Err(_) => { - // It's not really that desirable if these handles are closed - // synchronously, and because they're squirreled away in a task - // structure the destructors will be run when the task is - // attempted to get destroyed. This means that if we run a - // synchronous destructor we'll attempt to do some scheduling - // operations which will just result in sadness. - Some(f(File(io.fs_from_raw_fd(fd, CloseAsynchronously)))) - } + Err(_) => Some(f(File(io.fs_from_raw_fd(fd, DontClose)))), } }).unwrap() } -- cgit 1.4.1-3-g733a5