Skip to main content

SpawnOptions

Struct SpawnOptions 

Source
pub struct SpawnOptions {
    pub cgroup_procs: Option<Arc<CString>>,
    pub open_file_limit: Option<u64>,
    pub pids_limits: Arc<[PidsLimit]>,
    pub on_spawn: Option<Arc<dyn Fn(SpawnedProcess) + Send + Sync>>,
}
Expand description

What the shell does with each external process it spawns, for an embedder that confines or tracks the processes its commands start. The default does nothing.

The options are part of the shell’s RuntimeOptions, so they reach every external command the shell runs, pipelines, background jobs and subshells included, since those copy the shell they run in.

The exec builtin applies them in the shell’s own process, with no fork, so an exec that fails leaves in place the steps that ran before the failure. The order is the cgroup join, the process counts, the shell’s other descriptors, then the open-file limit; with process counts set, the builtin refuses before any step runs.

Fields§

§cgroup_procs: Option<Arc<CString>>

A file each child writes 0 to after it is forked and before it runs its program. For a cgroup v2’s cgroup.procs file, the write moves the child into that cgroup, so it cannot fork a process outside it; only Linux has cgroups. When the child cannot open the file or write to it, the command fails to execute and its program never runs.

§open_file_limit: Option<u64>

The soft limit on open files (RLIMIT_NOFILE) each child gets, set after it is forked and before it runs its program, for an embedder that raised its own soft limit and gives its children the one it started with. A value above the hard limit sets the hard limit, and on macOS a value it refuses is lowered to OPEN_MAX (10240). None leaves the limit the child inherits; on a platform without resource limits, setting it fails every external command.

§pids_limits: Arc<[PidsLimit]>

Process counts each child checks after it joins the cgroup in cgroup_procs and before it runs its program. The kernel does not apply a cgroup’s pids.max to a process that moves into it, so the child checks the count itself and fails its spawn, without running its program, when a count is above its limit or cannot be read: the command then fails to execute, with status 126, and on_spawn is not called. The exec builtin refuses to replace the shell while the list is non-empty, because in the shell’s own process a count would include every thread of the shell; a subshell’s exec forks and is checked as usual. Empty, the default, checks nothing; on a platform without this check, a non-empty list fails every external command.

§on_spawn: Option<Arc<dyn Fn(SpawnedProcess) + Send + Sync>>

Called with each child once it has started, before the shell waits for it. It runs on the shell’s task, so it should return quickly.

Trait Implementations§

Source§

impl Clone for SpawnOptions

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpawnOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpawnOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more