Skip to content

Commit

Permalink
Fix for args
Browse files Browse the repository at this point in the history
Signed-off-by: James Sturtevant <[email protected]>
  • Loading branch information
jsturtevant committed Jun 15, 2023
1 parent cfc813d commit 5bce748
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 11 additions & 4 deletions crates/containerd-shim-wasmedge/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
);
Expand All @@ -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 {
Expand All @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion crates/wasi-demo-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5bce748

Please sign in to comment.