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

Commit

Permalink
wasmldr: read module from fd 3 if no path given
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
wgwoods committed Oct 4, 2021
1 parent 0a9861a commit 175c6dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/wasmldr/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub struct RunOptions {
// TODO: --inherit-env
// TODO: --stdin, --stdout, --stderr
/// Path of the WebAssembly module to run
#[structopt(index = 1, required = true, value_name = "MODULE", parse(from_os_str))]
pub module: PathBuf,
#[structopt(index = 1, value_name = "MODULE", parse(from_os_str))]
pub module: Option<PathBuf>,

// NOTE: this has to come last for TrailingVarArg
/// Arguments to pass to the WebAssembly module
Expand Down
11 changes: 8 additions & 3 deletions internal/wasmldr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use structopt::StructOpt;

use std::fs::File;
use std::io::Read;
use std::os::unix::io::{FromRawFd, RawFd};

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

info!("reading {:?}", opts.module);
// TODO: don't just panic here...
let mut reader = File::open(&opts.module).expect("Unable to open file");
let mut reader = if let Some(module) = opts.module {
info!("reading module from {:?}", &module);
File::open(&module).expect("Unable to open file")
} else {
info!("reading module from fd 3");
unsafe { File::from_raw_fd(RawFd::from(3)) }
};

let mut bytes = Vec::new();
reader
Expand Down

0 comments on commit 175c6dd

Please sign in to comment.