diff --git a/yash-builtin/src/fg.rs b/yash-builtin/src/fg.rs index fd87e932..da90527f 100644 --- a/yash-builtin/src/fg.rs +++ b/yash-builtin/src/fg.rs @@ -92,7 +92,6 @@ use yash_env::job::id::parse; use yash_env::job::JobList; use yash_env::job::Pid; use yash_env::job::ProcessState; -use yash_env::semantics::ExitStatus; use yash_env::semantics::Field; use yash_env::system::Errno; use yash_env::system::System as _; @@ -189,7 +188,11 @@ pub async fn main(env: &mut Env, args: Vec) -> crate::Result { }; match result { - Ok(state) => ExitStatus::try_from(state).unwrap().into(), + Ok(state) => env + .system + .exit_status_for_process_state(state) + .unwrap() + .into(), Err(error) => report_simple_failure(env, &error.to_string()).await, } } @@ -208,6 +211,7 @@ mod tests { use yash_env::job::ProcessState; use yash_env::option::Option::Monitor; use yash_env::option::State::On; + use yash_env::semantics::ExitStatus; use yash_env::subshell::JobControl; use yash_env::subshell::Subshell; use yash_env::system::r#virtual::Process; diff --git a/yash-env/src/job.rs b/yash-env/src/job.rs index 6a940e05..0b46e9ed 100644 --- a/yash-env/src/job.rs +++ b/yash-env/src/job.rs @@ -141,28 +141,6 @@ impl ProcessState { } } -/// Error value indicating that the process is running. -/// -/// This error value may be returned by [`TryFrom::try_from`]. -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] -pub struct RunningProcess; - -/// Converts `ProcessState` to `ExitStatus`. -/// -/// For the `Running` state, the conversion fails with [`RunningProcess`]. -impl TryFrom for ExitStatus { - type Error = RunningProcess; - fn try_from(state: ProcessState) -> Result { - match state { - ProcessState::Exited(exit_status) => Ok(exit_status), - ProcessState::Signaled { signal, .. } | ProcessState::Stopped(signal) => { - Ok(ExitStatus::from(signal)) - } - ProcessState::Running => Err(RunningProcess), - } - } -} - /// Set of one or more processes executing a pipeline /// /// In the current implementation, a job contains the process ID of one child diff --git a/yash-env/src/lib.rs b/yash-env/src/lib.rs index 92ced0bc..0686d76b 100644 --- a/yash-env/src/lib.rs +++ b/yash-env/src/lib.rs @@ -361,7 +361,8 @@ impl Env { loop { let (pid, state) = self.wait_for_subshell(target).await?; if !state.is_alive() { - return Ok((pid, state.try_into().unwrap())); + let exit_status = self.system.exit_status_for_process_state(state).unwrap(); + return Ok((pid, exit_status)); } } } diff --git a/yash-semantics/src/command/compound_command/subshell.rs b/yash-semantics/src/command/compound_command/subshell.rs index 0fbc7d6b..88ba7074 100644 --- a/yash-semantics/src/command/compound_command/subshell.rs +++ b/yash-semantics/src/command/compound_command/subshell.rs @@ -28,6 +28,7 @@ use yash_env::semantics::ExitStatus; use yash_env::semantics::Result; use yash_env::subshell::JobControl; use yash_env::subshell::Subshell; +use yash_env::system::SystemEx as _; use yash_env::Env; use yash_syntax::source::Location; use yash_syntax::syntax::List; @@ -47,7 +48,7 @@ pub async fn execute(env: &mut Env, body: Rc, location: &Location) -> Resu env.jobs.add(job); } - env.exit_status = state.try_into().unwrap(); + env.exit_status = env.system.exit_status_for_process_state(state).unwrap(); env.apply_errexit() } Err(errno) => { diff --git a/yash-semantics/src/command/pipeline.rs b/yash-semantics/src/command/pipeline.rs index 1fae57f2..ed318688 100644 --- a/yash-semantics/src/command/pipeline.rs +++ b/yash-semantics/src/command/pipeline.rs @@ -36,7 +36,7 @@ use yash_env::subshell::JobControl; use yash_env::subshell::Subshell; use yash_env::system::Errno; use yash_env::system::FdFlag; -use yash_env::system::SystemEx; +use yash_env::system::SystemEx as _; use yash_env::Env; use yash_env::System; use yash_syntax::syntax; @@ -152,7 +152,7 @@ async fn execute_job_controlled_pipeline( env.jobs.add(job); } - env.exit_status = state.try_into().unwrap(); + env.exit_status = env.system.exit_status_for_process_state(state).unwrap(); Continue(()) } Err(errno) => { diff --git a/yash-semantics/src/command/simple_command/absent.rs b/yash-semantics/src/command/simple_command/absent.rs index fcc18062..0a0b2cca 100644 --- a/yash-semantics/src/command/simple_command/absent.rs +++ b/yash-semantics/src/command/simple_command/absent.rs @@ -32,6 +32,7 @@ use yash_env::semantics::ExitStatus; use yash_env::semantics::Result; use yash_env::subshell::JobControl; use yash_env::subshell::Subshell; +use yash_env::system::SystemEx as _; use yash_env::Env; use yash_syntax::syntax::Assign; use yash_syntax::syntax::Redir; @@ -81,7 +82,7 @@ pub async fn execute_absent_target( env.jobs.add(job); } - state.try_into().unwrap() + env.system.exit_status_for_process_state(state).unwrap() } Err(errno) => { print_error( diff --git a/yash-semantics/src/command/simple_command/external.rs b/yash-semantics/src/command/simple_command/external.rs index a0fcf4b8..5f3ee022 100644 --- a/yash-semantics/src/command/simple_command/external.rs +++ b/yash-semantics/src/command/simple_command/external.rs @@ -34,6 +34,7 @@ use yash_env::semantics::Result; use yash_env::subshell::JobControl; use yash_env::subshell::Subshell; use yash_env::system::Errno; +use yash_env::system::SystemEx as _; use yash_env::variable::Context; use yash_env::Env; use yash_env::System; @@ -120,7 +121,7 @@ pub async fn start_external_utility_in_subshell_and_wait( env.jobs.add(job); } - state.try_into().unwrap() + env.system.exit_status_for_process_state(state).unwrap() } Err(errno) => { print_error(