summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/process/wait.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/process/wait.rs')
-rw-r--r--vendor/rustix/src/process/wait.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/vendor/rustix/src/process/wait.rs b/vendor/rustix/src/process/wait.rs
index a4bd1b528..784e6627c 100644
--- a/vendor/rustix/src/process/wait.rs
+++ b/vendor/rustix/src/process/wait.rs
@@ -2,6 +2,9 @@ use crate::process::Pid;
use crate::{backend, io};
use bitflags::bitflags;
+#[cfg(target_os = "linux")]
+use crate::fd::BorrowedFd;
+
bitflags! {
/// Options for modifying the behavior of wait/waitpid
pub struct WaitOptions: u32 {
@@ -14,6 +17,23 @@ bitflags! {
}
}
+#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))]
+bitflags! {
+ /// Options for modifying the behavior of waitid
+ pub struct WaitidOptions: u32 {
+ /// Return immediately if no child has exited.
+ const NOHANG = backend::process::wait::WNOHANG as _;
+ /// Return if a stopped child has been resumed by delivery of `SIGCONT`
+ const CONTINUED = backend::process::wait::WCONTINUED as _;
+ /// Wait for processed that have exited.
+ const EXITED = backend::process::wait::WEXITED as _;
+ /// Keep processed in a waitable state.
+ const NOWAIT = backend::process::wait::WNOWAIT as _;
+ /// Wait for processes that have been stopped.
+ const STOPPED = backend::process::wait::WSTOPPED as _;
+ }
+}
+
/// the status of the child processes the caller waited on
#[derive(Debug, Clone, Copy)]
pub struct WaitStatus(u32);
@@ -77,6 +97,33 @@ impl WaitStatus {
}
}
+/// The status of a process after calling [`waitid`].
+#[derive(Clone, Copy)]
+#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))]
+pub struct WaitidStatus(pub(crate) backend::c::siginfo_t);
+
+/// The identifier to wait on in a call to [`waitid`].
+#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))]
+#[derive(Debug, Clone)]
+#[non_exhaustive]
+pub enum WaitId<'a> {
+ /// Wait on all processes.
+ All,
+
+ /// Wait for a specific process ID.
+ Pid(Pid),
+
+ /// Wait for a specific process file descriptor.
+ #[cfg(target_os = "linux")]
+ PidFd(BorrowedFd<'a>),
+
+ /// Eat the lifetime for non-Linux platforms.
+ #[doc(hidden)]
+ #[cfg(not(target_os = "linux"))]
+ __EatLifetime(std::marker::PhantomData<&'a ()>),
+ // TODO(notgull): Once this crate has the concept of PGIDs, add a WaitId::Pgid
+}
+
/// `waitpid(pid, waitopts)`—Wait for a specific process to change state.
///
/// If the pid is `None`, the call will wait for any child process whose
@@ -127,3 +174,14 @@ pub fn waitpid(pid: Option<Pid>, waitopts: WaitOptions) -> io::Result<Option<Wai
pub fn wait(waitopts: WaitOptions) -> io::Result<Option<(Pid, WaitStatus)>> {
backend::process::syscalls::wait(waitopts)
}
+
+/// `waitid(_, _, _, opts)`—Wait for the specified child process to change
+/// state.
+#[cfg(not(any(target_os = "wasi", target_os = "redox", target_os = "openbsd")))]
+#[inline]
+pub fn waitid<'a>(
+ id: impl Into<WaitId<'a>>,
+ options: WaitidOptions,
+) -> io::Result<Option<WaitidStatus>> {
+ backend::process::syscalls::waitid(id.into(), options)
+}