Struct yash_env::stack::EnvFrameGuard
source · pub struct EnvFrameGuard<'a> { /* private fields */ }Expand description
RAII-style guard that makes sure a stack frame is popped properly
The guard object is created by Env::push_frame.
Methods from Deref<Target = Env>§
sourcepub fn get_pwd_if_correct(&self) -> Option<&str>
pub fn get_pwd_if_correct(&self) -> Option<&str>
Returns the value of the $PWD variable if it is correct.
The variable is correct if:
- it is a scalar variable,
- its value is a pathname of the current working directory (possibly including symbolic link components), and
- there is no dot (
.) or dot-dot (..) component in the pathname.
sourcepub fn prepare_pwd(&mut self) -> Result<(), PreparePwdError>
pub fn prepare_pwd(&mut self) -> Result<(), PreparePwdError>
Updates the $PWD variable with the current working directory.
If the value of $PWD is correct, this
function does not modify it. Otherwise, this function sets the value to
self.system.getcwd().
This function is meant for initializing the $PWD variable when the
shell starts.
sourcepub fn push_frame(&mut self, frame: Frame) -> EnvFrameGuard<'_>
pub fn push_frame(&mut self, frame: Frame) -> EnvFrameGuard<'_>
Pushes a new frame to the runtime execution context stack.
This function is equivalent to self.stack.push(frame), but returns an
EnvFrameGuard that allows re-borrowing the Env.
sourcepub fn push_context(&mut self, context: Context) -> EnvContextGuard<'_>
pub fn push_context(&mut self, context: Context) -> EnvContextGuard<'_>
Pushes a new context to the variable set.
This function is equivalent to
self.variables.push_context(context_type), but returns an
EnvContextGuard that allows re-borrowing the Env.
sourcepub fn clone_with_system(&self, system: Box<dyn System>) -> Env
pub fn clone_with_system(&self, system: Box<dyn System>) -> Env
Clones this environment.
The application-managed parts of the environment are cloned normally.
The system-managed parts are replaced with the provided System
instance.
sourcepub fn init_variables(&mut self)
pub fn init_variables(&mut self)
Initializes default variables.
This function assigns the following variables to self:
IFS=' \t\n'OPTIND=1PS1='$ 'PS2='> 'PS4='+ 'PPID=(parent process ID)PWD=(current working directory)(SeeEnv::prepare_pwd)
This function ignores any errors that may occur.
TODO: PS1 should be set to "# " for root users.
sourcepub async fn wait_for_signals(&mut self) -> Rc<[Number]>
pub async fn wait_for_signals(&mut self) -> Rc<[Number]>
Waits for some signals to be caught in the current process.
Returns an array of signals caught.
This function is a wrapper for SharedSystem::wait_for_signals.
Before the function returns, it passes the results to
TrapSet::catch_signal so the trap set can remember the signals
caught to be handled later.
sourcepub async fn wait_for_signal(&mut self, signal: Number)
pub async fn wait_for_signal(&mut self, signal: Number)
Waits for a specific signal to be caught in the current process.
This function calls wait_for_signals
repeatedly until it returns results containing the specified signal.
sourcepub fn poll_signals(&mut self) -> Option<Rc<[Number]>>
pub fn poll_signals(&mut self) -> Option<Rc<[Number]>>
Returns signals that have been caught.
This function is similar to
wait_for_signals but does not wait for
signals to be caught. Instead, it only checks if any signals have been
caught but not yet consumed in the SharedSystem.
sourcepub fn get_tty(&mut self) -> Result<Fd, Errno>
pub fn get_tty(&mut self) -> Result<Fd, Errno>
Returns a file descriptor to the controlling terminal.
This function returns self.tty if it is Some FD. Otherwise, it
opens /dev/tty and saves the new FD to self.tty before returning it.
sourcepub fn is_interactive(&self) -> bool
pub fn is_interactive(&self) -> bool
Tests whether the current environment is an interactive shell.
This function returns true if and only if:
- the
Interactiveoption isOninself.options, and - the current context is not in a subshell (no
Frame::Subshellinself.stack).
sourcepub fn controls_jobs(&self) -> bool
pub fn controls_jobs(&self) -> bool
Tests whether the shell is performing job control.
This function returns true if and only if:
- the
Monitoroption isOninself.options, and - the current context is not in a subshell (no
Frame::Subshellinself.stack).
sourcepub async fn wait_for_subshell(
&mut self,
target: Pid,
) -> Result<(Pid, ProcessState), Errno>
pub async fn wait_for_subshell( &mut self, target: Pid, ) -> Result<(Pid, ProcessState), Errno>
Waits for a subshell to terminate, suspend, or resume.
This function waits for a subshell to change its execution state. The
target parameter specifies which child to wait for:
-1: any child0: any child in the same process group as the current processpid: the child whose process ID ispid-pgid: any child in the process group whose process group ID ispgid
When self.system.wait returned a new state of the
target, it is sent to self.jobs (JobList::update_status) before
being returned from this function.
If there is no matching target, this function returns
Err(Errno::ECHILD).
If the target subshell is not job-controlled, you may want to use
wait_for_subshell_to_finish
instead.
sourcepub async fn wait_for_subshell_to_finish(
&mut self,
target: Pid,
) -> Result<(Pid, ExitStatus), Errno>
pub async fn wait_for_subshell_to_finish( &mut self, target: Pid, ) -> Result<(Pid, ExitStatus), Errno>
Wait for a subshell to terminate.
This function is similar to
wait_for_subshell, but returns only when
the target is finished (either exited or killed by a signal).
Returns the process ID of the awaited process and its exit status.
sourcepub fn update_all_subshell_statuses(&mut self)
pub fn update_all_subshell_statuses(&mut self)
Applies all job status updates to jobs in self.jobs.
This function calls self.system.wait repeatedly until
all status updates available are applied to self.jobs
(JobList::update_status).
Note that updates of subshells that are not managed in self.jobs are
lost when you call this function.
sourcepub fn get_or_create_variable<S>(
&mut self,
name: S,
scope: Scope,
) -> VariableRefMut<'_>
pub fn get_or_create_variable<S>( &mut self, name: S, scope: Scope, ) -> VariableRefMut<'_>
Get an existing variable or create a new one.
This method is a thin wrapper around VariableSet::get_or_new.
If the AllExport option is on, the variable is
exported before being returned from the
method.
You should prefer using this method over VariableSet::get_or_new to
make sure that the AllExport option is applied.
sourcepub fn errexit_is_applicable(&self) -> bool
pub fn errexit_is_applicable(&self) -> bool
sourcepub fn apply_errexit(&self) -> ControlFlow<Divert>
pub fn apply_errexit(&self) -> ControlFlow<Divert>
Returns a Divert if the shell should exit because of the ErrExit
shell option.
The function returns Break(Divert::Exit(None)) if the errexit
option is applicable and the current
self.exit_status is non-zero. Otherwise, it returns Continue(()).
sourcepub fn apply_result(&mut self, result: Result)
pub fn apply_result(&mut self, result: Result)
Updates the exit status from the given result.
If result is a Break(divert) where divert.exit_status() is Some
exit status, this function sets self.exit_status to that exit status.
Trait Implementations§
source§impl<'a> Debug for EnvFrameGuard<'a>
impl<'a> Debug for EnvFrameGuard<'a>
source§impl Deref for EnvFrameGuard<'_>
impl Deref for EnvFrameGuard<'_>
source§impl DerefMut for EnvFrameGuard<'_>
impl DerefMut for EnvFrameGuard<'_>
Auto Trait Implementations§
impl<'a> Freeze for EnvFrameGuard<'a>
impl<'a> !RefUnwindSafe for EnvFrameGuard<'a>
impl<'a> !Send for EnvFrameGuard<'a>
impl<'a> !Sync for EnvFrameGuard<'a>
impl<'a> Unpin for EnvFrameGuard<'a>
impl<'a> !UnwindSafe for EnvFrameGuard<'a>
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> 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