Skip to main content

CapStdExtCommandExt

Trait CapStdExtCommandExt 

Source
pub trait CapStdExtCommandExt {
    // Required methods
    fn take_fd_n(&mut self, fd: Arc<OwnedFd>, target: i32) -> &mut Self;
    fn take_fds(&mut self, fds: CmdFds) -> &mut Self;
    fn cwd_dir(&mut self, dir: Dir) -> &mut Self;
    fn lifecycle_bind_to_parent_thread(&mut self) -> &mut Self;
}
Expand description

Extension trait for std::process::Command.

Required Methods§

Source

fn take_fd_n(&mut self, fd: Arc<OwnedFd>, target: i32) -> &mut Self

👎Deprecated:

Use CmdFds with take_fds() instead

Pass a file descriptor into the target process at a specific fd number.

§Deprecated

Use CmdFds with take_fds instead. This method registers an independent pre_exec hook per call, which means multiple take_fd_n calls (or mixing with take_fds) can clobber each other when a source fd’s raw number equals another mapping’s target. take_fds handles this correctly with atomic fd shuffling.

Source

fn take_fds(&mut self, fds: CmdFds) -> &mut Self

Apply a CmdFds to this command, passing all registered file descriptors and (if configured) setting up the systemd socket-activation environment.

§Important: Do not use Command::env() with systemd fds

When systemd socket-activation environment variables are configured (via CmdFds::new_systemd_fds), they are set using setenv(3) in a pre_exec hook. If Command::env() is also called, Rust will build an envp array that replaces the process environment, causing the LISTEN_* variables set by the hook to be lost. Command::envs() is equally problematic. If you need to set additional environment variables alongside systemd fds, set them via pre_exec + setenv as well.

Source

fn cwd_dir(&mut self, dir: Dir) -> &mut Self

Use the given directory as the current working directory for the process.

Source

fn lifecycle_bind_to_parent_thread(&mut self) -> &mut Self

On Linux, arrange for [SIGTERM] to be delivered to the child if the parent thread exits. This helps avoid leaking child processes if the parent crashes for example.

§IMPORTANT

Due to the semantics of https://man7.org/linux/man-pages/man2/prctl.2.html this will cause the child to exit when the parent thread (not process) exits. In particular this can become problematic when used with e.g. a threadpool such as Tokio’s https://kobzol.github.io/rust/2025/02/23/tokio-plus-prctl-equals-nasty-bug.html.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl CapStdExtCommandExt for Command

Source§

fn take_fd_n(&mut self, fd: Arc<OwnedFd>, target: i32) -> &mut Self

👎Deprecated:

Use CmdFds with take_fds() instead

Source§

fn take_fds(&mut self, fds: CmdFds) -> &mut Self

Source§

fn cwd_dir(&mut self, dir: Dir) -> &mut Self

Source§

fn lifecycle_bind_to_parent_thread(&mut self) -> &mut Self

Implementors§