2015-04-16 06:21:13 +00:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Unix-specific extensions to primitives in the `std::process` module.
|
|
|
|
|
|
|
|
#![stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
2016-02-04 00:55:59 +00:00
|
|
|
use prelude::v1::*;
|
|
|
|
|
|
|
|
use io;
|
2015-07-16 06:31:24 +00:00
|
|
|
use os::unix::io::{FromRawFd, RawFd, AsRawFd, IntoRawFd};
|
2015-04-16 06:21:13 +00:00
|
|
|
use process;
|
|
|
|
use sys;
|
2015-07-16 06:31:24 +00:00
|
|
|
use sys_common::{AsInnerMut, AsInner, FromInner, IntoInner};
|
2015-04-16 06:21:13 +00:00
|
|
|
|
|
|
|
/// Unix-specific extensions to the `std::process::Command` builder
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
pub trait CommandExt {
|
|
|
|
/// Sets the child process's user id. This translates to a
|
|
|
|
/// `setuid` call in the child process. Failure in the `setuid`
|
|
|
|
/// call will cause the spawn to fail.
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
std: Deprecate all std::os::*::raw types
This commit is an implementation of [RFC 1415][rfc] which deprecates all types
in the `std::os::*::raw` modules.
[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1415-trim-std-os.md
Many of the types in these modules don't actually have a canonical platform
representation, for example the definition of `stat` on 32-bit Linux will change
depending on whether C code is compiled with LFS support or not. Unfortunately
the current types in `std::os::*::raw` are billed as "compatible with C", which
in light of this means it isn't really possible.
To make matters worse, platforms like Android sometimes define these types as
*smaller* than the way they're actually represented in the `stat` structure
itself. This means that when methods like `DirEntry::ino` are called on Android
the result may be truncated as we're tied to returning a `ino_t` type, not the
underlying type.
The commit here incorporates two backwards-compatible components:
* Deprecate all `raw` types that aren't in `std::os::raw`
* Expand the `std::os::*::fs::MetadataExt` trait on all platforms for method
accessors of all fields. The fields now returned widened types which are the
same across platforms (consistency across platforms is not required, however,
it's just convenient).
and two also backwards-incompatible components:
* Change the definition of all `std::os::*::raw` type aliases to
correspond to the newly widened types that are being returned on each
platform.
* Change the definition of `std::os::*::raw::stat` on Linux to match the LFS
definitions rather than the standard ones.
The breaking changes here will specifically break code that assumes that `libc`
and `std` agree on the definition of `std::os::*::raw` types, or that the `std`
types are faithful representations of the types in C. An [audit] has been
performed of crates.io to determine the fallout which was determined two be
minimal, with the two found cases of breakage having been fixed now.
[audit]: https://github.com/rust-lang/rfcs/pull/1415#issuecomment-180645582
---
Ok, so after all that, we're finally able to support LFS on Linux! This commit
then simultaneously starts using `stat64` and friends on Linux to ensure that we
can open >4GB files on 32-bit Linux. Yay!
Closes #28978
Closes #30050
Closes #31549
2016-02-05 01:16:47 +00:00
|
|
|
fn uid(&mut self, id: u32) -> &mut process::Command;
|
2015-04-16 06:21:13 +00:00
|
|
|
|
|
|
|
/// Similar to `uid`, but sets the group id of the child process. This has
|
|
|
|
/// the same semantics as the `uid` field.
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
std: Deprecate all std::os::*::raw types
This commit is an implementation of [RFC 1415][rfc] which deprecates all types
in the `std::os::*::raw` modules.
[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1415-trim-std-os.md
Many of the types in these modules don't actually have a canonical platform
representation, for example the definition of `stat` on 32-bit Linux will change
depending on whether C code is compiled with LFS support or not. Unfortunately
the current types in `std::os::*::raw` are billed as "compatible with C", which
in light of this means it isn't really possible.
To make matters worse, platforms like Android sometimes define these types as
*smaller* than the way they're actually represented in the `stat` structure
itself. This means that when methods like `DirEntry::ino` are called on Android
the result may be truncated as we're tied to returning a `ino_t` type, not the
underlying type.
The commit here incorporates two backwards-compatible components:
* Deprecate all `raw` types that aren't in `std::os::raw`
* Expand the `std::os::*::fs::MetadataExt` trait on all platforms for method
accessors of all fields. The fields now returned widened types which are the
same across platforms (consistency across platforms is not required, however,
it's just convenient).
and two also backwards-incompatible components:
* Change the definition of all `std::os::*::raw` type aliases to
correspond to the newly widened types that are being returned on each
platform.
* Change the definition of `std::os::*::raw::stat` on Linux to match the LFS
definitions rather than the standard ones.
The breaking changes here will specifically break code that assumes that `libc`
and `std` agree on the definition of `std::os::*::raw` types, or that the `std`
types are faithful representations of the types in C. An [audit] has been
performed of crates.io to determine the fallout which was determined two be
minimal, with the two found cases of breakage having been fixed now.
[audit]: https://github.com/rust-lang/rfcs/pull/1415#issuecomment-180645582
---
Ok, so after all that, we're finally able to support LFS on Linux! This commit
then simultaneously starts using `stat64` and friends on Linux to ensure that we
can open >4GB files on 32-bit Linux. Yay!
Closes #28978
Closes #30050
Closes #31549
2016-02-05 01:16:47 +00:00
|
|
|
fn gid(&mut self, id: u32) -> &mut process::Command;
|
2015-06-21 14:43:19 +00:00
|
|
|
|
2016-02-04 00:55:59 +00:00
|
|
|
/// Schedules a closure to be run just before the `exec` function is
|
|
|
|
/// invoked.
|
|
|
|
///
|
|
|
|
/// The closure is allowed to return an I/O error whose OS error code will
|
|
|
|
/// be communicated back to the parent and returned as an error from when
|
|
|
|
/// the spawn was requested.
|
|
|
|
///
|
|
|
|
/// Multiple closures can be registered and they will be called in order of
|
|
|
|
/// their registration. If a closure returns `Err` then no further closures
|
|
|
|
/// will be called and the spawn operation will immediately return with a
|
|
|
|
/// failure.
|
|
|
|
///
|
|
|
|
/// # Notes
|
|
|
|
///
|
|
|
|
/// This closure will be run in the context of the child process after a
|
|
|
|
/// `fork`. This primarily means that any modificatons made to memory on
|
|
|
|
/// behalf of this closure will **not** be visible to the parent process.
|
|
|
|
/// This is often a very constrained environment where normal operations
|
|
|
|
/// like `malloc` or acquiring a mutex are not guaranteed to work (due to
|
|
|
|
/// other threads perhaps still running when the `fork` was run).
|
|
|
|
///
|
|
|
|
/// When this closure is run, aspects such as the stdio file descriptors and
|
|
|
|
/// working directory have successfully been changed, so output to these
|
|
|
|
/// locations may not appear where intended.
|
|
|
|
#[unstable(feature = "process_exec", issue = "31398")]
|
|
|
|
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
|
|
|
|
where F: FnMut() -> io::Result<()> + Send + Sync + 'static;
|
2016-02-04 19:16:32 +00:00
|
|
|
|
|
|
|
/// Performs all the required setup by this `Command`, followed by calling
|
|
|
|
/// the `execvp` syscall.
|
|
|
|
///
|
|
|
|
/// On success this function will not return, and otherwise it will return
|
|
|
|
/// an error indicating why the exec (or another part of the setup of the
|
|
|
|
/// `Command`) failed.
|
|
|
|
///
|
|
|
|
/// This function, unlike `spawn`, will **not** `fork` the process to create
|
|
|
|
/// a new child. Like spawn, however, the default behavior for the stdio
|
|
|
|
/// descriptors will be to inherited from the current process.
|
|
|
|
///
|
|
|
|
/// # Notes
|
|
|
|
///
|
|
|
|
/// The process may be in a "broken state" if this function returns in
|
|
|
|
/// error. For example the working directory, environment variables, signal
|
|
|
|
/// handling settings, various user/group information, or aspects of stdio
|
|
|
|
/// file descriptors may have changed. If a "transactional spawn" is
|
|
|
|
/// required to gracefully handle errors it is recommended to use the
|
|
|
|
/// cross-platform `spawn` instead.
|
2016-04-07 17:42:53 +00:00
|
|
|
#[stable(feature = "process_exec2", since = "1.9.0")]
|
2016-02-04 19:16:32 +00:00
|
|
|
fn exec(&mut self) -> io::Error;
|
2015-04-16 06:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl CommandExt for process::Command {
|
std: Deprecate all std::os::*::raw types
This commit is an implementation of [RFC 1415][rfc] which deprecates all types
in the `std::os::*::raw` modules.
[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1415-trim-std-os.md
Many of the types in these modules don't actually have a canonical platform
representation, for example the definition of `stat` on 32-bit Linux will change
depending on whether C code is compiled with LFS support or not. Unfortunately
the current types in `std::os::*::raw` are billed as "compatible with C", which
in light of this means it isn't really possible.
To make matters worse, platforms like Android sometimes define these types as
*smaller* than the way they're actually represented in the `stat` structure
itself. This means that when methods like `DirEntry::ino` are called on Android
the result may be truncated as we're tied to returning a `ino_t` type, not the
underlying type.
The commit here incorporates two backwards-compatible components:
* Deprecate all `raw` types that aren't in `std::os::raw`
* Expand the `std::os::*::fs::MetadataExt` trait on all platforms for method
accessors of all fields. The fields now returned widened types which are the
same across platforms (consistency across platforms is not required, however,
it's just convenient).
and two also backwards-incompatible components:
* Change the definition of all `std::os::*::raw` type aliases to
correspond to the newly widened types that are being returned on each
platform.
* Change the definition of `std::os::*::raw::stat` on Linux to match the LFS
definitions rather than the standard ones.
The breaking changes here will specifically break code that assumes that `libc`
and `std` agree on the definition of `std::os::*::raw` types, or that the `std`
types are faithful representations of the types in C. An [audit] has been
performed of crates.io to determine the fallout which was determined two be
minimal, with the two found cases of breakage having been fixed now.
[audit]: https://github.com/rust-lang/rfcs/pull/1415#issuecomment-180645582
---
Ok, so after all that, we're finally able to support LFS on Linux! This commit
then simultaneously starts using `stat64` and friends on Linux to ensure that we
can open >4GB files on 32-bit Linux. Yay!
Closes #28978
Closes #30050
Closes #31549
2016-02-05 01:16:47 +00:00
|
|
|
fn uid(&mut self, id: u32) -> &mut process::Command {
|
2016-01-15 20:29:45 +00:00
|
|
|
self.as_inner_mut().uid(id);
|
2015-04-16 06:21:13 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
std: Deprecate all std::os::*::raw types
This commit is an implementation of [RFC 1415][rfc] which deprecates all types
in the `std::os::*::raw` modules.
[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1415-trim-std-os.md
Many of the types in these modules don't actually have a canonical platform
representation, for example the definition of `stat` on 32-bit Linux will change
depending on whether C code is compiled with LFS support or not. Unfortunately
the current types in `std::os::*::raw` are billed as "compatible with C", which
in light of this means it isn't really possible.
To make matters worse, platforms like Android sometimes define these types as
*smaller* than the way they're actually represented in the `stat` structure
itself. This means that when methods like `DirEntry::ino` are called on Android
the result may be truncated as we're tied to returning a `ino_t` type, not the
underlying type.
The commit here incorporates two backwards-compatible components:
* Deprecate all `raw` types that aren't in `std::os::raw`
* Expand the `std::os::*::fs::MetadataExt` trait on all platforms for method
accessors of all fields. The fields now returned widened types which are the
same across platforms (consistency across platforms is not required, however,
it's just convenient).
and two also backwards-incompatible components:
* Change the definition of all `std::os::*::raw` type aliases to
correspond to the newly widened types that are being returned on each
platform.
* Change the definition of `std::os::*::raw::stat` on Linux to match the LFS
definitions rather than the standard ones.
The breaking changes here will specifically break code that assumes that `libc`
and `std` agree on the definition of `std::os::*::raw` types, or that the `std`
types are faithful representations of the types in C. An [audit] has been
performed of crates.io to determine the fallout which was determined two be
minimal, with the two found cases of breakage having been fixed now.
[audit]: https://github.com/rust-lang/rfcs/pull/1415#issuecomment-180645582
---
Ok, so after all that, we're finally able to support LFS on Linux! This commit
then simultaneously starts using `stat64` and friends on Linux to ensure that we
can open >4GB files on 32-bit Linux. Yay!
Closes #28978
Closes #30050
Closes #31549
2016-02-05 01:16:47 +00:00
|
|
|
fn gid(&mut self, id: u32) -> &mut process::Command {
|
2016-01-15 20:29:45 +00:00
|
|
|
self.as_inner_mut().gid(id);
|
2015-04-16 06:21:13 +00:00
|
|
|
self
|
|
|
|
}
|
2015-06-21 14:43:19 +00:00
|
|
|
|
2016-02-04 00:55:59 +00:00
|
|
|
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
|
|
|
|
where F: FnMut() -> io::Result<()> + Send + Sync + 'static
|
|
|
|
{
|
|
|
|
self.as_inner_mut().before_exec(Box::new(f));
|
|
|
|
self
|
|
|
|
}
|
2016-02-04 19:16:32 +00:00
|
|
|
|
|
|
|
fn exec(&mut self) -> io::Error {
|
|
|
|
self.as_inner_mut().exec(sys::process::Stdio::Inherit)
|
|
|
|
}
|
2015-04-16 06:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Unix-specific extensions to `std::process::ExitStatus`
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
pub trait ExitStatusExt {
|
2016-04-26 22:23:46 +00:00
|
|
|
/// Creates a new `ExitStatus` from the raw underlying `i32` return value of
|
|
|
|
/// a process.
|
|
|
|
#[unstable(feature = "exit_status_from", issue = "32713")]
|
|
|
|
fn from_raw(raw: i32) -> Self;
|
|
|
|
|
2015-04-16 06:21:13 +00:00
|
|
|
/// If the process was terminated by a signal, returns that signal.
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
fn signal(&self) -> Option<i32>;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl ExitStatusExt for process::ExitStatus {
|
2016-04-26 22:23:46 +00:00
|
|
|
fn from_raw(raw: i32) -> Self {
|
|
|
|
process::ExitStatus::from_inner(From::from(raw))
|
|
|
|
}
|
|
|
|
|
2015-04-16 06:21:13 +00:00
|
|
|
fn signal(&self) -> Option<i32> {
|
2015-10-29 20:45:56 +00:00
|
|
|
self.as_inner().signal()
|
2015-04-16 06:21:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-12 18:03:49 +00:00
|
|
|
|
2015-06-09 23:41:14 +00:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-05-12 18:03:49 +00:00
|
|
|
impl FromRawFd for process::Stdio {
|
|
|
|
unsafe fn from_raw_fd(fd: RawFd) -> process::Stdio {
|
2016-02-04 19:10:37 +00:00
|
|
|
let fd = sys::fd::FileDesc::new(fd);
|
|
|
|
let io = sys::process::Stdio::Fd(fd);
|
|
|
|
process::Stdio::from_inner(io)
|
2015-05-12 18:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 23:41:14 +00:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-05-12 18:03:49 +00:00
|
|
|
impl AsRawFd for process::ChildStdin {
|
|
|
|
fn as_raw_fd(&self) -> RawFd {
|
|
|
|
self.as_inner().fd().raw()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 23:41:14 +00:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-05-12 18:03:49 +00:00
|
|
|
impl AsRawFd for process::ChildStdout {
|
|
|
|
fn as_raw_fd(&self) -> RawFd {
|
|
|
|
self.as_inner().fd().raw()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 23:41:14 +00:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-05-12 18:03:49 +00:00
|
|
|
impl AsRawFd for process::ChildStderr {
|
|
|
|
fn as_raw_fd(&self) -> RawFd {
|
|
|
|
self.as_inner().fd().raw()
|
|
|
|
}
|
|
|
|
}
|
2015-07-16 06:31:24 +00:00
|
|
|
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-07-16 06:31:24 +00:00
|
|
|
impl IntoRawFd for process::ChildStdin {
|
|
|
|
fn into_raw_fd(self) -> RawFd {
|
|
|
|
self.into_inner().into_fd().into_raw()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-07-16 06:31:24 +00:00
|
|
|
impl IntoRawFd for process::ChildStdout {
|
|
|
|
fn into_raw_fd(self) -> RawFd {
|
|
|
|
self.into_inner().into_fd().into_raw()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 16:54:28 +00:00
|
|
|
#[stable(feature = "process_extensions", since = "1.2.0")]
|
2015-07-16 06:31:24 +00:00
|
|
|
impl IntoRawFd for process::ChildStderr {
|
|
|
|
fn into_raw_fd(self) -> RawFd {
|
|
|
|
self.into_inner().into_fd().into_raw()
|
|
|
|
}
|
|
|
|
}
|