DIAG(execve): trace exec::execve (real fork+exec path, not posix_spawn) - log exe open + interp(ld.so) open, the two ENOENT-masking points

This commit is contained in:
Red Bear OS
2026-07-18 20:45:18 +09:00
parent e64c914319
commit 20d4e8746f
+23 -1
View File
@@ -77,13 +77,25 @@ pub fn execve(
arg_env: ArgEnv,
interp_override: Option<InterpOverride>,
) -> Result<Infallible> {
let dbg = |m: &str| {
let _ = syscall::write(2, m.as_bytes());
};
dbg("EXECVE-DIAG: enter\n");
// NOTE: We must omit O_CLOEXEC and close manually, otherwise it will be closed before we
// have even read it!
let (mut image_file, stat, arg0) = match exec {
Executable::AtPath(path) => {
{
let mut b = alloc::string::String::from("EXECVE-DIAG: opening exe '");
b.push_str(core::str::from_utf8(path.to_bytes()).unwrap_or("<utf8?>"));
b.push_str("'\n");
dbg(&b);
}
let Ok(src_fd) = File::open(path, O_RDONLY as c_int) else {
dbg("EXECVE-DIAG: exe File::open FAILED -> ENOENT\n");
return Err(Error::new(ENOENT));
};
dbg("EXECVE-DIAG: exe opened ok\n");
let mut src_stat = Stat::default();
redox_rt::sys::fstat(*src_fd as usize, &mut src_stat)?;
@@ -166,8 +178,18 @@ pub fn execve(
let mut args: Vec<&[u8]> = Vec::with_capacity(len);
if let Some(interpreter) = &interpreter_path {
{
let mut b = alloc::string::String::from("EXECVE-DIAG: needs interp '");
b.push_str(core::str::from_utf8(interpreter.as_bytes()).unwrap_or("<utf8?>"));
b.push_str("'\n");
dbg(&b);
}
image_file = File::open(CStr::borrow(&interpreter), O_RDONLY as c_int)
.map_err(|_| Error::new(ENOENT))?;
.map_err(|_| {
dbg("EXECVE-DIAG: interp File::open FAILED -> ENOENT\n");
Error::new(ENOENT)
})?;
dbg("EXECVE-DIAG: interp opened ok\n");
// Push interpreter to arguments
args.push(interpreter.as_bytes());