diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-05-12 11:03:49 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-05-16 11:18:36 -0700 |
| commit | 3dd3450484c1a914d07da2ab522e3bd27ce2a4bb (patch) | |
| tree | 036734c4a002be0f56eb75901802ac32f9a5000d /src/libstd/sys/unix/ext/process.rs | |
| parent | 5e535eae5c4b70879aefc050a5fe0b8137c07eac (diff) | |
| download | rust-3dd3450484c1a914d07da2ab522e3bd27ce2a4bb.tar.gz rust-3dd3450484c1a914d07da2ab522e3bd27ce2a4bb.zip | |
std: Implement lowering and raising for process IO
This commit implements a number of standard traits for the standard library's
process I/O handles. The `FromRaw{Fd,Handle}` traits are now implemented for the
`Stdio` type and the `AsRaw{Fd,Handle}` traits are now implemented for the
`Child{Stdout,Stdin,Stderr}` types. Additionally this implements the
`AsRawHandle` trait for `Child` on Windows.
The stability markers for these implementations mention that they are stable for
1.1 as I will nominate this commit for cherry-picking to beta.
Diffstat (limited to 'src/libstd/sys/unix/ext/process.rs')
| -rw-r--r-- | src/libstd/sys/unix/ext/process.rs | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/libstd/sys/unix/ext/process.rs b/src/libstd/sys/unix/ext/process.rs index 45d0d62a015..2d30b016a2d 100644 --- a/src/libstd/sys/unix/ext/process.rs +++ b/src/libstd/sys/unix/ext/process.rs @@ -13,10 +13,11 @@ #![stable(feature = "rust1", since = "1.0.0")] use os::unix::raw::{uid_t, gid_t}; +use os::unix::io::{FromRawFd, RawFd, AsRawFd}; use prelude::v1::*; use process; use sys; -use sys_common::{AsInnerMut, AsInner}; +use sys_common::{AsInnerMut, AsInner, FromInner}; /// Unix-specific extensions to the `std::process::Command` builder #[stable(feature = "rust1", since = "1.0.0")] @@ -63,3 +64,49 @@ impl ExitStatusExt for process::ExitStatus { } } } + +#[stable(feature = "from_raw_os", since = "1.1.0")] +impl FromRawFd for process::Stdio { + /// Creates a new instance of `Stdio` from the raw underlying file + /// descriptor. + /// + /// When this `Stdio` is used as an I/O handle for a child process the given + /// file descriptor will be `dup`d into the destination file descriptor in + /// the child process. + /// + /// Note that this function **does not** take ownership of the file + /// descriptor provided and it will **not** be closed when `Stdio` goes out + /// of scope. As a result this method is unsafe because due to the lack of + /// knowledge about the lifetime of the provided file descriptor, this could + /// cause another I/O primitive's ownership property of its file descriptor + /// to be violated. + /// + /// Also note that this file descriptor may be used multiple times to spawn + /// processes. For example the `Command::spawn` function could be called + /// more than once to spawn more than one process sharing this file + /// descriptor. + unsafe fn from_raw_fd(fd: RawFd) -> process::Stdio { + process::Stdio::from_inner(sys::process::Stdio::Fd(fd)) + } +} + +#[stable(feature = "from_raw_os", since = "1.1.0")] +impl AsRawFd for process::ChildStdin { + fn as_raw_fd(&self) -> RawFd { + self.as_inner().fd().raw() + } +} + +#[stable(feature = "from_raw_os", since = "1.1.0")] +impl AsRawFd for process::ChildStdout { + fn as_raw_fd(&self) -> RawFd { + self.as_inner().fd().raw() + } +} + +#[stable(feature = "from_raw_os", since = "1.1.0")] +impl AsRawFd for process::ChildStderr { + fn as_raw_fd(&self) -> RawFd { + self.as_inner().fd().raw() + } +} |
