Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 14 pull requests #77437

Closed
wants to merge 74 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
84ef603
Fix 'FIXME' about using NonZeroU32 instead of u32.
m-ou-se Sep 17, 2020
323bcd3
unix: Extend UnixStream and UnixDatagram to send and receive file des…
LinkTed Aug 21, 2020
ff87ba1
Split net.rs into multiple files
LinkTed Aug 22, 2020
e7b8925
Add AncillaryError
LinkTed Aug 22, 2020
656d7b9
Add UCred struct
LinkTed Aug 23, 2020
baa7c21
Move `add_to_ancillary_data` and `AncillaryDataIter` to ancillary.rs
LinkTed Aug 23, 2020
b4bc663
Using `read_unaligned` instead of `memcpy`.
LinkTed Aug 25, 2020
383aaac
Replace `TryFrom` of `AncillaryData` with a private method.
LinkTed Aug 25, 2020
83cb075
Add integer overflow check
LinkTed Aug 25, 2020
24938ee
Remove `Clone` trait bound in `add_to_ancillary_data`
LinkTed Aug 25, 2020
acd7dbe
Remove lifetime annotation in `messages` function
LinkTed Aug 25, 2020
5bf5db9
Remove inner function in `bind`, `connect` and `send_to`
LinkTed Aug 25, 2020
7106d76
Use `fill` instead of `memset`
LinkTed Aug 27, 2020
0968853
Remove unnecessary path
LinkTed Aug 27, 2020
1f3f10a
Move conditional compilation to the upper module and sort the target …
LinkTed Aug 28, 2020
748d310
Reduce impl trait by using macro in `raw_fd.rs`
LinkTed Aug 28, 2020
f947d2f
Add doc(cfg(...))
LinkTed Aug 29, 2020
e66b921
Add doc comments
LinkTed Aug 29, 2020
ab469ba
Rename `test.rs` to `tests.rs`
LinkTed Sep 1, 2020
dce9b21
Add `set_passcred` and `passcred` methods to `UnixStream` and `UnixDa…
LinkTed Sep 7, 2020
031521a
Change API to unsafe and add doc comments
LinkTed Sep 12, 2020
e78467b
Change name of struct to SocketCred
LinkTed Sep 16, 2020
263f0b2
Change standard types to libc types
LinkTed Sep 16, 2020
e74dbac
Remove unsupported target_os for SocketCred
LinkTed Sep 17, 2020
e9ff53c
Cast boolean into int directly in function set_passcred
LinkTed Sep 17, 2020
a86761e
Replace `assert` with `unreachable`
LinkTed Sep 18, 2020
05765ac
Add the code of the tracking issue
LinkTed Sep 19, 2020
112b7dc
Remove `target_os`, which does not have `MSG_CMSG_CLOEXEC` constant i…
LinkTed Sep 20, 2020
3806579
Remove `target_os`, which does not have `cmsghdr` struct in `libc`
LinkTed Sep 20, 2020
d5f070b
Remove `target_os`, which does not have `SO_PASSCRED` constant in `libc`
LinkTed Sep 20, 2020
6626e5b
Fix cfg condition for test
LinkTed Sep 20, 2020
b50153d
Add conditional compilation for import
LinkTed Sep 20, 2020
4ee7a85
Fix `MSG_CMSG_CLOEXEC` for macos
LinkTed Sep 22, 2020
d839df3
Fix `SO_PASSCRED` for macos
LinkTed Sep 22, 2020
168d063
Fix unused import for `IoSliceMut` for macos
LinkTed Sep 22, 2020
4e9714b
Remove `SocketCred` for `emscripten`
LinkTed Sep 22, 2020
f289468
Stabilize slice_ptr_range.
m-ou-se Sep 23, 2020
d77477e
Fix type mismatching for different OSes.
LinkTed Sep 25, 2020
3efcf72
Remove unnecessary trailing semicolon
LinkTed Sep 26, 2020
20c88dd
Remove `passcred` for `emscripten`
LinkTed Sep 26, 2020
c297e20
Add accessors to Command.
ehuss Sep 21, 2020
6f6336b
Split sys_common::Mutex in StaticMutex and MovableMutex.
m-ou-se Sep 24, 2020
825dda8
Fix ui test.
m-ou-se Sep 24, 2020
7eea071
Change imports for `cfg(doc)`
LinkTed Sep 27, 2020
6533c29
Remove --cfg dox from rustdoc.rs
jyn514 Sep 29, 2020
351f850
Remove unused --cfg stageN
jyn514 Sep 29, 2020
384eb26
rustc_metadata: Do not forget to encode inherent impls for foreign types
petrochenkov Sep 30, 2020
20202da
Improve the example for ptr::copy
scottmcm Oct 1, 2020
8164218
Fix some clippy issues
jyn514 Oct 1, 2020
e58f3d3
Things are only moved if non-copy
scottmcm Oct 1, 2020
4243475
BTreeMap: use Unique::from to avoid a cast where type information exists
ssomers Sep 26, 2020
8b2bdfd
Improve std::sys::windows::compat.
m-ou-se Sep 20, 2020
93310ef
Use AcquireSRWLockExclusive::is_available() instead of an extra lookup.
m-ou-se Sep 20, 2020
09cbaf4
Formatting.
m-ou-se Sep 20, 2020
63b6007
Work around potential merging/duplication issues in sys/windows/compat.
m-ou-se Oct 1, 2020
2140d80
Add note about possible future improvement
m-ou-se Oct 1, 2020
ca98778
Update stdarch submodule
jyn514 Oct 1, 2020
cd159fd
Uplift drop-bounds lint from clippy
notriddle Aug 19, 2020
4bf5c45
Remove outdated line from `publish_toolstate` hook
LeSeulArtichaut Sep 28, 2020
1c2c336
Link `new` method in `DefautHasher`s doc
WaffleLapkin Oct 1, 2020
a7db0bf
Rollup merge of #69864 - LinkTed:master, r=Amanieu
Dylan-DPC Oct 1, 2020
edf43ea
Rollup merge of #75699 - notriddle:drop-bounds-lint, r=petrochenkov
Dylan-DPC Oct 1, 2020
3f868d2
Rollup merge of #76851 - fusion-engineering-forks:fixme-nonzero, r=pe…
Dylan-DPC Oct 1, 2020
4ded681
Rollup merge of #76979 - fusion-engineering-forks:windows-fallback-ch…
Dylan-DPC Oct 1, 2020
d2e06b7
Rollup merge of #77029 - ehuss:command-access, r=dtolnay
Dylan-DPC Oct 1, 2020
bf59451
Rollup merge of #77111 - fusion-engineering-forks:stabilize-slice-ptr…
Dylan-DPC Oct 1, 2020
5f080bb
Rollup merge of #77147 - fusion-engineering-forks:static-mutex, r=dto…
Dylan-DPC Oct 1, 2020
01ff733
Rollup merge of #77312 - LeSeulArtichaut:toolstate-msg, r=Mark-Simula…
Dylan-DPC Oct 1, 2020
260256b
Rollup merge of #77347 - jyn514:dox, r=Amanieu
Dylan-DPC Oct 1, 2020
9b26c35
Rollup merge of #77375 - petrochenkov:inherext, r=oli-obk
Dylan-DPC Oct 1, 2020
55409cc
Rollup merge of #77385 - scottmcm:fix-77220, r=jyn514
Dylan-DPC Oct 1, 2020
ecfea2f
Rollup merge of #77389 - jyn514:THE-PAPERCLIP-COMETH, r=Mark-Simulacrum
Dylan-DPC Oct 1, 2020
c8440bf
Rollup merge of #77399 - ssomers:btree_cleanup_5, r=Mark-Simulacrum
Dylan-DPC Oct 1, 2020
86e6afa
Rollup merge of #77429 - WaffleLapkin:doc_link_default_hasher_new, r=…
Dylan-DPC Oct 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
@@ -110,6 +110,8 @@ use crate::path::Path;
use crate::str;
use crate::sys::pipe::{read2, AnonPipe};
use crate::sys::process as imp;
#[unstable(feature = "command_access", issue = "44434")]
pub use crate::sys_common::process::CommandEnvs;
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};

/// Representation of a running or exited child process.
@@ -894,6 +896,98 @@ impl Command {
.map(Child::from_inner)
.and_then(|mut p| p.wait())
}

/// Returns the path to the program that was given to [`Command::new`].
///
/// # Examples
///
/// ```
/// # #![feature(command_access)]
/// use std::process::Command;
///
/// let cmd = Command::new("echo");
/// assert_eq!(cmd.get_program(), "echo");
/// ```
#[unstable(feature = "command_access", issue = "44434")]
pub fn get_program(&self) -> &OsStr {
self.inner.get_program()
}

