TrapSet

Struct TrapSet 

Source
pub struct TrapSet { /* private fields */ }
Expand description

Collection of event handling settings.

See the module documentation for details.

Implementations§

Source§

impl TrapSet

Source

pub fn get_state<C: Into<Condition>>( &self, cond: C, ) -> (Option<&TrapState>, Option<&TrapState>)

Returns the current and parent states for a condition.

This function returns a pair of optional trap states. The first is the currently configured trap action, and the second is the action set before enter_subshell was called.

The current state (the first return value) is None if the state is unknown (because no trap action or internal disposition has been set for the signal specified by the condition). To get the current signal disposition in this case, use peek_state.

The parent state (the second return value) is None if the shell environment has not entered a subshell or a trap action has been modified after entering the subshell.

Source

pub fn peek_state<S: SignalSystem, C: Into<Condition>>( &mut self, system: &S, cond: C, ) -> Result<&TrapState, Errno>

Returns the current state for a condition.

This function returns the trap action for the specified condition that is to be included in the output of the trap built-in.

If the current state is not yet known (because no trap action or internal disposition has been set for the signal specified by the condition), it calls SignalSystem::get_disposition to get the current signal disposition and saves it as the current state.

If the shell environment has entered a subshell and no trap action has been modified after entering the subshell, the state that was active before entering the subshell is returned.

See also get_state, which returns None if the current state is not yet known.

Source

pub fn set_action<S: SignalSystem, C: Into<Condition>>( &mut self, system: &mut S, cond: C, action: Action, origin: Location, override_ignore: bool, ) -> Result<(), SetActionError>

Sets a trap action for a condition.

If the condition is a signal, this function installs a signal handler to the specified underlying system.

If override_ignore is false, you cannot set a trap for a signal that has been ignored since the shell startup. An interactive shell should set override_ignore to true to bypass this restriction.

You can never set a trap for SIGKILL or SIGSTOP.

origin should be the location of the command performing this trap update. It is only informative: It does not affect the signal handling behavior and can be referenced later by get_state.

This function clears all parent states remembered when entering a subshell, not only for the specified condition but also for all other conditions.

Source

pub fn iter(&self) -> Iter<'_>

Returns an iterator over the signal actions configured in this trap set.

The iterator yields tuples of the signal, the currently configured trap action, and the action set before enter_subshell was called.

The iterator only emits conditions for which a trap action has been set or peeked. In other words, it does not include conditions for which the current state is not yet known. To get the state for all conditions, use peek_state for each condition.

Source

pub fn enter_subshell<S: SignalSystem>( &mut self, system: &mut S, ignore_sigint_sigquit: bool, keep_internal_dispositions_for_stoppers: bool, )

Updates signal dispositions on entering a subshell.

§Resetting non-ignore traps

POSIX requires that traps other than Action::Ignore be reset when entering a subshell. This function achieves that effect.

The trap set will remember the original trap states as the parent states. You can get them from the second return value of get_state or the third item of tuples yielded by an iterator.

Note that trap actions other than Trap::Command remain as before.

§Clearing internal dispositions

Internal dispositions that have been installed are cleared except for the SIGCHLD signal.

§Ignoring SIGINT and SIGQUIT

If ignore_sigint_sigquit is true, this function sets the dispositions for SIGINT and SIGQUIT to Ignore.

§Ignoring SIGTSTP, SIGTTIN, and SIGTTOU

If keep_internal_dispositions_for_stoppers is true and the internal dispositions have been enabled for SIGTSTP, SIGTTIN, and SIGTTOU, this function leaves the dispositions for those signals set to Ignore.

§Errors

This function ignores any errors that may occur when setting signal dispositions.

Source

pub fn catch_signal(&mut self, signal: Number)

Sets the pending flag of the TrapState for the specified signal.

This function does nothing if no trap action has been set for the signal.

Source

pub fn take_signal_if_caught(&mut self, signal: Number) -> Option<&TrapState>

Resets the pending flag of the TrapState for the specified signal.

Returns the TrapState if the flag was set.

Source

pub fn take_caught_signal(&mut self) -> Option<(Number, &TrapState)>

Returns a signal that has been caught.

This function clears the pending flag of the TrapState for the specified signal.

If there is more than one caught signal, it is unspecified which one of them is returned. If there is no caught signal, None is returned.

Source

pub fn enable_internal_disposition_for_sigchld<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>

Installs the internal disposition for SIGCHLD.

You should install the internal disposition for SIGCHLD by using this function before waiting for SIGCHLD with System::wait and SharedSystem::wait_for_signal. The disposition allows catching SIGCHLD.

This function remembers that the disposition has been installed, so a second call to the function will be a no-op.

Source

pub fn enable_internal_dispositions_for_terminators<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>

Installs the internal dispositions for SIGINT, SIGTERM, and SIGQUIT.

An interactive shell should install the internal dispositions for these signals by using this function. The dispositions catch SIGINT and ignore SIGTERM and SIGQUIT.

This function remembers that the dispositions have been installed, so a second call to the function will be a no-op.

Source

pub fn enable_internal_dispositions_for_stoppers<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>

Installs the internal dispositions for SIGTSTP, SIGTTIN, and SIGTTOU.

An interactive job-controlling shell should install the internal dispositions for these signals by using this function. The dispositions ignore the signals.

This function remembers that the dispositions have been installed, so a second call to the function will be a no-op.

Source

pub fn disable_internal_dispositions_for_terminators<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>

Uninstalls the internal dispositions for SIGINT, SIGTERM, and SIGQUIT.

Source

pub fn disable_internal_dispositions_for_stoppers<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>

Uninstalls the internal dispositions for SIGTSTP, SIGTTIN, and SIGTTOU.

Source

pub fn disable_internal_dispositions<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>

Uninstalls all internal dispositions.

This function removes all internal dispositions that have been previously installed by self, except for the SIGCHLD signal. Dispositions for any existing user-defined traps are not affected.

Trait Implementations§

Source§

impl Clone for TrapSet

Source§

fn clone(&self) -> TrapSet

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TrapSet

Source§

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

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

impl Default for TrapSet

Source§

fn default() -> TrapSet

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

impl<'a> IntoIterator for &'a TrapSet

Source§

type Item = (&'a Condition, &'a TrapState, Option<&'a TrapState>)

Type of items yielded by this iterator

Each item is a tuple of a condition, the currently configured trap state, and the parent state that was active before entering a subshell.

Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Iter<'a>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl Freeze for TrapSet

§

impl !RefUnwindSafe for TrapSet

§

impl !Send for TrapSet

§

impl !Sync for TrapSet

§

impl Unpin for TrapSet

§

impl !UnwindSafe for TrapSet

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.