From 5bce7483b9f498bee22dfd083f5caf3fd4d6e1fe Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Thu, 15 Jun 2023 20:26:42 +0000 Subject: [PATCH] Fix for args Signed-off-by: James Sturtevant --- crates/containerd-shim-wasmedge/src/executor.rs | 15 +++++++++++---- crates/wasi-demo-app/src/main.rs | 5 ++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/containerd-shim-wasmedge/src/executor.rs b/crates/containerd-shim-wasmedge/src/executor.rs index fbfd06b34..ce38d62f8 100644 --- a/crates/containerd-shim-wasmedge/src/executor.rs +++ b/crates/containerd-shim-wasmedge/src/executor.rs @@ -5,8 +5,8 @@ use oci_spec::runtime::Spec; use libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO}; use libcontainer::workload::{Executor, ExecutorError}; +use log::debug; use std::os::unix::io::RawFd; - use wasmedge_sdk::{ config::{CommonConfigOptions, ConfigBuilder, HostRegistrationConfigOptions}, params, VmBuilder, @@ -42,9 +42,15 @@ impl Executor for WasmEdgeExecutor { .ok_or_else(|| anyhow::Error::msg("Not found wasi module")) .map_err(|err| ExecutorError::Execution(err.into()))?; - let module_args = oci::get_module_args(spec); + let args = oci::get_module_args(spec); + let mut module_args = None; + if !args.is_empty() { + module_args = Some(args.iter().map(|s| s as &str).collect()) + } + + debug!("module args: {:?}", module_args); wasi_module.initialize( - Some(module_args.iter().map(|s| s as &str).collect()), + module_args, Some(envs.iter().map(|s| s as &str).collect()), None, ); @@ -63,7 +69,7 @@ impl Executor for WasmEdgeExecutor { }; let vm = vm - .register_module_from_file("main", module_name) + .register_module_from_file("main", module_name.clone()) .map_err(|err| ExecutorError::Execution(err))?; if let Some(stdin) = self.stdin { @@ -79,6 +85,7 @@ impl Executor for WasmEdgeExecutor { let _ = dup2(stderr, STDERR_FILENO); } + debug!("running {:?} with method {}", module_name, method); match vm.run_func(Some("main"), method, params!()) { Ok(_) => std::process::exit(0), Err(_) => std::process::exit(137), diff --git a/crates/wasi-demo-app/src/main.rs b/crates/wasi-demo-app/src/main.rs index 36c5e2730..a7cff38ff 100644 --- a/crates/wasi-demo-app/src/main.rs +++ b/crates/wasi-demo-app/src/main.rs @@ -4,7 +4,10 @@ fn main() { let args: Vec<_> = env::args().collect(); let mut cmd = "daemon"; if !args.is_empty() { - cmd = &args[0]; + // temporary work around for wasmedge bug + if !(args.len() == 1 && args[0].is_empty()) { + cmd = &args[0]; + } } match cmd {