wasi-common: switch all logs from log to tracing
tracing is already the dep that wiggle uses. I used tracing structured arguments wherever I could, but I skipped over it in all of the snapshot_0 code, because I'm going to delete that code and replace it with wiggle-based stuff real soon.
This commit is contained in:
@@ -55,7 +55,7 @@ impl AsFile for dyn Handle + 'static {
|
||||
} else if let Some(other) = self.as_any().downcast_ref::<OsOther>() {
|
||||
other.as_file()
|
||||
} else {
|
||||
log::error!("tried to make std::fs::File from non-OS handle");
|
||||
tracing::error!("tried to make std::fs::File from non-OS handle");
|
||||
Err(io::Error::from_raw_os_error(libc::EBADF))
|
||||
}
|
||||
}
|
||||
@@ -69,17 +69,26 @@ impl TryFrom<File> for Box<dyn Handle> {
|
||||
match file_type {
|
||||
types::Filetype::RegularFile => {
|
||||
let handle = OsFile::try_from(file)?;
|
||||
log::debug!("Created new instance of OsFile: {:?}", handle);
|
||||
tracing::debug!(
|
||||
handle = tracing::field::debug(&handle),
|
||||
"Created new instance of OsFile"
|
||||
);
|
||||
Ok(Box::new(handle))
|
||||
}
|
||||
types::Filetype::Directory => {
|
||||
let handle = OsDir::try_from(file)?;
|
||||
log::debug!("Created new instance of OsDir: {:?}", handle);
|
||||
tracing::debug!(
|
||||
handle = tracing::field::debug(&handle),
|
||||
"Created new instance of OsDir"
|
||||
);
|
||||
Ok(Box::new(handle))
|
||||
}
|
||||
_ => {
|
||||
let handle = OsOther::try_from(file)?;
|
||||
log::debug!("Created new instance of OsOther: {:?}", handle);
|
||||
tracing::debug!(
|
||||
handle = tracing::field::debug(&handle),
|
||||
"Created new instance of OsOther"
|
||||
);
|
||||
Ok(Box::new(handle))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ use super::sys_impl::oshandle::RawOsHandle;
|
||||
use super::{fd, path, AsFile};
|
||||
use crate::handle::{Handle, HandleRights};
|
||||
use crate::wasi::{types, Errno, Result};
|
||||
use log::{debug, error};
|
||||
use std::any::Any;
|
||||
use std::io;
|
||||
use std::ops::Deref;
|
||||
use tracing::{debug, error};
|
||||
|
||||
// TODO could this be cleaned up?
|
||||
// The actual `OsDir` struct is OS-dependent, therefore we delegate
|
||||
|
||||
@@ -59,10 +59,10 @@ pub(crate) fn readdir<'a>(
|
||||
// Seek if needed. Unless cookie is wasi::__WASI_DIRCOOKIE_START,
|
||||
// new items may not be returned to the caller.
|
||||
if cookie == wasi::DIRCOOKIE_START {
|
||||
log::trace!(" | fd_readdir: doing rewinddir");
|
||||
tracing::trace!("fd_readdir: doing rewinddir");
|
||||
dir.rewind();
|
||||
} else {
|
||||
log::trace!(" | fd_readdir: doing seekdir to {}", cookie);
|
||||
tracing::trace!("fd_readdir: doing seekdir to {}", cookie);
|
||||
let loc = unsafe { SeekLoc::from_raw(cookie as i64)? };
|
||||
dir.seek(loc);
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ pub(crate) fn unlink_file(dirfd: &OsDir, path: &str) -> Result<()> {
|
||||
pub(crate) fn symlink(old_path: &str, new_dirfd: &OsDir, new_path: &str) -> Result<()> {
|
||||
use yanix::file::symlinkat;
|
||||
|
||||
log::debug!("path_symlink old_path = {:?}", old_path);
|
||||
log::debug!(
|
||||
"path_symlink (new_dirfd, new_path) = ({:?}, {:?})",
|
||||
new_dirfd,
|
||||
new_path
|
||||
tracing::debug!(
|
||||
old_path = old_path,
|
||||
new_dirfd = tracing::field::debug(new_dirfd),
|
||||
new_path = new_path,
|
||||
"path symlink"
|
||||
);
|
||||
|
||||
unsafe { symlinkat(old_path, new_dirfd.as_raw_fd(), new_path)? };
|
||||
|
||||
@@ -50,19 +50,19 @@ impl<T: AsRawFd> AsFile for T {
|
||||
pub(super) fn get_file_type(file: &File) -> io::Result<types::Filetype> {
|
||||
let ft = file.metadata()?.file_type();
|
||||
let file_type = if ft.is_block_device() {
|
||||
log::debug!("Host fd {:?} is a block device", file.as_raw_fd());
|
||||
tracing::debug!("Host fd {:?} is a block device", file.as_raw_fd());
|
||||
types::Filetype::BlockDevice
|
||||
} else if ft.is_char_device() {
|
||||
log::debug!("Host fd {:?} is a char device", file.as_raw_fd());
|
||||
tracing::debug!("Host fd {:?} is a char device", file.as_raw_fd());
|
||||
types::Filetype::CharacterDevice
|
||||
} else if ft.is_dir() {
|
||||
log::debug!("Host fd {:?} is a directory", file.as_raw_fd());
|
||||
tracing::debug!("Host fd {:?} is a directory", file.as_raw_fd());
|
||||
types::Filetype::Directory
|
||||
} else if ft.is_file() {
|
||||
log::debug!("Host fd {:?} is a file", file.as_raw_fd());
|
||||
tracing::debug!("Host fd {:?} is a file", file.as_raw_fd());
|
||||
types::Filetype::RegularFile
|
||||
} else if ft.is_socket() {
|
||||
log::debug!("Host fd {:?} is a socket", file.as_raw_fd());
|
||||
tracing::debug!("Host fd {:?} is a socket", file.as_raw_fd());
|
||||
use yanix::socket::{get_socket_type, SockType};
|
||||
match unsafe { get_socket_type(file.as_raw_fd())? } {
|
||||
SockType::Datagram => types::Filetype::SocketDgram,
|
||||
@@ -70,10 +70,10 @@ pub(super) fn get_file_type(file: &File) -> io::Result<types::Filetype> {
|
||||
_ => return Err(io::Error::from_raw_os_error(libc::EINVAL)),
|
||||
}
|
||||
} else if ft.is_fifo() {
|
||||
log::debug!("Host fd {:?} is a fifo", file.as_raw_fd());
|
||||
tracing::debug!("Host fd {:?} is a fifo", file.as_raw_fd());
|
||||
types::Filetype::Unknown
|
||||
} else {
|
||||
log::debug!("Host fd {:?} is unknown", file.as_raw_fd());
|
||||
tracing::debug!("Host fd {:?} is unknown", file.as_raw_fd());
|
||||
return Err(io::Error::from_raw_os_error(libc::EINVAL));
|
||||
};
|
||||
Ok(file_type)
|
||||
@@ -221,12 +221,12 @@ impl From<io::Error> for Errno {
|
||||
libc::ENOTRECOVERABLE => Self::Notrecoverable,
|
||||
libc::ENOTSUP => Self::Notsup,
|
||||
x => {
|
||||
log::debug!("Unknown errno value: {}", x);
|
||||
tracing::debug!("Unknown errno value: {}", x);
|
||||
Self::Io
|
||||
}
|
||||
},
|
||||
None => {
|
||||
log::debug!("Other I/O error: {}", err);
|
||||
tracing::debug!("Other I/O error: {}", err);
|
||||
Self::Io
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ pub(crate) fn readlinkat(dirfd: &OsDir, path: &str) -> Result<String> {
|
||||
use std::os::unix::prelude::AsRawFd;
|
||||
use yanix::file::readlinkat;
|
||||
|
||||
log::debug!("path_get readlinkat path = {:?}", path);
|
||||
tracing::debug!(path = path, "path_get readlinkat");
|
||||
|
||||
let path = unsafe { readlinkat(dirfd.as_raw_fd(), path)? };
|
||||
let path = from_host(path)?;
|
||||
@@ -123,9 +123,12 @@ pub(crate) fn open(
|
||||
// umask is, but don't set the executable flag, because it isn't yet
|
||||
// meaningful for WASI programs to create executable files.
|
||||
|
||||
log::debug!("path_open dirfd = {:?}", dirfd);
|
||||
log::debug!("path_open path = {:?}", path);
|
||||
log::debug!("path_open oflags = {:?}", nix_all_oflags);
|
||||
tracing::debug!(
|
||||
dirfd = tracing::field::debug(dirfd),
|
||||
path = tracing::field::debug(path),
|
||||
oflags = tracing::field::debug(nix_all_oflags),
|
||||
"path_open"
|
||||
);
|
||||
|
||||
let fd_no = unsafe {
|
||||
openat(
|
||||
@@ -148,7 +151,10 @@ pub(crate) fn open(
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
log::debug!("path_open fstatat error: {:?}", err);
|
||||
tracing::debug!(
|
||||
error = tracing::field::debug(&err),
|
||||
"path_open fstatat error",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,7 +170,10 @@ pub(crate) fn open(
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
log::debug!("path_open fstatat error: {:?}", err);
|
||||
tracing::debug!(
|
||||
error = tracing::field::debug(&err),
|
||||
"path_open fstatat error",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,7 +189,7 @@ pub(crate) fn open(
|
||||
}
|
||||
};
|
||||
|
||||
log::debug!("path_open (host) new_fd = {:?}", new_fd);
|
||||
tracing::debug!(new_fd = tracing::field::debug(new_fd));
|
||||
|
||||
// Determine the type of the new file descriptor and which rights contradict with this type
|
||||
let file = unsafe { File::from_raw_fd(new_fd) };
|
||||
|
||||
@@ -38,7 +38,7 @@ pub(crate) fn oneoff(
|
||||
let delay = timeout.delay / 1_000_000; // poll syscall requires delay to expressed in milliseconds
|
||||
delay.try_into().unwrap_or(libc::c_int::max_value())
|
||||
});
|
||||
log::debug!("poll_oneoff poll_timeout = {:?}", poll_timeout);
|
||||
tracing::debug!("poll_oneoff poll_timeout = {:?}", poll_timeout);
|
||||
|
||||
let ready = loop {
|
||||
match poll(&mut poll_fds, poll_timeout) {
|
||||
@@ -91,15 +91,14 @@ fn handle_fd_event(
|
||||
}
|
||||
|
||||
for (fd_event, poll_fd) in ready_events {
|
||||
// log::debug!("poll_oneoff_handle_fd_event fd_event = {:?}", fd_event);
|
||||
log::debug!("poll_oneoff_handle_fd_event poll_fd = {:?}", poll_fd);
|
||||
tracing::debug!("poll_oneoff_handle_fd_event poll_fd = {:?}", poll_fd);
|
||||
|
||||
let revents = match poll_fd.revents() {
|
||||
Some(revents) => revents,
|
||||
None => continue,
|
||||
};
|
||||
|
||||
log::debug!("poll_oneoff_handle_fd_event revents = {:?}", revents);
|
||||
tracing::debug!("poll_oneoff_handle_fd_event revents = {:?}", revents);
|
||||
|
||||
let nbytes = if fd_event.r#type == types::Eventtype::FdRead {
|
||||
query_nbytes(fd_event.handle)?
|
||||
|
||||
Reference in New Issue
Block a user