From b7ca81a7f828e164b514f8890f8bbcc9460a8cf5 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Fri, 27 Oct 2023 22:07:14 +0800 Subject: [PATCH] Fixed the bug in spawn_exec() where non-zero exit codes aren't propagated properly --- lib/wasix/src/bin_factory/exec.rs | 16 ++++++++-------- lib/wasix/src/runners/wasi.rs | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/wasix/src/bin_factory/exec.rs b/lib/wasix/src/bin_factory/exec.rs index fd16db0f781..035b1b73dd5 100644 --- a/lib/wasix/src/bin_factory/exec.rs +++ b/lib/wasix/src/bin_factory/exec.rs @@ -203,13 +203,8 @@ fn call_module( if let Err(err) = call_ret { match err.downcast::() { - Ok(WasiError::Exit(code)) => { - if code.is_success() { - Ok(Errno::Success) - } else { - Ok(Errno::Noexec) - } - } + Ok(WasiError::Exit(code)) if code.is_success() => Ok(Errno::Success), + Ok(err @ WasiError::Exit(_)) => Err(err.into()), Ok(WasiError::DeepSleep(deep)) => { // Create the callback that will be invoked when the thread respawns after a deep sleep let rewind = deep.rewind; @@ -222,7 +217,12 @@ fn call_module( // Spawns the WASM process after a trigger if let Err(err) = unsafe { - tasks.resume_wasm_after_poller(Box::new(respawn), ctx, store, deep.trigger) + tasks.resume_wasm_after_poller( + Box::new(respawn), + ctx, + store, + deep.trigger, + ) } { debug!("failed to go into deep sleep - {}", err); } diff --git a/lib/wasix/src/runners/wasi.rs b/lib/wasix/src/runners/wasi.rs index 618ac90cf74..b2c2292805b 100644 --- a/lib/wasix/src/runners/wasi.rs +++ b/lib/wasix/src/runners/wasi.rs @@ -244,8 +244,10 @@ impl crate::runners::Runner for WasiRunner { let exit_code = tasks.spawn_and_block_on( async move { - let fut = crate::bin_factory::spawn_exec(pkg, &command_name, store, env, &runtime); - let mut task_handle = fut.await.context("Spawn failed")?; + let mut task_handle = + crate::bin_factory::spawn_exec(pkg, &command_name, store, env, &runtime) + .await + .context("Spawn failed")?; task_handle .wait_finished()