2015-04-16 06:21:13 +00:00
|
|
|
|
//! Unix-specific extensions to primitives in the `std::process` module.
|
|
|
|
|
|
|
|
|
|
#![stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
|
2019-11-18 06:56:13 +00:00
|
|
|
|
use crate::ffi::OsStr;
|
2019-02-10 19:23:21 +00:00
|
|
|
|
use crate::io;
|
2021-08-17 23:28:00 +00:00
|
|
|
|
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
|
2019-02-10 19:23:21 +00:00
|
|
|
|
use crate::process;
|
2021-02-10 21:30:30 +00:00
|
|
|
|
use crate::sealed::Sealed;
|
2019-02-10 19:23:21 +00:00
|
|
|
|
use crate::sys;
|
2019-11-27 18:28:39 +00:00
|
|
|
|
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
|
2015-04-16 06:21:13 +00:00
|
|
|
|
|
2018-04-10 00:44:28 +00:00
|
|
|
|
/// Unix-specific extensions to the [`process::Command`] builder.
|
2021-02-10 21:30:30 +00:00
|
|
|
|
///
|
|
|
|
|
/// This trait is sealed: it cannot be implemented outside the standard library.
|
|
|
|
|
/// This is so that future additional methods are not breaking changes.
|
2015-04-16 06:21:13 +00:00
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2021-02-10 21:30:30 +00:00
|
|
|
|
pub trait CommandExt: Sealed {
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Sets the child process's user ID. This translates to a
|
2015-04-16 06:21:13 +00:00
|
|
|
|
/// `setuid` call in the child process. Failure in the `setuid`
|
|
|
|
|
/// call will cause the spawn to fail.
|
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2020-10-07 18:38:25 +00:00
|
|
|
|
fn uid(
|
|
|
|
|
&mut self,
|
|
|
|
|
#[cfg(not(target_os = "vxworks"))] id: u32,
|
|
|
|
|
#[cfg(target_os = "vxworks")] id: u16,
|
|
|
|
|
) -> &mut process::Command;
|
2015-04-16 06:21:13 +00:00
|
|
|
|
|
2019-02-09 22:16:58 +00:00
|
|
|
|
/// Similar to `uid`, but sets the group ID of the child process. This has
|
2015-04-16 06:21:13 +00:00
|
|
|
|
/// the same semantics as the `uid` field.
|
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2020-10-07 18:38:25 +00:00
|
|
|
|
fn gid(
|
|
|
|
|
&mut self,
|
|
|
|
|
#[cfg(not(target_os = "vxworks"))] id: u32,
|
|
|
|
|
#[cfg(target_os = "vxworks")] id: u16,
|
|
|
|
|
) -> &mut process::Command;
|
2015-06-21 14:43:19 +00:00
|
|
|
|
|
2020-06-16 04:39:34 +00:00
|
|
|
|
/// Sets the supplementary group IDs for the calling process. Translates to
|
|
|
|
|
/// a `setgroups` call in the child process.
|
|
|
|
|
#[unstable(feature = "setgroups", issue = "38527", reason = "")]
|
|
|
|
|
fn groups(
|
|
|
|
|
&mut self,
|
|
|
|
|
#[cfg(not(target_os = "vxworks"))] groups: &[u32],
|
|
|
|
|
#[cfg(target_os = "vxworks")] groups: &[u16],
|
|
|
|
|
) -> &mut process::Command;
|
|
|
|
|
|
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.
|
|
|
|
|
///
|
2019-02-01 18:57:06 +00:00
|
|
|
|
/// # Notes and Safety
|
2016-02-04 00:55:59 +00:00
|
|
|
|
///
|
|
|
|
|
/// This closure will be run in the context of the child process after a
|
2017-08-11 18:34:14 +00:00
|
|
|
|
/// `fork`. This primarily means that any modifications made to memory on
|
2016-02-04 00:55:59 +00:00
|
|
|
|
/// behalf of this closure will **not** be visible to the parent process.
|
|
|
|
|
/// This is often a very constrained environment where normal operations
|
2021-03-09 20:42:38 +00:00
|
|
|
|
/// like `malloc`, accessing environment variables through [`std::env`]
|
|
|
|
|
/// or acquiring a mutex are not guaranteed to work (due to
|
2016-02-04 00:55:59 +00:00
|
|
|
|
/// other threads perhaps still running when the `fork` was run).
|
|
|
|
|
///
|
2021-03-09 20:42:38 +00:00
|
|
|
|
/// For further details refer to the [POSIX fork() specification]
|
|
|
|
|
/// and the equivalent documentation for any targeted
|
|
|
|
|
/// platform, especially the requirements around *async-signal-safety*.
|
|
|
|
|
///
|
2019-02-01 18:53:32 +00:00
|
|
|
|
/// This also means that all resources such as file descriptors and
|
|
|
|
|
/// memory-mapped regions got duplicated. It is your responsibility to make
|
|
|
|
|
/// sure that the closure does not violate library invariants by making
|
2019-02-03 10:17:59 +00:00
|
|
|
|
/// invalid use of these duplicates.
|
2019-02-01 18:53:32 +00:00
|
|
|
|
///
|
2021-02-07 13:41:49 +00:00
|
|
|
|
/// Panicking in the closure is safe only if all the format arguments for the
|
|
|
|
|
/// panic message can be safely formatted; this is because although
|
|
|
|
|
/// `Command` calls [`std::panic::always_abort`](crate::panic::always_abort)
|
|
|
|
|
/// before calling the pre_exec hook, panic will still try to format the
|
|
|
|
|
/// panic message.
|
|
|
|
|
///
|
2016-02-04 00:55:59 +00:00
|
|
|
|
/// When this closure is run, aspects such as the stdio file descriptors and
|
|
|
|
|
/// working directory have successfully been changed, so output to these
|
2021-07-23 23:14:28 +00:00
|
|
|
|
/// locations might not appear where intended.
|
2021-03-09 20:42:38 +00:00
|
|
|
|
///
|
|
|
|
|
/// [POSIX fork() specification]:
|
|
|
|
|
/// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html
|
|
|
|
|
/// [`std::env`]: mod@crate::env
|
2019-02-01 18:53:32 +00:00
|
|
|
|
#[stable(feature = "process_pre_exec", since = "1.34.0")]
|
|
|
|
|
unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command
|
2019-11-27 18:28:39 +00:00
|
|
|
|
where
|
|
|
|
|
F: FnMut() -> io::Result<()> + Send + Sync + 'static;
|
2019-02-01 18:53:32 +00:00
|
|
|
|
|
|
|
|
|
/// Schedules a closure to be run just before the `exec` function is
|
|
|
|
|
/// invoked.
|
|
|
|
|
///
|
2019-02-02 10:05:43 +00:00
|
|
|
|
/// This method is stable and usable, but it should be unsafe. To fix
|
|
|
|
|
/// that, it got deprecated in favor of the unsafe [`pre_exec`].
|
2019-02-01 18:53:32 +00:00
|
|
|
|
///
|
2020-08-18 16:41:20 +00:00
|
|
|
|
/// [`pre_exec`]: CommandExt::pre_exec
|
2016-12-14 20:22:15 +00:00
|
|
|
|
#[stable(feature = "process_exec", since = "1.15.0")]
|
2019-02-02 10:00:55 +00:00
|
|
|
|
#[rustc_deprecated(since = "1.37.0", reason = "should be unsafe, use `pre_exec` instead")]
|
2016-02-04 00:55:59 +00:00
|
|
|
|
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
|
2019-11-27 18:28:39 +00:00
|
|
|
|
where
|
|
|
|
|
F: FnMut() -> io::Result<()> + Send + Sync + 'static,
|
2019-02-01 18:53:32 +00:00
|
|
|
|
{
|
|
|
|
|
unsafe { self.pre_exec(f) }
|
|
|
|
|
}
|
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.
|
|
|
|
|
///
|
2016-12-21 19:42:07 +00:00
|
|
|
|
/// `exec` not returning has the same implications as calling
|
|
|
|
|
/// [`process::exit`] – no destructors on the current stack or any other
|
|
|
|
|
/// thread’s stack will be run. Therefore, it is recommended to only call
|
|
|
|
|
/// `exec` at a point where it is fine to not run any destructors. Note,
|
|
|
|
|
/// that the `execvp` syscall independently guarantees that all memory is
|
|
|
|
|
/// freed and all file descriptors with the `CLOEXEC` option (set by default
|
|
|
|
|
/// on all file descriptors opened by the standard library) are closed.
|
|
|
|
|
///
|
2016-02-04 19:16:32 +00:00
|
|
|
|
/// 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;
|
2019-11-18 06:56:13 +00:00
|
|
|
|
|
|
|
|
|
/// Set executable argument
|
|
|
|
|
///
|
|
|
|
|
/// Set the first process argument, `argv[0]`, to something other than the
|
|
|
|
|
/// default executable path.
|
2020-05-12 00:19:25 +00:00
|
|
|
|
#[stable(feature = "process_set_argv0", since = "1.45.0")]
|
2019-11-18 06:56:13 +00:00
|
|
|
|
fn arg0<S>(&mut self, arg: S) -> &mut process::Command
|
2019-11-27 18:28:39 +00:00
|
|
|
|
where
|
|
|
|
|
S: AsRef<OsStr>;
|
2015-04-16 06:21:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
impl CommandExt for process::Command {
|
2020-10-07 18:38:25 +00:00
|
|
|
|
fn uid(
|
|
|
|
|
&mut self,
|
|
|
|
|
#[cfg(not(target_os = "vxworks"))] id: u32,
|
|
|
|
|
#[cfg(target_os = "vxworks")] id: u16,
|
|
|
|
|
) -> &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
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-07 18:38:25 +00:00
|
|
|
|
fn gid(
|
|
|
|
|
&mut self,
|
|
|
|
|
#[cfg(not(target_os = "vxworks"))] id: u32,
|
|
|
|
|
#[cfg(target_os = "vxworks")] id: u16,
|
|
|
|
|
) -> &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
|
|
|
|
|
2020-06-16 04:39:34 +00:00
|
|
|
|
fn groups(
|
|
|
|
|
&mut self,
|
|
|
|
|
#[cfg(not(target_os = "vxworks"))] groups: &[u32],
|
|
|
|
|
#[cfg(target_os = "vxworks")] groups: &[u16],
|
|
|
|
|
) -> &mut process::Command {
|
|
|
|
|
self.as_inner_mut().groups(groups);
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-01 18:53:32 +00:00
|
|
|
|
unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command
|
2019-11-27 18:28:39 +00:00
|
|
|
|
where
|
|
|
|
|
F: FnMut() -> io::Result<()> + Send + Sync + 'static,
|
2016-02-04 00:55:59 +00:00
|
|
|
|
{
|
2019-02-01 18:53:32 +00:00
|
|
|
|
self.as_inner_mut().pre_exec(Box::new(f));
|
2016-02-04 00:55:59 +00:00
|
|
|
|
self
|
|
|
|
|
}
|
2016-02-04 19:16:32 +00:00
|
|
|
|
|
|
|
|
|
fn exec(&mut self) -> io::Error {
|
2021-02-24 04:19:15 +00:00
|
|
|
|
// NOTE: This may *not* be safe to call after `libc::fork`, because it
|
|
|
|
|
// may allocate. That may be worth fixing at some point in the future.
|
2016-02-04 19:16:32 +00:00
|
|
|
|
self.as_inner_mut().exec(sys::process::Stdio::Inherit)
|
|
|
|
|
}
|
2019-11-18 06:56:13 +00:00
|
|
|
|
|
|
|
|
|
fn arg0<S>(&mut self, arg: S) -> &mut process::Command
|
2019-11-27 18:28:39 +00:00
|
|
|
|
where
|
|
|
|
|
S: AsRef<OsStr>,
|
2019-11-18 06:56:13 +00:00
|
|
|
|
{
|
|
|
|
|
self.as_inner_mut().set_arg_0(arg.as_ref());
|
|
|
|
|
self
|
|
|
|
|
}
|
2015-04-16 06:21:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-24 14:52:16 +00:00
|
|
|
|
/// Unix-specific extensions to [`process::ExitStatus`] and
|
|
|
|
|
/// [`ExitStatusError`](process::ExitStatusError).
|
2021-01-04 17:11:41 +00:00
|
|
|
|
///
|
2021-05-11 17:09:03 +00:00
|
|
|
|
/// On Unix, `ExitStatus` **does not necessarily represent an exit status**, as
|
2021-02-24 14:52:16 +00:00
|
|
|
|
/// passed to the `exit` system call or returned by
|
2021-05-11 17:09:03 +00:00
|
|
|
|
/// [`ExitStatus::code()`](crate::process::ExitStatus::code). It represents **any wait status**
|
|
|
|
|
/// as returned by one of the `wait` family of system
|
2021-02-24 14:52:16 +00:00
|
|
|
|
/// calls.
|
2021-02-22 15:26:19 +00:00
|
|
|
|
///
|
2021-02-24 14:52:16 +00:00
|
|
|
|
/// A Unix wait status (a Rust `ExitStatus`) can represent a Unix exit status, but can also
|
|
|
|
|
/// represent other kinds of process event.
|
2021-02-22 15:26:19 +00:00
|
|
|
|
///
|
2021-01-11 02:11:00 +00:00
|
|
|
|
/// This trait is sealed: it cannot be implemented outside the standard library.
|
2021-01-04 17:11:41 +00:00
|
|
|
|
/// This is so that future additional methods are not breaking changes.
|
2015-04-16 06:21:13 +00:00
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2021-02-10 21:30:30 +00:00
|
|
|
|
pub trait ExitStatusExt: Sealed {
|
2021-02-24 14:52:16 +00:00
|
|
|
|
/// Creates a new `ExitStatus` or `ExitStatusError` from the raw underlying integer status
|
|
|
|
|
/// value from `wait`
|
2021-02-22 15:26:19 +00:00
|
|
|
|
///
|
|
|
|
|
/// The value should be a **wait status, not an exit status**.
|
2021-02-24 14:52:16 +00:00
|
|
|
|
///
|
|
|
|
|
/// # Panics
|
|
|
|
|
///
|
|
|
|
|
/// Panics on an attempt to make an `ExitStatusError` from a wait status of `0`.
|
|
|
|
|
///
|
2021-06-25 20:18:56 +00:00
|
|
|
|
/// Making an `ExitStatus` always succeeds and never panics.
|
2016-08-11 21:08:24 +00:00
|
|
|
|
#[stable(feature = "exit_status_from", since = "1.12.0")]
|
2016-04-26 22:23:46 +00:00
|
|
|
|
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.
|
2020-12-12 21:37:34 +00:00
|
|
|
|
///
|
2020-12-13 11:03:37 +00:00
|
|
|
|
/// In other words, if `WIFSIGNALED`, this returns `WTERMSIG`.
|
2015-04-16 06:21:13 +00:00
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
fn signal(&self) -> Option<i32>;
|
2020-12-12 21:41:55 +00:00
|
|
|
|
|
2020-12-12 21:44:13 +00:00
|
|
|
|
/// If the process was terminated by a signal, says whether it dumped core.
|
2021-01-04 17:37:34 +00:00
|
|
|
|
#[unstable(feature = "unix_process_wait_more", issue = "80695")]
|
2020-12-12 21:44:13 +00:00
|
|
|
|
fn core_dumped(&self) -> bool;
|
|
|
|
|
|
2020-12-12 21:47:47 +00:00
|
|
|
|
/// If the process was stopped by a signal, returns that signal.
|
|
|
|
|
///
|
2020-12-13 11:03:17 +00:00
|
|
|
|
/// In other words, if `WIFSTOPPED`, this returns `WSTOPSIG`. This is only possible if the status came from
|
2021-03-25 10:48:27 +00:00
|
|
|
|
/// a `wait` system call which was passed `WUNTRACED`, and was then converted into an `ExitStatus`.
|
2021-01-04 17:37:34 +00:00
|
|
|
|
#[unstable(feature = "unix_process_wait_more", issue = "80695")]
|
2020-12-12 21:47:47 +00:00
|
|
|
|
fn stopped_signal(&self) -> Option<i32>;
|
|
|
|
|
|
2020-12-12 21:52:17 +00:00
|
|
|
|
/// Whether the process was continued from a stopped status.
|
|
|
|
|
///
|
|
|
|
|
/// Ie, `WIFCONTINUED`. This is only possible if the status came from a `wait` system call
|
2021-03-25 10:48:27 +00:00
|
|
|
|
/// which was passed `WCONTINUED`, and was then converted into an `ExitStatus`.
|
2021-01-04 17:37:34 +00:00
|
|
|
|
#[unstable(feature = "unix_process_wait_more", issue = "80695")]
|
2020-12-12 21:52:17 +00:00
|
|
|
|
fn continued(&self) -> bool;
|
|
|
|
|
|
2020-12-12 21:41:55 +00:00
|
|
|
|
/// Returns the underlying raw `wait` status.
|
2021-02-22 15:26:19 +00:00
|
|
|
|
///
|
|
|
|
|
/// The returned integer is a **wait status, not an exit status**.
|
2021-01-04 17:37:34 +00:00
|
|
|
|
#[unstable(feature = "unix_process_wait_more", issue = "80695")]
|
2020-12-12 21:41:55 +00:00
|
|
|
|
fn into_raw(self) -> i32;
|
2015-04-16 06:21:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[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
|
|
|
|
}
|
2020-12-12 21:41:55 +00:00
|
|
|
|
|
2020-12-12 21:44:13 +00:00
|
|
|
|
fn core_dumped(&self) -> bool {
|
|
|
|
|
self.as_inner().core_dumped()
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:47:47 +00:00
|
|
|
|
fn stopped_signal(&self) -> Option<i32> {
|
|
|
|
|
self.as_inner().stopped_signal()
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:52:17 +00:00
|
|
|
|
fn continued(&self) -> bool {
|
|
|
|
|
self.as_inner().continued()
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:41:55 +00:00
|
|
|
|
fn into_raw(self) -> i32 {
|
|
|
|
|
self.as_inner().into_raw().into()
|
|
|
|
|
}
|
2015-04-16 06:21:13 +00:00
|
|
|
|
}
|
2015-05-12 18:03:49 +00:00
|
|
|
|
|
2021-02-24 14:52:16 +00:00
|
|
|
|
#[unstable(feature = "exit_status_error", issue = "84908")]
|
|
|
|
|
impl ExitStatusExt for process::ExitStatusError {
|
|
|
|
|
fn from_raw(raw: i32) -> Self {
|
|
|
|
|
process::ExitStatus::from_raw(raw)
|
|
|
|
|
.exit_ok()
|
|
|
|
|
.expect_err("<ExitStatusError as ExitStatusExt>::from_raw(0) but zero is not an error")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn signal(&self) -> Option<i32> {
|
|
|
|
|
self.into_status().signal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn core_dumped(&self) -> bool {
|
|
|
|
|
self.into_status().core_dumped()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn stopped_signal(&self) -> Option<i32> {
|
|
|
|
|
self.into_status().stopped_signal()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn continued(&self) -> bool {
|
|
|
|
|
self.into_status().continued()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn into_raw(self) -> i32 {
|
|
|
|
|
self.into_status().into_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 FromRawFd for process::Stdio {
|
2021-04-25 06:39:09 +00:00
|
|
|
|
#[inline]
|
2015-05-12 18:03:49 +00:00
|
|
|
|
unsafe fn from_raw_fd(fd: RawFd) -> process::Stdio {
|
2021-07-01 04:44:30 +00:00
|
|
|
|
let fd = sys::fd::FileDesc::from_raw_fd(fd);
|
2016-02-04 19:10:37 +00:00
|
|
|
|
let io = sys::process::Stdio::Fd(fd);
|
|
|
|
|
process::Stdio::from_inner(io)
|
2015-05-12 18:03:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 23:28:00 +00:00
|
|
|
|
#[unstable(feature = "io_safety", issue = "87074")]
|
|
|
|
|
impl From<OwnedFd> for process::Stdio {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(fd: OwnedFd) -> process::Stdio {
|
|
|
|
|
let fd = sys::fd::FileDesc::from_inner(fd);
|
|
|
|
|
let io = sys::process::Stdio::Fd(fd);
|
|
|
|
|
process::Stdio::from_inner(io)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
2021-04-25 06:39:09 +00:00
|
|
|
|
#[inline]
|
2015-05-12 18:03:49 +00:00
|
|
|
|
fn as_raw_fd(&self) -> RawFd {
|
2021-07-01 04:44:30 +00:00
|
|
|
|
self.as_inner().as_raw_fd()
|
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::ChildStdout {
|
2021-04-25 06:39:09 +00:00
|
|
|
|
#[inline]
|
2015-05-12 18:03:49 +00:00
|
|
|
|
fn as_raw_fd(&self) -> RawFd {
|
2021-07-01 04:44:30 +00:00
|
|
|
|
self.as_inner().as_raw_fd()
|
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::ChildStderr {
|
2021-04-25 06:39:09 +00:00
|
|
|
|
#[inline]
|
2015-05-12 18:03:49 +00:00
|
|
|
|
fn as_raw_fd(&self) -> RawFd {
|
2021-07-01 04:44:30 +00:00
|
|
|
|
self.as_inner().as_raw_fd()
|
2015-05-12 18:03:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-16 06:31:24 +00:00
|
|
|
|
|
2016-09-28 10:28:42 +00:00
|
|
|
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
2015-07-16 06:31:24 +00:00
|
|
|
|
impl IntoRawFd for process::ChildStdin {
|
2021-04-25 06:39:09 +00:00
|
|
|
|
#[inline]
|
2015-07-16 06:31:24 +00:00
|
|
|
|
fn into_raw_fd(self) -> RawFd {
|
2021-07-01 04:44:30 +00:00
|
|
|
|
self.into_inner().into_inner().into_raw_fd()
|
2015-07-16 06:31:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 10:28:42 +00:00
|
|
|
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
2015-07-16 06:31:24 +00:00
|
|
|
|
impl IntoRawFd for process::ChildStdout {
|
2021-04-25 06:39:09 +00:00
|
|
|
|
#[inline]
|
2015-07-16 06:31:24 +00:00
|
|
|
|
fn into_raw_fd(self) -> RawFd {
|
2021-07-01 04:44:30 +00:00
|
|
|
|
self.into_inner().into_inner().into_raw_fd()
|
2015-07-16 06:31:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 10:28:42 +00:00
|
|
|
|
#[stable(feature = "into_raw_os", since = "1.4.0")]
|
2015-07-16 06:31:24 +00:00
|
|
|
|
impl IntoRawFd for process::ChildStderr {
|
2021-04-25 06:39:09 +00:00
|
|
|
|
#[inline]
|
2015-07-16 06:31:24 +00:00
|
|
|
|
fn into_raw_fd(self) -> RawFd {
|
2021-07-01 04:44:30 +00:00
|
|
|
|
self.into_inner().into_inner().into_raw_fd()
|
2015-07-16 06:31:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-19 05:09:18 +00:00
|
|
|
|
|
|
|
|
|
/// Returns the OS-assigned process identifier associated with this process's parent.
|
2018-04-04 01:47:37 +00:00
|
|
|
|
#[stable(feature = "unix_ppid", since = "1.27.0")]
|
2017-11-19 05:09:18 +00:00
|
|
|
|
pub fn parent_id() -> u32 {
|
2019-02-10 19:23:21 +00:00
|
|
|
|
crate::sys::os::getppid()
|
2017-11-19 05:09:18 +00:00
|
|
|
|
}
|