Skip to main content

Config

Struct Config 

Source
#[non_exhaustive]
pub struct Config { pub job_control: Option<JobControl>, pub ignores_sigint_sigquit: bool, }
Expand description

Configuration for subshell creation

This struct configures how a subshell is created. An instance of Config can be created with new or foreground, and modified by setting the fields. To start a subshell, call start or start_and_wait.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§job_control: Option<JobControl>

Specifies disposition of the subshell with respect to job control.

If this value is None (which is the default), the subshell runs in the same process group as the parent process. If it is Some(_), the subshell becomes a new process group leader. For Some(JobControl::Foreground), it also brings itself to the foreground.

This parameter is ignored if the shell is not controlling jobs when starting the subshell. You can tell the actual job control status of the subshell by checking the second return value of start in the parent environment and the second argument passed to the task in the subshell environment.

If the parent process is a job-controlling interactive shell, but the subshell is not job-controlled, the subshell’s signal dispositions for SIGTSTP, SIGTTIN, and SIGTTOU are set to Ignore. This is to prevent the subshell from being stopped by a job-stopping signal. Were the subshell stopped, you could never resume it since it is not job-controlled.

§ignores_sigint_sigquit: bool

If true, the subshell ignores SIGINT and SIGQUIT.

This parameter is for implementing the POSIX requirement that asynchronous and-or lists ignore SIGINT and SIGQUIT if job control is disabled. The value is passed to TrapSet::enter_subshell to modify the signal dispositions for SIGINT and SIGQUIT in the subshell.

This parameter has no effect if the subshell is job-controlled (see job_control). The default value is false.

Implementations§

Source§

impl Config

Source

pub fn new() -> Self

Creates a new Config with default settings.

Source

pub fn foreground() -> Self

Creates a new Config with foreground job control.

This is a convenient function to create a Config for a subshell that should run in the foreground if job control is active. The returned Config has job_control set to Some(JobControl::Foreground), and the other fields set to their default values.

Source

pub async fn start<S, F>( self, env: &mut Env<S>, task: F, ) -> Result<(Pid, Option<JobControl>), Errno>

Starts the subshell.

This function creates a new child process that runs the task provided as an argument.

Although this function is async, it does not wait for the child to finish, which means the parent and child processes will run concurrently. To wait for the child to change state, call Env::wait_for_subshell, Env::wait_for_subshell_to_halt, or Env::wait_for_subshell_to_finish. If job control is active, you may want to add the process ID to Env::jobs before waiting. To start the subshell and wait for it to finish at once, use start_and_wait.

If you set job_control to Some(JobControl::Foreground), this function opens Env::tty by calling Env::get_tty. The tty is used to change the foreground job to the new subshell. However, job_control is effective only when the shell is controlling jobs.

If the subshell started successfully, the return value is a pair of the child process ID and the actual job control status. Otherwise, it indicates the error.

Source

pub async fn start_and_wait<S, F>( self, env: &mut Env<S>, task: F, ) -> Result<(Pid, ProcessResult), Errno>

Starts the subshell and waits for it to finish.

This function starts self and waits for it to finish. This function returns when the subshell process exits or is killed by a signal. If the subshell is job-controlled, the function also returns when the job is suspended.

If the subshell started successfully, the return value is the process ID and the process result of the subshell. If there was an error starting the subshell, this function returns the error.

If you set job_control to JobControl::Foreground and job control is effective as per Env::controls_jobs, this function makes the shell the foreground job after the subshell terminated or suspended.

When a job-controlled subshell suspends, this function does not add it to env.jobs. You have to do it for yourself if necessary.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

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 Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Config

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<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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.