pub struct TrapSet { /* private fields */ }Expand description
Collection of event handling settings.
See the module documentation for details.
Implementations§
Source§impl TrapSet
impl TrapSet
Sourcepub fn get_state<C: Into<Condition>>(
&self,
cond: C,
) -> (Option<&TrapState>, Option<&TrapState>)
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.
Sourcepub fn peek_state<S: SignalSystem, C: Into<Condition>>(
&mut self,
system: &S,
cond: C,
) -> Result<&TrapState, Errno>
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.
Sourcepub fn set_action<S: SignalSystem, C: Into<Condition>>(
&mut self,
system: &mut S,
cond: C,
action: Action,
origin: Location,
override_ignore: bool,
) -> Result<(), SetActionError>
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.
Sourcepub fn iter(&self) -> Iter<'_> ⓘ
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.
Sourcepub fn enter_subshell<S: SignalSystem>(
&mut self,
system: &mut S,
ignore_sigint_sigquit: bool,
keep_internal_dispositions_for_stoppers: bool,
)
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.
Sourcepub fn catch_signal(&mut self, signal: Number)
pub fn catch_signal(&mut self, signal: Number)
Sourcepub fn take_signal_if_caught(&mut self, signal: Number) -> Option<&TrapState>
pub fn take_signal_if_caught(&mut self, signal: Number) -> Option<&TrapState>
Sourcepub fn take_caught_signal(&mut self) -> Option<(Number, &TrapState)>
pub fn take_caught_signal(&mut self) -> Option<(Number, &TrapState)>
Sourcepub fn enable_internal_disposition_for_sigchld<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
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.
Sourcepub fn enable_internal_dispositions_for_terminators<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
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.
Sourcepub fn enable_internal_dispositions_for_stoppers<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
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.
Sourcepub fn disable_internal_dispositions_for_terminators<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
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.
Sourcepub fn disable_internal_dispositions_for_stoppers<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
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.
Sourcepub fn disable_internal_dispositions<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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