/// Returns an iterator of the arguments that will be passed to the program.
///
/// This does not include the path to the program as the first argument;
/// it only includes the arguments specified with [`Command::arg`] and
/// [`Command::args`].
///
/// # Examples
///
/// ```
/// # #![feature(command_access)]
/// use std::ffi::OsStr;
/// use std::process::Command;
///
/// let mut cmd = Command::new("echo");
/// cmd.arg("first").arg("second");
/// let args: Vec<&OsStr> = cmd.get_args().collect();
/// assert_eq!(args, &["first", "second"]);
/// ```
#[unstable(feature = "command_access", issue = "44434")]
pub fn get_args(&self) -> CommandArgs<'_> {
CommandArgs { inner: self.inner.get_args() }
}

/// Returns an iterator of the environment variables that will be set when
/// the process is spawned.
///
/// Each element is a tuple `(&OsStr, Option<&OsStr>)`, where the first
/// value is the key, and the second is the value, which is [`None`] if
/// the environment variable is to be explicitly removed.
///
/// This only includes environment variables explicitly set with
/// [`Command::env`], [`Command::envs`], and [`Command::env_remove`]. It
/// does not include environment variables that will be inherited by the
/// child process.
///
/// # Examples
///
/// ```
/// # #![feature(command_access)]
/// use std::ffi::OsStr;
/// use std::process::Command;
///
/// let mut cmd = Command::new("ls");
/// cmd.env("TERM", "dumb").env_remove("TZ");
/// let envs: Vec<(&OsStr, Option<&OsStr>)> = cmd.get_envs().collect();
/// assert_eq!(envs, &[
/// (OsStr::new("TERM"), Some(OsStr::new("dumb"))),
/// (OsStr::new("TZ"), None)
/// ]);
/// ```
#[unstable(feature = "command_access", issue = "44434")]
pub fn get_envs(&self) -> CommandEnvs<'_> {
self.inner.get_envs()
}

