Merge branch 'open-log' into 'master'
Parse flags when logging openat See merge request redox-os/relibc!1523
This commit is contained in:
@@ -115,6 +115,19 @@ macro_rules! trace_expr {
|
||||
});
|
||||
}
|
||||
|
||||
// log::trace! but functions inside them will
|
||||
// not be evaluated or compiled unless enabled
|
||||
macro_rules! trace_log {
|
||||
($($arg:tt)+) => {
|
||||
#[cfg(not(feature = "no_trace"))]
|
||||
{
|
||||
if log::log_enabled!(log::Level::Trace) {
|
||||
log::trace!($($arg)+);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! skipws {
|
||||
($ptr:expr) => {
|
||||
|
||||
@@ -227,13 +227,15 @@ impl RedoxLogger {
|
||||
self
|
||||
}
|
||||
pub fn enable(self) -> Result<&'static Self, log::SetLoggerError> {
|
||||
let leak = Box::leak(Box::new(self));
|
||||
log::set_logger(leak)?;
|
||||
if let Some(max) = leak.max_level_in_use {
|
||||
log::set_max_level(max);
|
||||
} else {
|
||||
log::set_max_level(DEFAULT_LOG_LEVEL);
|
||||
let mut this = self;
|
||||
if this.max_level_in_use.is_none() {
|
||||
// to fix log::log_enabled! macro if
|
||||
// DEFAULT_LOG_LEVEL changed to TRACE
|
||||
this = this.with_max_level_override(DEFAULT_LOG_LEVEL);
|
||||
}
|
||||
let leak = Box::leak(Box::new(this));
|
||||
log::set_logger(leak)?;
|
||||
log::set_max_level(leak.max_level_in_use.unwrap());
|
||||
Ok(leak)
|
||||
}
|
||||
fn write_record<W: fmt::Write + ?Sized>(
|
||||
|
||||
@@ -221,9 +221,10 @@ pub fn openat(dirfd: c_int, path: RedoxStr<'_>, flags: usize) -> Result<usize> {
|
||||
redox_rt::sys::openat(dirfd as usize, &path, flags, fcntl_flags)
|
||||
};
|
||||
|
||||
log::trace!(
|
||||
"openat({dirfd:?}, {:?}, {flags:x}): {:?}",
|
||||
trace_log!(
|
||||
"openat({dirfd:?}, {:?}, {}): {:?}",
|
||||
&path,
|
||||
decode_open_flags(flags),
|
||||
initial_res
|
||||
);
|
||||
|
||||
@@ -268,7 +269,12 @@ pub fn open(path: RedoxStr<'_>, flags: usize) -> Result<usize> {
|
||||
open_absolute(&path, flags)
|
||||
};
|
||||
|
||||
log::trace!("open({:?}, {flags:x}): {:?}", &path, initial_res);
|
||||
trace_log!(
|
||||
"open({:?}, {}): {:?}",
|
||||
&path,
|
||||
decode_open_flags(flags),
|
||||
initial_res
|
||||
);
|
||||
|
||||
match initial_res {
|
||||
Ok(fd) => Ok(fd),
|
||||
@@ -400,3 +406,60 @@ pub(super) fn openat2(
|
||||
let oflags = at_flags_to_open_flags(at_flags) | fcntl::O_CLOEXEC | oflags;
|
||||
File::openat(dirfd, path, oflags)
|
||||
}
|
||||
|
||||
#[cfg(any(debug_assertions, not(feature = "no_trace")))]
|
||||
pub fn decode_open_flags(mut value: usize) -> alloc::string::String {
|
||||
let flags = [
|
||||
("O_NONBLOCK", O_NONBLOCK),
|
||||
("O_APPEND", O_APPEND),
|
||||
("O_SHLOCK", O_SHLOCK),
|
||||
("O_EXLOCK", O_EXLOCK),
|
||||
("O_ASYNC", O_ASYNC),
|
||||
("O_FSYNC", O_FSYNC),
|
||||
("O_CLOEXEC", O_CLOEXEC),
|
||||
("O_CREAT", O_CREAT),
|
||||
("O_TRUNC", O_TRUNC),
|
||||
("O_EXCL", O_EXCL),
|
||||
("O_DIRECTORY", O_DIRECTORY),
|
||||
("O_STAT", O_STAT),
|
||||
("O_SYMLINK", O_SYMLINK),
|
||||
("O_NOFOLLOW", O_NOFOLLOW),
|
||||
];
|
||||
|
||||
let mut result = alloc::string::String::new();
|
||||
|
||||
let accmode = value & O_ACCMODE;
|
||||
match accmode {
|
||||
O_RDONLY => result.push_str("O_RDONLY"),
|
||||
O_WRONLY => result.push_str("O_WRONLY"),
|
||||
O_RDWR => result.push_str("O_RDWR"),
|
||||
_ => {}
|
||||
}
|
||||
value &= !O_ACCMODE;
|
||||
for (name, flag) in flags.iter() {
|
||||
if (value & flag) == *flag {
|
||||
if !result.is_empty() {
|
||||
result.push_str(" | ");
|
||||
}
|
||||
result.push_str(name);
|
||||
value &= !flag;
|
||||
}
|
||||
}
|
||||
|
||||
const PERM: usize = MODE_PERM as usize;
|
||||
if (value & PERM) != 0 {
|
||||
if !result.is_empty() {
|
||||
result.push_str(" | ");
|
||||
}
|
||||
result.push_str(&format!("0o{:o}", value & PERM));
|
||||
}
|
||||
value &= !PERM;
|
||||
if value != 0 {
|
||||
if !result.is_empty() {
|
||||
result.push_str(" | ");
|
||||
}
|
||||
result.push_str(&format!("0x{:x}", value));
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user