Updates for the review comments

This commit is contained in:
Johnathan Sharratt
2023-03-09 16:11:42 +11:00
parent 1c85b34031
commit 80b10fcba7
3 changed files with 20 additions and 22 deletions

View File

@@ -7,6 +7,8 @@ use std::{collections::BTreeSet, path::Path};
use wasmer::{AsStoreMut, Instance, Module, RuntimeError, Value}; use wasmer::{AsStoreMut, Instance, Module, RuntimeError, Value};
use wasmer_vfs::FileSystem; use wasmer_vfs::FileSystem;
use wasmer_vfs::{DeviceFile, PassthruFileSystem, RootFileSystemBuilder}; use wasmer_vfs::{DeviceFile, PassthruFileSystem, RootFileSystemBuilder};
use wasmer_wasi::os::tty_sys::SysTyy;
use wasmer_wasi::os::TtyBridge;
use wasmer_wasi::types::__WASI_STDIN_FILENO; use wasmer_wasi::types::__WASI_STDIN_FILENO;
use wasmer_wasi::{ use wasmer_wasi::{
default_fs_backing, get_wasi_versions, PluggableRuntimeImplementation, WasiEnv, WasiError, default_fs_backing, get_wasi_versions, PluggableRuntimeImplementation, WasiEnv, WasiError,
@@ -60,6 +62,10 @@ pub struct Wasi {
#[clap(long = "net")] #[clap(long = "net")]
pub networking: bool, pub networking: bool,
/// Disables the TTY bridge
#[clap(long = "no-tty")]
pub no_tty: bool,
/// Allow instances to send http requests. /// Allow instances to send http requests.
/// ///
/// Access to domains is granted by default. /// Access to domains is granted by default.
@@ -128,6 +134,12 @@ impl Wasi {
rt.set_networking_implementation(wasmer_vnet::UnsupportedVirtualNetworking::default()); rt.set_networking_implementation(wasmer_vnet::UnsupportedVirtualNetworking::default());
} }
if self.no_tty == false {
let tty = Arc::new(SysTyy::default());
tty.reset();
rt.set_tty(tty)
}
let engine = store.as_store_mut().engine().clone(); let engine = store.as_store_mut().engine().clone();
rt.set_engine(Some(engine)); rt.set_engine(Some(engine));

View File

@@ -2763,10 +2763,7 @@ unsafe impl wasmer::FromToNativeWasmType for Errno {
78 => Self::Memviolation, 78 => Self::Memviolation,
79 => Self::Unknown, 79 => Self::Unknown,
q => { _ => Self::Unknown,
tracing::debug!("could not serialize number {q} to enum Errno");
Self::Unknown
}
} }
} }
@@ -3758,10 +3755,7 @@ unsafe impl wasmer::FromToNativeWasmType for Signal {
30 => Self::Sigpwr, 30 => Self::Sigpwr,
31 => Self::Sigsys, 31 => Self::Sigsys,
q => { _ => Self::Sigunknown,
tracing::warn!("could not serialize number {q} to enum Signal");
Self::Sigunknown
}
} }
} }

View File

@@ -54,7 +54,7 @@ where
} }
/// Get access to the TTY used by the environment. /// Get access to the TTY used by the environment.
fn tty(&self) -> Option<&dyn TtyBridge> { fn tty(&self) -> Option<&(dyn TtyBridge + Send + Sync)> {
None None
} }
} }
@@ -92,7 +92,7 @@ pub struct PluggableRuntimeImplementation {
#[cfg(feature = "sys")] #[cfg(feature = "sys")]
pub engine: Option<wasmer::Engine>, pub engine: Option<wasmer::Engine>,
#[derivative(Debug = "ignore")] #[derivative(Debug = "ignore")]
pub tty: Arc<dyn TtyBridge + Send + Sync>, pub tty: Option<Arc<dyn TtyBridge + Send + Sync>>,
} }
impl PluggableRuntimeImplementation { impl PluggableRuntimeImplementation {
@@ -109,7 +109,7 @@ impl PluggableRuntimeImplementation {
} }
pub fn set_tty(&mut self, tty: Arc<dyn TtyBridge + Send + Sync>) { pub fn set_tty(&mut self, tty: Arc<dyn TtyBridge + Send + Sync>) {
self.tty = tty; self.tty = Some(tty);
} }
pub fn new(rt: Arc<dyn VirtualTaskManager>) -> Self { pub fn new(rt: Arc<dyn VirtualTaskManager>) -> Self {
@@ -130,14 +130,6 @@ impl PluggableRuntimeImplementation {
let http_client = None; let http_client = None;
} }
} }
cfg_if::cfg_if! {
if #[cfg(all(feature = "host-termios", unix))] {
let tty = Arc::new(crate::os::tty_sys::SysTyy::default());
tty.reset();
} else {
let tty = Arc::new(DefaultTty::default());
}
}
Self { Self {
rt, rt,
@@ -145,7 +137,7 @@ impl PluggableRuntimeImplementation {
http_client, http_client,
#[cfg(feature = "sys")] #[cfg(feature = "sys")]
engine: None, engine: None,
tty, tty: None,
} }
} }
} }
@@ -184,7 +176,7 @@ impl WasiRuntime for PluggableRuntimeImplementation {
&self.rt &self.rt
} }
fn tty(&self) -> Option<&dyn TtyBridge> { fn tty(&self) -> Option<&(dyn TtyBridge + Send + Sync)> {
Some(self.tty.as_ref()) self.tty.as_deref()
} }
} }