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 state 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.
This function does not reflect the initial signal actions the shell inherited on startup.
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.
sourcepub fn enter_subshell<S: SignalSystem>(
&mut self,
system: &mut S,
ignore_sigint_sigquit: bool,
keep_stopper_handlers: bool,
)
pub fn enter_subshell<S: SignalSystem>( &mut self, system: &mut S, ignore_sigint_sigquit: bool, keep_stopper_handlers: bool, )
Updates signal handlings 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 handlers
Internal handlers that have been installed are cleared except for the SIGCHLD handler.
§Ignoring SIGINT and SIGQUIT
If ignore_sigint_sigquit is true, this function sets the signal
handlings for SIGINT and SIGQUIT to Ignore.
§Ignoring SIGTSTP, SIGTTIN, and SIGTTOU
If keep_stopper_handlers is true and the stopper handlers have been
enabled, this function leaves the
signal handlings for SIGTSTP, SIGTTIN, and SIGTTOU set to Ignore.
§Errors
This function ignores any errors that may occur when setting signal handlings.
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_sigchld_handler<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
pub fn enable_sigchld_handler<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>
Installs an internal handler for SIGCHLD.
You should install the SIGCHLD handler to the system by using this
function before waiting for SIGCHLD with System::wait and
SharedSystem::wait_for_signal. The handler allows catching
SIGCHLD.
This function remembers that the handler has been installed, so a second call to the function will be a no-op.
sourcepub fn enable_terminator_handlers<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
pub fn enable_terminator_handlers<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>
Installs internal handlers for SIGINT, SIGTERM, and SIGQUIT.
An interactive shell should install the handlers for these signals by
using this function. The SIGINT handler allows catching SIGINT and
the SIGTERM and SIGQUIT handlers ignore the signals.
This function remembers that the handlers have been installed, so a second call to the function will be a no-op.
sourcepub fn enable_stopper_handlers<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
pub fn enable_stopper_handlers<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>
Installs internal handlers for SIGTSTP, SIGTTIN, and SIGTTOU.
An interactive job-controlling shell should install the handlers for these signals by using this function. The handlers ignore the signals.
This function remembers that the handlers have been installed, so a second call to the function will be a no-op.
sourcepub fn disable_terminator_handlers<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
pub fn disable_terminator_handlers<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>
Uninstalls the internal handlers for SIGINT, SIGTERM, and SIGQUIT.
sourcepub fn disable_stopper_handlers<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
pub fn disable_stopper_handlers<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>
Uninstalls the internal handlers for SIGTSTP, SIGTTIN, and SIGTTOU.
sourcepub fn disable_internal_handlers<S: SignalSystem>(
&mut self,
system: &mut S,
) -> Result<(), Errno>
pub fn disable_internal_handlers<S: SignalSystem>( &mut self, system: &mut S, ) -> Result<(), Errno>
Uninstalls all internal handlers.
This function removes all internal handlers that have been previously
installed by self. It leaves handlers for any existing user-defined
traps.
Trait Implementations§
source§impl<'a> IntoIterator for &'a TrapSet
impl<'a> IntoIterator for &'a TrapSet
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)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