From 05c6fef21431b3c480acabfdde9e1048daeb5de3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 11 Nov 2021 21:03:47 +0000 Subject: [PATCH 01/15] std::process (unix): Implement From etc. for imp::Stdio This involves adding a new variant `imp::Stdio::StaticFd`. Signed-off-by: Ian Jackson --- .../src/sys/unix/process/process_common.rs | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 640648e870748..5c3b486fc031e 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -7,13 +7,14 @@ use crate::collections::BTreeMap; use crate::ffi::{CStr, CString, OsStr, OsString}; use crate::fmt; use crate::io; +use crate::mem::ManuallyDrop; 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, CommandEnvs}; -use crate::sys_common::IntoInner; +use crate::sys_common::{FromInner, IntoInner}; #[cfg(not(target_os = "fuchsia"))] use crate::sys::fs::OpenOptions; @@ -150,6 +151,7 @@ pub enum Stdio { Null, MakePipe, Fd(FileDesc), + StaticFd(BorrowedFd<'static>), } #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -463,6 +465,17 @@ impl Stdio { } } + Stdio::StaticFd(fd) => { + let fd = unsafe { + // Unfortunately there is no public method to dup BorrwedFd into an OwnedFd ! + // https://github.com/rust-lang/rust/issues/88564#issuecomment-916460459 + let fd = fd.as_raw_fd(); + let fd = ManuallyDrop::new(FileDesc::from_inner(OwnedFd::from_raw_fd(fd))); + fd.duplicate()? + }; + Ok((ChildStdio::Owned(fd), None)) + } + Stdio::MakePipe => { let (reader, writer) = pipe::anon_pipe()?; let (ours, theirs) = if readable { (writer, reader) } else { (reader, writer) }; @@ -497,6 +510,27 @@ impl From for Stdio { } } +impl From for Stdio { + fn from(_: io::Stdin) -> Stdio { + // What this ought to be is Stdio::StaticFd(input_argument.as_fd()). + // But there is no AsStaticFd trait or anything. + // https://github.com/rust-lang/rust/issues/90809 + Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw_fd(libc::STDIN_FILENO) }) + } +} + +impl From for Stdio { + fn from(_: io::Stdout) -> Stdio { + Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw_fd(libc::STDOUT_FILENO) }) + } +} + +impl From for Stdio { + fn from(_: io::Stderr) -> Stdio { + Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw_fd(libc::STDERR_FILENO) }) + } +} + impl ChildStdio { pub fn fd(&self) -> Option { match *self { From b921c79d11a7e74c4ed5c1116d0760e773cd29ca Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 3 Jan 2023 15:01:19 +0000 Subject: [PATCH 02/15] std::process (windows): refactor Stdio::to_handle slightly We're going to want to reuse this bit of code. --- library/std/src/sys/windows/process.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index e3493cbb85094..4d92caee8520b 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -521,17 +521,18 @@ fn program_exists(path: &Path) -> Option> { impl Stdio { fn to_handle(&self, stdio_id: c::DWORD, pipe: &mut Option) -> io::Result { - match *self { - Stdio::Inherit => match stdio::get_handle(stdio_id) { - Ok(io) => unsafe { - let io = Handle::from_raw_handle(io); - let ret = io.duplicate(0, true, c::DUPLICATE_SAME_ACCESS); - io.into_raw_handle(); - ret - }, - // If no stdio handle is available, then propagate the null value. - Err(..) => unsafe { Ok(Handle::from_raw_handle(ptr::null_mut())) }, + let use_stdio_id = |stdio_id| match stdio::get_handle(stdio_id) { + Ok(io) => unsafe { + let io = Handle::from_raw_handle(io); + let ret = io.duplicate(0, true, c::DUPLICATE_SAME_ACCESS); + io.into_raw_handle(); + ret }, + // If no stdio handle is available, then propagate the null value. + Err(..) => unsafe { Ok(Handle::from_raw_handle(ptr::null_mut())) }, + }; + match *self { + Stdio::Inherit => use_stdio_id(stdio_id), Stdio::MakePipe => { let ours_readable = stdio_id != c::STD_INPUT_HANDLE; From 4722fcda7bcf52e89677030ee425fe4194a102ec Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 8 Nov 2021 18:38:04 +0000 Subject: [PATCH 03/15] std::process (windows): Implement From etc. for imp::Stdio This involves a new variant `imp;::Stdio::InheritSpecific`. Signed-off-by: Ian Jackson --- library/std/src/sys/windows/process.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index 4d92caee8520b..22a5721716c65 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -170,6 +170,7 @@ pub struct Command { pub enum Stdio { Inherit, + InheritSpecific { from_stdio_id: c::DWORD }, Null, MakePipe, Pipe(AnonPipe), @@ -533,6 +534,7 @@ impl Stdio { }; match *self { Stdio::Inherit => use_stdio_id(stdio_id), + Stdio::InheritSpecific { from_stdio_id } => use_stdio_id(from_stdio_id), Stdio::MakePipe => { let ours_readable = stdio_id != c::STD_INPUT_HANDLE; @@ -580,6 +582,24 @@ impl From for Stdio { } } +impl From for Stdio { + fn from(_: io::Stdin) -> Stdio { + Stdio::InheritSpecific { from_stdio_id: c::STD_INPUT_HANDLE } + } +} + +impl From for Stdio { + fn from(_: io::Stdout) -> Stdio { + Stdio::InheritSpecific { from_stdio_id: c::STD_OUTPUT_HANDLE } + } +} + +impl From for Stdio { + fn from(_: io::Stderr) -> Stdio { + Stdio::InheritSpecific { from_stdio_id: c::STD_ERROR_HANDLE } + } +} + //////////////////////////////////////////////////////////////////////////////// // Processes //////////////////////////////////////////////////////////////////////////////// From ccf56e22867cc042394de1e055c418041ca0e795 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 1 Sep 2021 16:39:02 +0100 Subject: [PATCH 04/15] std::process: impl From (etc.) for Stdio Signed-off-by: Ian Jackson --- library/std/src/process.rs | 86 +++++++++++++++++++ .../src/sys/unix/process/process_common.rs | 6 +- 2 files changed, 89 insertions(+), 3 deletions(-) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 8f3201b0091d3..c83c6d236ff46 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1491,6 +1491,92 @@ impl From for Stdio { } } +#[stable(feature = "stdio_from_stdio", since = "1.58.0")] +impl From for Stdio { + /// Specify to inherit our stdin. + /// + /// # Examples + /// + /// ```rust,no_run + /// #![feature(exit_status_error)] + /// use std::io; + /// use std::process::Command; + /// + /// # fn test() -> Result<(), Box> { + /// let output = Command::new("wc").arg("-l") + /// .stdin(io::stdin()) + /// .output()?; + /// output.status.exit_ok()?; + /// let input_lines: u64 = std::str::from_utf8(&output.stdout)?.trim().parse()?; + /// eprintln!("our standard input had {} lines", input_lines); + /// # Ok(()) + /// # } + /// ``` + fn from(inherit: io::Stdin) -> Stdio { + Stdio::from_inner(inherit.into()) + } +} + +#[stable(feature = "stdio_from_stdio", since = "1.58.0")] +impl From for Stdio { + /// Redirect command stdout/stderr to our stdout + /// + /// # Examples + /// + /// ```rust + /// #![feature(exit_status_error)] + /// use std::io; + /// use std::process::Command; + /// + /// # fn test() -> Result<(), Box> { + /// let output = Command::new("whoami") + // "whoami" is a command which exists on both Unix and Winodows, + // and which succeeds, producing some stdout output but no stderr. + /// .stdout(io::stdout()) + /// .output()?; + /// output.status.exit_ok()?; + /// assert!(output.stdout.is_empty()); + /// # Ok(()) + /// # } + /// # + /// # if cfg!(unix) { + /// # test().unwrap(); + /// # } + /// ``` + fn from(inherit: io::Stdout) -> Stdio { + Stdio::from_inner(inherit.into()) + } +} + +#[stable(feature = "stdio_from_stdio", since = "1.58.0")] +impl From for Stdio { + /// Redirect command stdout/stderr to our stderr + /// + /// # Examples + /// + /// ```rust + /// #![feature(exit_status_error)] + /// use std::io; + /// use std::process::Command; + /// + /// # fn test() -> Result<(), Box> { + /// let output = Command::new("whoami") + /// .stdout(io::stderr()) + /// .output()?; + /// output.status.exit_ok()?; + /// assert!(output.stdout.is_empty()); + /// # Ok(()) + /// # } + /// # + /// # if cfg!(unix) { + /// # test().unwrap(); + /// # } + /// ``` + fn from(inherit: io::Stderr) -> Stdio { + Stdio::from_inner(inherit.into()) + } +} + /// Describes the result of a process after it has terminated. /// /// This `struct` is used to represent the exit status or other termination of a child process. diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 5c3b486fc031e..6bc7dd5d787fb 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -515,19 +515,19 @@ impl From for Stdio { // What this ought to be is Stdio::StaticFd(input_argument.as_fd()). // But there is no AsStaticFd trait or anything. // https://github.com/rust-lang/rust/issues/90809 - Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw_fd(libc::STDIN_FILENO) }) + Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDIN_FILENO) }) } } impl From for Stdio { fn from(_: io::Stdout) -> Stdio { - Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw_fd(libc::STDOUT_FILENO) }) + Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDOUT_FILENO) }) } } impl From for Stdio { fn from(_: io::Stderr) -> Stdio { - Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw_fd(libc::STDERR_FILENO) }) + Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDERR_FILENO) }) } } From 8e12985641464f6fcf919736c89e8a7605f00d02 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 3 Jan 2023 15:21:43 +0000 Subject: [PATCH 05/15] DO NOT MERGE - RUN WINDOWS CI My attempt at following the instructions in https://github.com/rust-lang/rust/pull/88561#issuecomment-1193392005 --- .github/workflows/ci.yml | 6 ++++++ src/ci/github-actions/ci.yml | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0842b69c219c8..3bfe4a37137a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,6 +61,12 @@ jobs: - name: x86_64-gnu-tools os: ubuntu-20.04-16core-64gb env: {} + - name: x86_64-msvc-1 + env: + RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --enable-profiler" + SCRIPT: make ci-msvc + tidy: false + os: windows-2019-8core-32gb timeout-minutes: 600 runs-on: "${{ matrix.os }}" steps: diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 55fd6cca85a5d..8fb0908f388e0 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -326,6 +326,13 @@ jobs: - name: x86_64-gnu-llvm-14 <<: *job-linux-16c + - name: x86_64-msvc-1 + env: + RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-profiler + SCRIPT: make ci-msvc + <<: *job-windows-xl + tidy: false + - name: x86_64-gnu-tools <<: *job-linux-16c From 65a474a1caf02464f7615a61a9a120d84af5be31 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 18 Jul 2023 15:43:58 +0100 Subject: [PATCH 06/15] squash! std::process (unix): Implement From etc. for imp::Stdio Exclude stdin. --- library/std/src/sys/unix/process/process_common.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 6bc7dd5d787fb..12fa1b83c4333 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -510,15 +510,6 @@ impl From for Stdio { } } -impl From for Stdio { - fn from(_: io::Stdin) -> Stdio { - // What this ought to be is Stdio::StaticFd(input_argument.as_fd()). - // But there is no AsStaticFd trait or anything. - // https://github.com/rust-lang/rust/issues/90809 - Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDIN_FILENO) }) - } -} - impl From for Stdio { fn from(_: io::Stdout) -> Stdio { Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDOUT_FILENO) }) From ab33b8670909fac7ce99a12f5c175ed6ce59f3dd Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 18 Jul 2023 15:45:16 +0100 Subject: [PATCH 07/15] squash! std::process (windows): Implement From etc. for imp::Stdio Exclude Stdin --- library/std/src/sys/windows/process.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index 22a5721716c65..02ca4fc615a00 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -582,12 +582,6 @@ impl From for Stdio { } } -impl From for Stdio { - fn from(_: io::Stdin) -> Stdio { - Stdio::InheritSpecific { from_stdio_id: c::STD_INPUT_HANDLE } - } -} - impl From for Stdio { fn from(_: io::Stdout) -> Stdio { Stdio::InheritSpecific { from_stdio_id: c::STD_OUTPUT_HANDLE } From 348293b27917b6e8f40092c420edc9ecd4877cb0 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 18 Jul 2023 15:49:42 +0100 Subject: [PATCH 08/15] fixup! std::process: impl From (etc.) for Stdio --- library/std/src/process.rs | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index c83c6d236ff46..3acadf26b0e2d 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1491,32 +1491,6 @@ impl From for Stdio { } } -#[stable(feature = "stdio_from_stdio", since = "1.58.0")] -impl From for Stdio { - /// Specify to inherit our stdin. - /// - /// # Examples - /// - /// ```rust,no_run - /// #![feature(exit_status_error)] - /// use std::io; - /// use std::process::Command; - /// - /// # fn test() -> Result<(), Box> { - /// let output = Command::new("wc").arg("-l") - /// .stdin(io::stdin()) - /// .output()?; - /// output.status.exit_ok()?; - /// let input_lines: u64 = std::str::from_utf8(&output.stdout)?.trim().parse()?; - /// eprintln!("our standard input had {} lines", input_lines); - /// # Ok(()) - /// # } - /// ``` - fn from(inherit: io::Stdin) -> Stdio { - Stdio::from_inner(inherit.into()) - } -} - #[stable(feature = "stdio_from_stdio", since = "1.58.0")] impl From for Stdio { /// Redirect command stdout/stderr to our stdout From 22454e6a5442bb390799c00a44272283015a0994 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 18 Jul 2023 15:53:46 +0100 Subject: [PATCH 09/15] fixup! squash! std::process (unix): Implement From etc. for imp::Stdio --- library/std/src/sys/unix/process/process_common.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 12fa1b83c4333..c20a4f4c39c16 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -512,6 +512,9 @@ impl From for Stdio { impl From for Stdio { fn from(_: io::Stdout) -> Stdio { + // What this ought to be is Stdio::StaticFd(input_argument.as_fd()). + // But there is no AsStaticFd trait or anything. + // https://github.com/rust-lang/rust/issues/90809 Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDOUT_FILENO) }) } } From d202637aede3b35e570fc751e307d2ab68c7dbdc Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 18 Jul 2023 16:05:31 +0100 Subject: [PATCH 10/15] std::process (unix): Update discussion of fd borrowing --- library/std/src/sys/unix/process/process_common.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index c20a4f4c39c16..0b4f66bb52ff8 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -512,9 +512,16 @@ impl From for Stdio { impl From for Stdio { fn from(_: io::Stdout) -> Stdio { - // What this ought to be is Stdio::StaticFd(input_argument.as_fd()). - // But there is no AsStaticFd trait or anything. - // https://github.com/rust-lang/rust/issues/90809 + // This ought really to be is Stdio::StaticFd(input_argument.as_fd()). + // But AsFd::as_fd takes its argument by reference, and yields + // a bounded lifetime, so it's no use here. There is no AsStaticFd. + // + // Additionally AsFd is only implemented for the *locked* versions. + // We don't want to lock them here. (The implications of not locking + // are the same as those for process::Stdio::inherit().) + // + // Arguably the hypothetical AsStaticFd and AsFd<'static> + // should be implemented for io::Stdout, not just for StdoutLocked. Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDOUT_FILENO) }) } } From b8907993c786047de96f6cf200fe95587177beda Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 18 Jul 2023 16:37:30 +0100 Subject: [PATCH 11/15] squash! DO NOT MERGE - RUN WINDOWS CI --- .github/workflows/ci.yml | 6 +++--- src/ci/github-actions/ci.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3bfe4a37137a1..176886197d650 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,15 +58,15 @@ jobs: - name: x86_64-gnu-llvm-14 os: ubuntu-20.04-16core-64gb env: {} - - name: x86_64-gnu-tools - os: ubuntu-20.04-16core-64gb - env: {} - name: x86_64-msvc-1 env: RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --enable-profiler" SCRIPT: make ci-msvc tidy: false os: windows-2019-8core-32gb + - name: x86_64-gnu-tools + os: ubuntu-20.04-16core-64gb + env: {} timeout-minutes: 600 runs-on: "${{ matrix.os }}" steps: diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 8fb0908f388e0..f2ec38c013b44 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -330,7 +330,7 @@ jobs: env: RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-profiler SCRIPT: make ci-msvc - <<: *job-windows-xl + <<: *job-windows-8c tidy: false - name: x86_64-gnu-tools From a7158fa2decb55358fff8afd8d76ba79473ad9b7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 7 Aug 2023 14:49:31 +0100 Subject: [PATCH 12/15] Fix typo Co-authored-by: Lonami --- library/std/src/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 3acadf26b0e2d..d460bf91e61ed 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1504,7 +1504,7 @@ impl From for Stdio { /// /// # fn test() -> Result<(), Box> { /// let output = Command::new("whoami") - // "whoami" is a command which exists on both Unix and Winodows, + // "whoami" is a command which exists on both Unix and Windows, // and which succeeds, producing some stdout output but no stderr. /// .stdout(io::stdout()) /// .output()?; From ff0d579fc4b99caf83755f03981d2e24a4df693d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 7 Aug 2023 14:49:57 +0100 Subject: [PATCH 13/15] Use CURRENT_RUSTC_VERSION in one stable attr Co-authored-by: teor --- library/std/src/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index d460bf91e61ed..23f824177bf28 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1491,7 +1491,7 @@ impl From for Stdio { } } -#[stable(feature = "stdio_from_stdio", since = "1.58.0")] +#[stable(feature = "stdio_from_stdio", since = "CURRENT_RUSTC_VERSION")] impl From for Stdio { /// Redirect command stdout/stderr to our stdout /// From 5a715aa5ca19bcb06e51b74c50bf077755af2fa1 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 7 Aug 2023 14:52:40 +0100 Subject: [PATCH 14/15] Use CURRENT_RUSTC_VERSION in the other attr As per https://github.com/rust-lang/rust/pull/88561#pullrequestreview-1561942767 --- library/std/src/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 23f824177bf28..c9dfd30084498 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1522,7 +1522,7 @@ impl From for Stdio { } } -#[stable(feature = "stdio_from_stdio", since = "1.58.0")] +#[stable(feature = "stdio_from_stdio", since = "CURRENT_RUSTC_VERSION")] impl From for Stdio { /// Redirect command stdout/stderr to our stderr /// From de9b744c2795c0c097718c1ad9da0dbfd13ed627 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 7 Aug 2023 15:08:57 +0100 Subject: [PATCH 15/15] unix process: Use BorrowedFd::try_clone_to_owned --- library/std/src/sys/unix/process/process_common.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 0b4f66bb52ff8..9cc13ba6f98e4 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -7,7 +7,6 @@ use crate::collections::BTreeMap; use crate::ffi::{CStr, CString, OsStr, OsString}; use crate::fmt; use crate::io; -use crate::mem::ManuallyDrop; use crate::path::Path; use crate::ptr; use crate::sys::fd::FileDesc; @@ -466,13 +465,7 @@ impl Stdio { } Stdio::StaticFd(fd) => { - let fd = unsafe { - // Unfortunately there is no public method to dup BorrwedFd into an OwnedFd ! - // https://github.com/rust-lang/rust/issues/88564#issuecomment-916460459 - let fd = fd.as_raw_fd(); - let fd = ManuallyDrop::new(FileDesc::from_inner(OwnedFd::from_raw_fd(fd))); - fd.duplicate()? - }; + let fd = FileDesc::from_inner(fd.try_clone_to_owned()?); Ok((ChildStdio::Owned(fd), None)) }