/// Returns the working directory for the child process.
///
/// This returns [`None`] if the working directory will not be changed.
///
/// # Examples
///
/// ```
/// # #![feature(command_access)]
/// use std::path::Path;
/// use std::process::Command;
///
/// let mut cmd = Command::new("ls");
/// assert_eq!(cmd.get_current_dir(), None);
/// cmd.current_dir("/bin");
/// assert_eq!(cmd.get_current_dir(), Some(Path::new("/bin")));
/// ```
#[unstable(feature = "command_access", issue = "44434")]
pub fn get_current_dir(&self) -> Option<&Path> {
self.inner.get_current_dir()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
@@ -918,6 +1012,37 @@ impl AsInnerMut<imp::Command> for Command {
}
}

/// An iterator over the command arguments.
///
/// This struct is created by [`Command::get_args`]. See its documentation for
/// more.
#[unstable(feature = "command_access", issue = "44434")]
#[derive(Debug)]
pub struct CommandArgs<'a> {
inner: imp::CommandArgs<'a>,
}

#[unstable(feature = "command_access", issue = "44434")]
impl<'a> Iterator for CommandArgs<'a> {
type Item = &'a OsStr;
fn next(&mut self) -> Option<&'a OsStr> {
self.inner.next()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}
}

#[unstable(feature = "command_access", issue = "44434")]
impl<'a> ExactSizeIterator for CommandArgs<'a> {
fn len(&self) -> usize {
self.inner.len()
}
fn is_empty(&self) -> bool {
self.inner.is_empty()
}
}

