Skip to content

Commit

Permalink
Use inherit_stdio()
Browse files Browse the repository at this point in the history
Signed-off-by: jiaxiao zhou <[email protected]>
  • Loading branch information
Mossaka committed Jun 29, 2023
1 parent 7ca42a1 commit 8d5c858
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions crates/containerd-shim-wasmtime/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{fs::OpenOptions, os::fd::RawFd, path::PathBuf};
use nix::unistd::{dup, dup2};
use std::{fs::OpenOptions, os::fd::RawFd};

use anyhow::{anyhow, Result};
use containerd_shim_wasm::sandbox::oci;
Expand All @@ -10,7 +10,7 @@ use oci_spec::runtime::Spec;
use wasmtime::{Engine, Linker, Module, Store};
use wasmtime_wasi::WasiCtxBuilder;

use crate::oci_wasmtime::{self, wasi_dir, wasi_file};
use crate::oci_wasmtime::{self, wasi_dir};

const EXECUTOR_NAME: &str = "wasmtime";

Expand Down Expand Up @@ -59,37 +59,24 @@ impl WasmtimeExecutor {
log::info!("setting up wasi");

let path = wasi_dir(".", OpenOptions::new().read(true))?;
let mut wasi_builder = WasiCtxBuilder::new()
let wasi_builder = WasiCtxBuilder::new()
.args(args)?
.envs(env.as_slice())?
.inherit_stdio()
.preopened_dir(path, "/")?;

// if let Some(stdin) = self.stdin {
// let _ = dup(STDIN_FILENO);
// let _ = dup2(stdin, STDIN_FILENO);
// }
// if let Some(stdout) = self.stdout {
// let _ = dup(STDOUT_FILENO);
// let _ = dup2(stdout, STDOUT_FILENO);
// }
// if let Some(stderr) = self.stderr {
// let _ = dup(STDERR_FILENO);
// let _ = dup2(stderr, STDERR_FILENO);
// }
// log::info!("opening stdin");
// let stdin_path = PathBuf::from("/dev/stdin");
// let stdin_wasi_file = wasi_file(stdin_path, OpenOptions::new().read(true))?;
// wasi_builder = wasi_builder.stdin(Box::new(stdin_wasi_file));

// log::info!("opening stdout");
// let stdout_path = PathBuf::from("/dev/stdout");
// let stdout_wasi_file = wasi_file(stdout_path, OpenOptions::new().write(true))?;
// wasi_builder = wasi_builder.stdout(Box::new(stdout_wasi_file));

// log::info!("opening stderr");
// let stderr_path = PathBuf::from("/dev/stderr");
// let stderr_wasi_file = wasi_file(stderr_path, OpenOptions::new().write(true))?;
// wasi_builder = wasi_builder.stderr(Box::new(stderr_wasi_file));
if let Some(stdin) = self.stdin {
let _ = dup(STDIN_FILENO);
let _ = dup2(stdin, STDIN_FILENO);
}
if let Some(stdout) = self.stdout {
let _ = dup(STDOUT_FILENO);
let _ = dup2(stdout, STDOUT_FILENO);
}
if let Some(stderr) = self.stderr {
let _ = dup(STDERR_FILENO);
let _ = dup2(stderr, STDERR_FILENO);
}

log::info!("building wasi context");
let wctx = wasi_builder.build();
Expand Down

0 comments on commit 8d5c858

Please sign in to comment.