wasi-common: don't rely on platform dependent "NUL" device
If stdio is not inherited nor associated with a file, WasiCtxBuilder
tries to open "/dev/null" ("NUL" on Windows) and attach stdio to it.
While most platforms today support those device files, it would be
good to avoid unnecessary access to the host device if possible. This
patch instead uses a virtual Handle that emulates the "NUL" device.
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
use super::oshandle::RawOsHandle;
|
||||
use super::{get_file_type, get_rights};
|
||||
use crate::handle::Handle;
|
||||
use crate::sys::osother::{OsOther, OsOtherExt};
|
||||
use crate::sys::osother::OsOther;
|
||||
use crate::wasi::types;
|
||||
use std::convert::TryFrom;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::os::unix::prelude::{FromRawFd, IntoRawFd};
|
||||
|
||||
@@ -21,14 +20,3 @@ impl TryFrom<File> for OsOther {
|
||||
Ok(Self::new(file_type, rights, handle))
|
||||
}
|
||||
}
|
||||
|
||||
impl OsOtherExt for OsOther {
|
||||
fn from_null() -> io::Result<Box<dyn Handle>> {
|
||||
let file = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open("/dev/null")?;
|
||||
let file = Self::try_from(file)?;
|
||||
Ok(Box::new(file))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user