/// The output of a finished process.
///
/// This is returned in a Result by either the [`output`] method of a
3 changes: 2 additions & 1 deletion library/std/src/sys/unix/process/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub use self::process_common::{Command, ExitCode, Stdio, StdioPipes};
pub use self::process_common::{Command, CommandArgs, ExitCode, Stdio, StdioPipes};
pub use self::process_inner::{ExitStatus, Process};
pub use crate::ffi::OsString as EnvKey;
pub use crate::sys_common::process::CommandEnvs;

mod process_common;
#[cfg(not(target_os = "fuchsia"))]
53 changes: 51 additions & 2 deletions library/std/src/sys/unix/process/process_common.rs
Original file line number Diff line number Diff line change
@@ -7,11 +7,12 @@ use crate::collections::BTreeMap;
use crate::ffi::{CStr, CString, OsStr, OsString};
use crate::fmt;
use crate::io;
use crate::path::Path;
use crate::ptr;
use crate::sys::fd::FileDesc;
use crate::sys::fs::File;
use crate::sys::pipe::{self, AnonPipe};
use crate::sys_common::process::CommandEnv;
use crate::sys_common::process::{CommandEnv, CommandEnvs};

#[cfg(not(target_os = "fuchsia"))]
use crate::sys::fs::OpenOptions;
@@ -184,11 +185,30 @@ impl Command {
pub fn saw_nul(&self) -> bool {
self.saw_nul
}

pub fn get_program(&self) -> &OsStr {
OsStr::from_bytes(self.program.as_bytes())
}

pub fn get_args(&self) -> CommandArgs<'_> {
let mut iter = self.args.iter();
iter.next();
CommandArgs { iter }
}

pub fn get_envs(&self) -> CommandEnvs<'_> {
self.env.iter()
}

pub fn get_current_dir(&self) -> Option<&Path> {
self.cwd.as_ref().map(|cs| Path::new(OsStr::from_bytes(cs.as_bytes())))
}

pub fn get_argv(&self) -> &Vec<*const c_char> {
&self.argv.0
}

pub fn get_program(&self) -> &CStr {
pub fn get_program_cstr(&self) -> &CStr {
&*self.program
}

@@ -402,3 +422,32 @@ impl ExitCode {
self.0 as i32
}
}

pub struct CommandArgs<'a> {
iter: crate::slice::Iter<'a, CString>,
}

impl<'a> Iterator for CommandArgs<'a> {
type Item = &'a OsStr;
fn next(&mut self) -> Option<&'a OsStr> {
self.iter.next().map(|cs| OsStr::from_bytes(cs.as_bytes()))
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

impl<'a> ExactSizeIterator for CommandArgs<'a> {
fn len(&self) -> usize {
self.iter.len()
}
fn is_empty(&self) -> bool {
self.iter.is_empty()
}
}

impl<'a> fmt::Debug for CommandArgs<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.iter.clone()).finish()
}
}
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/process/process_fuchsia.rs
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ impl Command {
| FDIO_SPAWN_CLONE_NAMESPACE
| FDIO_SPAWN_CLONE_ENVIRON // this is ignored when envp is non-null
| FDIO_SPAWN_CLONE_UTC_CLOCK,
self.get_program().as_ptr(),
self.get_program_cstr().as_ptr(),
self.get_argv().as_ptr(),
envp,
actions.len() as size_t,
4 changes: 2 additions & 2 deletions library/std/src/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
@@ -245,7 +245,7 @@ impl Command {
*sys::os::environ() = envp.as_ptr();
}

libc::execvp(self.get_program().as_ptr(), self.get_argv().as_ptr());
libc::execvp(self.get_program_cstr().as_ptr(), self.get_argv().as_ptr());
Err(io::Error::last_os_error())
}

