Skip to content
This repository was archived by the owner on Oct 26, 2021. It is now read-only.

Commit ea202c6

Browse files
committed
wasmldr: read module from fd 3 if no path given
This commit makes wasmldr try to read the wasm module from fd3 if no file path was given. (Since keepldr doesn't currently pass arguments to wasmldr, this will be the default behavior.) This means you should be able to run a .wasm module in a keep by doing: cargo run -- exec 3< hello.wasm This behavior will likely change soon, but hey.. Hello World! Signed-off-by: Will Woods <[email protected]>
1 parent a77654e commit ea202c6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

internal/wasmldr/src/cli.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub struct RunOptions {
2424
// TODO: --inherit-env
2525
// TODO: --stdin, --stdout, --stderr
2626
/// Path of the WebAssembly module to run
27-
#[structopt(index = 1, required = true, value_name = "MODULE", parse(from_os_str))]
28-
pub module: PathBuf,
27+
#[structopt(index = 1, value_name = "MODULE", parse(from_os_str))]
28+
pub module: Option<PathBuf>,
2929

3030
// NOTE: this has to come last for TrailingVarArg
3131
/// Arguments to pass to the WebAssembly module

internal/wasmldr/src/main.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use structopt::StructOpt;
3636

3737
use std::fs::File;
3838
use std::io::Read;
39+
use std::os::unix::io::{FromRawFd, RawFd};
3940

4041
fn main() {
4142
// Initialize the logger, taking settings from the default env vars
@@ -47,9 +48,13 @@ fn main() {
4748
let opts = cli::RunOptions::from_args();
4849
info!("opts: {:#?}", opts);
4950

50-
info!("reading {:?}", opts.module);
51-
// TODO: don't just panic here...
52-
let mut reader = File::open(&opts.module).expect("Unable to open file");
51+
let mut reader = if let Some(module) = opts.module {
52+
info!("reading module from {:?}", &module);
53+
File::open(&module).expect("Unable to open file")
54+
} else {
55+
info!("reading module from fd 3");
56+
unsafe { File::from_raw_fd(RawFd::from(3)) }
57+
};
5358

5459
let mut bytes = Vec::new();
5560
reader

0 commit comments

Comments
 (0)