pub struct Process<'a> { /* private fields */ }Expand description
A live sandboxed process with caller-owned stdio streams, returned by
Sandbox::popen.
take_stdin / take_stdout / take_stderr move out the pipe end of each
stream opened with StdioMode::Piped (each available once); the caller
reads/writes those while the process runs. Unlike std::process::Child,
this borrows the originating Sandbox rather than owning the process:
the process is killed and reaped when that Sandbox is dropped, or eagerly
via Process::kill.
A Process that is dropped without Process::wait leaves the child
running until the Sandbox is dropped — call wait (or kill) to end it.
Implementations§
Source§impl Process<'_>
impl Process<'_>
Sourcepub fn take_stdin(&mut self) -> Option<OwnedFd>
pub fn take_stdin(&mut self) -> Option<OwnedFd>
Take the write end of a Piped stdin. The caller writes the child’s
input; closing this fd signals EOF. None if stdin was not piped or was
already taken.
Deadlock warning (as with std::process::Child): if you take stdin you
own it — drop/close it before Process::wait, or a child that reads to
EOF (e.g. cat) never exits and wait blocks forever. (An untaken
piped stdin is closed by wait for you.)
Sourcepub fn take_stdout(&mut self) -> Option<OwnedFd>
pub fn take_stdout(&mut self) -> Option<OwnedFd>
Take the read end of a Piped stdout. None if stdout was not piped or
was already taken.
Sourcepub fn take_stderr(&mut self) -> Option<OwnedFd>
pub fn take_stderr(&mut self) -> Option<OwnedFd>
Take the read end of a Piped stderr. None if stderr was not piped or
was already taken.
Sourcepub fn pid(&self) -> Option<i32>
pub fn pid(&self) -> Option<i32>
The child PID, or None if not spawned. Remains Some after the child
exits (until the Sandbox is dropped).
Sourcepub fn kill(&mut self) -> Result<(), SandlockError>
pub fn kill(&mut self) -> Result<(), SandlockError>
Send SIGKILL to the child’s entire process group (every process the workload spawned, not just the top-level child). Idempotent — a process that already exited is not an error.
Sourcepub async fn wait(self) -> Result<RunResult, SandlockError>
pub async fn wait(self) -> Result<RunResult, SandlockError>
Wait for the child to exit. Any Piped stdout/stderr the caller did not
take is drained into the returned RunResult; taken streams are None
because the caller owns them. An untaken piped stdin is closed here so the
child sees EOF; a taken stdin the caller must close itself first (see
Process::take_stdin) or this blocks forever.