@@ -383,7 +383,7 @@ impl Command {
let envp = envp.map(|c| c.as_ptr()).unwrap_or_else(|| *sys::os::environ() as *const _);
let ret = libc::posix_spawnp(
&mut p.pid,
self.get_program().as_ptr(),
self.get_program_cstr().as_ptr(),
file_actions.0.as_ptr(),
attrs.0.as_ptr(),
self.get_argv().as_ptr() as *const _,
39 changes: 38 additions & 1 deletion library/std/src/sys/unsupported/process.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::ffi::OsStr;
use crate::fmt;
use crate::io;
use crate::marker::PhantomData;
use crate::path::Path;
use crate::sys::fs::File;
use crate::sys::pipe::AnonPipe;
use crate::sys::{unsupported, Void};
use crate::sys_common::process::CommandEnv;
use crate::sys_common::process::{CommandEnv, CommandEnvs};

pub use crate::ffi::OsString as EnvKey;

@@ -49,6 +51,22 @@ impl Command {

pub fn stderr(&mut self, _stderr: Stdio) {}

pub fn get_program(&self) -> &OsStr {
panic!("unsupported")
}

pub fn get_args(&self) -> CommandArgs<'_> {
CommandArgs { _p: PhantomData }
}

pub fn get_envs(&self) -> CommandEnvs<'_> {
self.env.iter()
}

pub fn get_current_dir(&self) -> Option<&Path> {
None
}

pub fn spawn(
&mut self,
_default: Stdio,
@@ -147,3 +165,22 @@ impl Process {
match self.0 {}
}
}

pub struct CommandArgs<'a> {
_p: PhantomData<&'a ()>,
}

impl<'a> Iterator for CommandArgs<'a> {
type Item = &'a OsStr;
fn next(&mut self) -> Option<&'a OsStr> {
None
}
}

impl<'a> ExactSizeIterator for CommandArgs<'a> {}

impl<'a> fmt::Debug for CommandArgs<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().finish()
}
}
48 changes: 47 additions & 1 deletion library/std/src/sys/windows/process.rs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ use crate::sys::handle::Handle;
use crate::sys::mutex::Mutex;
use crate::sys::pipe::{self, AnonPipe};
use crate::sys::stdio;
use crate::sys_common::process::CommandEnv;
use crate::sys_common::process::{CommandEnv, CommandEnvs};
use crate::sys_common::AsInner;

use libc::{c_void, EXIT_FAILURE, EXIT_SUCCESS};
@@ -134,6 +134,23 @@ impl Command {
self.flags = flags;
}

pub fn get_program(&self) -> &OsStr {
&self.program
}

pub fn get_args(&self) -> CommandArgs<'_> {
let iter = self.args.iter();
CommandArgs { iter }
}

pub fn get_envs(&self) -> CommandEnvs<'_> {
self.env.iter()
}

pub fn get_current_dir(&self) -> Option<&Path> {
self.cwd.as_ref().map(|cwd| Path::new(cwd))
}

pub fn spawn(
&mut self,
default: Stdio,
@@ -529,3 +546,32 @@ fn make_dirp(d: Option<&OsString>) -> io::Result<(*const u16, Vec<u16>)> {
None => Ok((ptr::null(), Vec::new())),
}
}

pub struct CommandArgs<'a> {
iter: crate::slice::Iter<'a, OsString>,
}

impl<'a> Iterator for CommandArgs<'a> {
type Item = &'a OsStr;
fn next(&mut self) -> Option<&'a OsStr> {
self.iter.next().map(|s| s.as_ref())
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

impl<'a> ExactSizeIterator for CommandArgs<'a> {
fn len(&self) -> usize {
self.iter.len()
}
fn is_empty(&self) -> bool {
self.iter.is_empty()
}
}

impl<'a> fmt::Debug for CommandArgs<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.iter.clone()).finish()
}
}
Loading