2021-09-17 17:53:21 +00:00
|
|
|
|
//! Unix-specific extensions to primitives in the [`std::process`] module.
|
|
|
|
|
//!
|
|
|
|
|
//! [`std::process`]: crate::process
|
2015-04-16 06:21:13 +00:00
|
|
|
|
|
|
|
|
|
#![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-19 19:24:25 +00:00
|
|
|
|
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, 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;
|
|
|
|
|
use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
|
2015-04-16 06:21:13 +00:00
|
|
|
|
|
2023-01-10 09:44:05 +00:00
|
|
|
|
use cfg_if::cfg_if;
|
2022-06-08 02:57:15 +00:00
|
|
|
|
|
2023-01-10 09:44:05 +00:00
|
|
|
|
cfg_if! {
|
2023-06-04 14:44:43 +00:00
|
|
|
|
if #[cfg(any(target_os = "vxworks", target_os = "espidf", target_os = "horizon", target_os = "vita"))] {
|
2023-01-10 09:44:05 +00:00
|
|
|
|
type UserId = u16;
|
|
|
|
|
type GroupId = u16;
|
|
|
|
|
} else if #[cfg(target_os = "nto")] {
|
|
|
|
|
// Both IDs are signed, see `sys/target_nto.h` of the QNX Neutrino SDP.
|
|
|
|
|
// Only positive values should be used, see e.g.
|
|
|
|
|
// https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/s/setuid.html
|
|
|
|
|
type UserId = i32;
|
|
|
|
|
type GroupId = i32;
|
|
|
|
|
} else {
|
|
|
|
|
type UserId = u32;
|
|
|
|
|
type GroupId = u32;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-08 02:57:15 +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")]
|
2022-06-08 02:57:15 +00:00
|
|
|
|
fn uid(&mut self, id: UserId) -> &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")]
|
2022-06-08 02:57:15 +00:00
|
|
|
|
fn gid(&mut self, id: GroupId) -> &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.
|
2021-11-10 01:28:56 +00:00
|
|
|
|
#[unstable(feature = "setgroups", issue = "90747")]
|
2022-06-08 02:57:15 +00:00
|
|
|
|
fn groups(&mut self, groups: &[GroupId]) -> &mut process::Command;
|
2020-06-16 04:39:34 +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.
|
|
|
|
|
///
|
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
|
|
|
|
|
where
|
|
|
|
|
F: FnMut() -> io::Result<()> + Send + Sync + 'static;
|
|
|
|
|
|
|
|
|
|
/// 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")]
|
2022-04-08 01:20:32 +00:00
|
|
|
|
#[deprecated(since = "1.37.0", note = "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-02-01 18:53:32 +00:00
|
|
|
|
where
|
|
|
|
|
F: FnMut() -> io::Result<()> + Send + Sync + 'static,
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
where
|
|
|
|
|
S: AsRef<OsStr>;
|
2022-02-03 09:40:45 +00:00
|
|
|
|
|
2022-07-16 21:45:16 +00:00
|
|
|
|
/// Sets the process group ID (PGID) of the child process. Equivalent to a
|
2022-06-15 22:12:03 +00:00
|
|
|
|
/// `setpgid` call in the child process, but may be more efficient.
|
|
|
|
|
///
|
|
|
|
|
/// Process groups determine which processes receive signals.
|
|
|
|
|
///
|
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// Pressing Ctrl-C in a terminal will send SIGINT to all processes in
|
|
|
|
|
/// the current foreground process group. By spawning the `sleep`
|
|
|
|
|
/// subprocess in a new process group, it will not receive SIGINT from the
|
|
|
|
|
/// terminal.
|
|
|
|
|
///
|
|
|
|
|
/// The parent process could install a signal handler and manage the
|
|
|
|
|
/// subprocess on its own terms.
|
|
|
|
|
///
|
2022-07-16 21:45:16 +00:00
|
|
|
|
/// A process group ID of 0 will use the process ID as the PGID.
|
|
|
|
|
///
|
2022-06-15 22:12:03 +00:00
|
|
|
|
/// ```no_run
|
|
|
|
|
/// use std::process::Command;
|
|
|
|
|
/// use std::os::unix::process::CommandExt;
|
|
|
|
|
///
|
|
|
|
|
/// Command::new("sleep")
|
|
|
|
|
/// .arg("10")
|
|
|
|
|
/// .process_group(0)
|
|
|
|
|
/// .spawn()?
|
|
|
|
|
/// .wait()?;
|
|
|
|
|
/// #
|
|
|
|
|
/// # Ok::<_, Box<dyn std::error::Error>>(())
|
|
|
|
|
/// ```
|
|
|
|
|
#[stable(feature = "process_set_process_group", since = "1.64.0")]
|
2022-02-03 09:40:45 +00:00
|
|
|
|
fn process_group(&mut self, pgroup: i32) -> &mut process::Command;
|
2015-04-16 06:21:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
|
impl CommandExt for process::Command {
|
2022-06-08 02:57:15 +00:00
|
|
|
|
fn uid(&mut self, id: UserId) -> &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
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-08 02:57:15 +00:00
|
|
|
|
fn gid(&mut self, id: GroupId) -> &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
|
|
|
|
|
2022-06-08 02:57:15 +00:00
|
|
|
|
fn groups(&mut self, groups: &[GroupId]) -> &mut process::Command {
|
2020-06-16 04:39:34 +00:00
|
|
|
|
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
|
2016-02-04 00:55:59 +00:00
|
|
|
|
where
|
|
|
|
|
F: FnMut() -> io::Result<()> + Send + Sync + 'static,
|
|
|
|
|
{
|
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
|
|
|
|
|
where
|
|
|
|
|
S: AsRef<OsStr>,
|
|
|
|
|
{
|
|
|
|
|
self.as_inner_mut().set_arg_0(arg.as_ref());
|
|
|
|
|
self
|
|
|
|
|
}
|
2022-02-03 09:40:45 +00:00
|
|
|
|
|
|
|
|
|
fn process_group(&mut self, pgroup: i32) -> &mut process::Command {
|
|
|
|
|
self.as_inner_mut().pgroup(pgroup);
|
|
|
|
|
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-11-08 17:28:02 +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-10-22 17:47:34 +00:00
|
|
|
|
#[stable(feature = "unix_process_wait_more", since = "1.58.0")]
|
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-10-22 17:47:34 +00:00
|
|
|
|
#[stable(feature = "unix_process_wait_more", since = "1.58.0")]
|
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-10-22 17:47:34 +00:00
|
|
|
|
#[stable(feature = "unix_process_wait_more", since = "1.58.0")]
|
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-10-22 17:47:34 +00:00
|
|
|
|
#[stable(feature = "unix_process_wait_more", since = "1.58.0")]
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-08 23:38:08 +00:00
|
|
|
|
#[stable(feature = "io_safety", since = "1.63.0")]
|
2021-08-17 23:28:00 +00:00
|
|
|
|
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
|
|
|
|
|
2022-03-08 23:38:08 +00:00
|
|
|
|
#[stable(feature = "io_safety", since = "1.63.0")]
|
2021-08-19 19:24:25 +00:00
|
|
|
|
impl AsFd for crate::process::ChildStdin {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn as_fd(&self) -> BorrowedFd<'_> {
|
|
|
|
|
self.as_inner().as_fd()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-08 23:38:08 +00:00
|
|
|
|
#[stable(feature = "io_safety", since = "1.63.0")]
|
2021-08-19 19:24:25 +00:00
|
|
|
|
impl From<crate::process::ChildStdin> for OwnedFd {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(child_stdin: crate::process::ChildStdin) -> OwnedFd {
|
|
|
|
|
child_stdin.into_inner().into_inner().into_inner()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 09:46:38 +00:00
|
|
|
|
/// Create a `ChildStdin` from the provided `OwnedFd`.
|
|
|
|
|
///
|
|
|
|
|
/// The provided file descriptor must point to a pipe
|
|
|
|
|
/// with the `CLOEXEC` flag set.
|
2023-10-02 23:12:46 +00:00
|
|
|
|
#[stable(feature = "child_stream_from_fd", since = "1.74.0")]
|
2022-07-06 13:29:17 +00:00
|
|
|
|
impl From<OwnedFd> for process::ChildStdin {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(fd: OwnedFd) -> process::ChildStdin {
|
|
|
|
|
let fd = sys::fd::FileDesc::from_inner(fd);
|
|
|
|
|
let pipe = sys::pipe::AnonPipe::from_inner(fd);
|
|
|
|
|
process::ChildStdin::from_inner(pipe)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-08 23:38:08 +00:00
|
|
|
|
#[stable(feature = "io_safety", since = "1.63.0")]
|
2021-08-19 19:24:25 +00:00
|
|
|
|
impl AsFd for crate::process::ChildStdout {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn as_fd(&self) -> BorrowedFd<'_> {
|
|
|
|
|
self.as_inner().as_fd()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-08 23:38:08 +00:00
|
|
|
|
#[stable(feature = "io_safety", since = "1.63.0")]
|
2021-08-19 19:24:25 +00:00
|
|
|
|
impl From<crate::process::ChildStdout> for OwnedFd {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(child_stdout: crate::process::ChildStdout) -> OwnedFd {
|
|
|
|
|
child_stdout.into_inner().into_inner().into_inner()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 09:46:38 +00:00
|
|
|
|
/// Create a `ChildStdout` from the provided `OwnedFd`.
|
|
|
|
|
///
|
|
|
|
|
/// The provided file descriptor must point to a pipe
|
|
|
|
|
/// with the `CLOEXEC` flag set.
|
2023-10-02 23:12:46 +00:00
|
|
|
|
#[stable(feature = "child_stream_from_fd", since = "1.74.0")]
|
2022-07-06 13:29:17 +00:00
|
|
|
|
impl From<OwnedFd> for process::ChildStdout {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(fd: OwnedFd) -> process::ChildStdout {
|
|
|
|
|
let fd = sys::fd::FileDesc::from_inner(fd);
|
|
|
|
|
let pipe = sys::pipe::AnonPipe::from_inner(fd);
|
|
|
|
|
process::ChildStdout::from_inner(pipe)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-08 23:38:08 +00:00
|
|
|
|
#[stable(feature = "io_safety", since = "1.63.0")]
|
2021-08-19 19:24:25 +00:00
|
|
|
|
impl AsFd for crate::process::ChildStderr {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn as_fd(&self) -> BorrowedFd<'_> {
|
|
|
|
|
self.as_inner().as_fd()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-08 23:38:08 +00:00
|
|
|
|
#[stable(feature = "io_safety", since = "1.63.0")]
|
2021-08-19 19:24:25 +00:00
|
|
|
|
impl From<crate::process::ChildStderr> for OwnedFd {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(child_stderr: crate::process::ChildStderr) -> OwnedFd {
|
|
|
|
|
child_stderr.into_inner().into_inner().into_inner()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 09:46:38 +00:00
|
|
|
|
/// Create a `ChildStderr` from the provided `OwnedFd`.
|
|
|
|
|
///
|
|
|
|
|
/// The provided file descriptor must point to a pipe
|
|
|
|
|
/// with the `CLOEXEC` flag set.
|
2023-10-02 23:12:46 +00:00
|
|
|
|
#[stable(feature = "child_stream_from_fd", since = "1.74.0")]
|
2022-07-06 13:29:17 +00:00
|
|
|
|
impl From<OwnedFd> for process::ChildStderr {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn from(fd: OwnedFd) -> process::ChildStderr {
|
|
|
|
|
let fd = sys::fd::FileDesc::from_inner(fd);
|
|
|
|
|
let pipe = sys::pipe::AnonPipe::from_inner(fd);
|
|
|
|
|
process::ChildStderr::from_inner(pipe)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-19 05:09:18 +00:00
|
|
|
|
/// Returns the OS-assigned process identifier associated with this process's parent.
|
2021-10-31 03:37:32 +00:00
|
|
|
|
#[must_use]
|
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
|
|
|
|
}
|