pub trait ExecExt {
// Required methods
fn setuid(self, uid: u32) -> Self;
fn setgid(self, gid: u32) -> Self;
fn setpgid(self) -> Self;
unsafe fn pre_exec<F>(self, f: F) -> Self
where F: FnMut() -> Result<()> + Send + Sync + 'static;
}Expand description
Extension trait for Unix-specific process creation options.
Required Methods§
Sourcefn setuid(self, uid: u32) -> Self
fn setuid(self, uid: u32) -> Self
Set the user ID for the spawned process.
The child process will run with the specified user ID, which affects file
access permissions and process ownership. This calls setuid(2) in the child
process after fork() but before exec().
Sourcefn setgid(self, gid: u32) -> Self
fn setgid(self, gid: u32) -> Self
Set the group ID for the spawned process.
The child process will run with the specified group ID, which affects file
access permissions based on group ownership. This calls setgid(2) in the
child process after fork() but before exec().
Sourcefn setpgid(self) -> Self
fn setpgid(self) -> Self
Put the subprocess into its own process group.
This calls setpgid(0, 0) before exec’ing the child process, making it the
leader of a new process group. Useful for a single process that spawns
children, allowing them all to be signaled as a group with
ProcessExt::send_signal_group.
For pipelines, use PipelineExt::setpgid instead, which puts all pipeline
processes into a shared group.
Sourceunsafe fn pre_exec<F>(self, f: F) -> Self
unsafe fn pre_exec<F>(self, f: F) -> Self
Schedule a closure to run in the child process between fork() and exec().
This is useful for performing setup that must happen in the child, such as
setting resource limits, calling setsid(), or closing extra file
descriptors.
Multiple closures can be registered and they will run in the order they were added. If any closure returns an error, the child process will exit and the error will be reported to the parent.
Closures run after all builder-configured setup and immediately before the
exec(). To run code with the parent’s original privileges, omit the
corresponding builder methods and drop privileges manually at the end of the
closure.
§Safety
The closure runs after fork() in the child process. It must only call
async-signal-safe functions. In particular, it must not allocate, acquire
locks, or call into code that does so. Violating this may cause deadlocks or
undefined behavior in the child process.
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.