Remove temporary spawn/execve diagnostics

This commit is contained in:
Red Bear OS
2026-07-18 23:07:56 +09:00
parent 20d4e8746f
commit c6f8a2c208
2 changed files with 2 additions and 57 deletions
+1 -23
View File
@@ -77,25 +77,13 @@ 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)?;
@@ -178,18 +166,8 @@ 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(|_| {
dbg("EXECVE-DIAG: interp File::open FAILED -> ENOENT\n");
Error::new(ENOENT)
})?;
dbg("EXECVE-DIAG: interp opened ok\n");
.map_err(|_| Error::new(ENOENT))?;
// Push interpreter to arguments
args.push(interpreter.as_bytes());
+1 -34
View File
@@ -1264,31 +1264,13 @@ impl Pal for Sys {
envp: Option<NulTerminated<*mut c_char>>,
) -> Result<pid_t> {
use crate::header::spawn::Flags;
let dbg = |m: &str| {
// fd 2 (login's stderr -> pty -> fbcond -> serial) is proven to
// reach the capture; also try the kernel debug scheme directly.
let _ = syscall::write(2, m.as_bytes());
if let Ok(g) = FdGuard::open("/scheme/debug", syscall::O_WRONLY) {
let _ = syscall::write(g.as_raw_fd(), m.as_bytes());
}
};
dbg("SPAWN-DIAG: enter\n");
let child = redox_rt::proc::new_child_process(&redox_rt::proc::ForkArgs::Managed)?;
dbg("SPAWN-DIAG: new_child_process ok\n");
let mut cwd = path::clone_cwd().unwrap_or_default();
{
let mut b = alloc::string::String::from("SPAWN-DIAG: cwd='");
b.push_str(cwd.as_str());
b.push_str("'\n");
dbg(&b);
}
let mut cwd_fd = FdGuard::open(cwd.as_str(), syscall::O_STAT)?.to_upper()?;
dbg("SPAWN-DIAG: cwd_fd opened ok\n");
let proc_fd = child.proc_fd.unwrap();
let curr_proc_fd = redox_rt::current_proc_fd();
let cur_filetable_fd = RtTcb::current().thread_fd().dup_into_upper(b"filetable")?;
let file_table = cur_filetable_fd.dup_into_upper(b"copy")?;
dbg("SPAWN-DIAG: filetable copied ok\n");
{
let new_file_table = child.thr_fd.dup_into_upper(b"current-filetable")?;
@@ -1321,7 +1303,6 @@ impl Pal for Sys {
)?;
}
dbg("SPAWN-DIAG: bootstrap fds installed, processing file_actions\n");
if let Some(fac) = fac {
for action in fac {
match action {
@@ -1394,16 +1375,13 @@ impl Pal for Sys {
FdGuard::open(cwd.as_str(), syscall::O_STAT)?
};
dbg("SPAWN-DIAG: dirfd(cwd) opened, opening executable via openat\n");
let executable = Sys::openat(
dirfd.as_c_fd().ok_or(Errno(EMFILE))?,
program,
fcntl::O_RDONLY,
0,
)?;
dbg("SPAWN-DIAG: executable openat ok\n");
let executable = FdGuard::new(executable as usize).to_upper()?;
dbg("SPAWN-DIAG: executable to_upper ok\n");
let mut executable_stat = syscall::Stat::default();
executable.fstat(&mut executable_stat)?;
drop(dirfd);
@@ -1549,7 +1527,6 @@ impl Pal for Sys {
let program = program.to_bytes();
dbg("SPAWN-DIAG: calling fexec_impl (initial)\n");
if let Some(redox_rt::proc::FexecResult::Interp {
path: interp_path,
interp_override,
@@ -1566,18 +1543,8 @@ impl Pal for Sys {
let interp_path =
CStr::from_bytes_with_nul(&interp_path).map_err(|_| Errno(ENOEXEC))?;
{
let mut b = alloc::string::String::from("SPAWN-DIAG: needs interp='");
b.push_str(interp_path.to_str().unwrap_or("<utf8?>"));
b.push_str("'\n");
dbg(&b);
}
let interpreter = File::open(interp_path, fcntl::O_RDONLY | fcntl::O_CLOEXEC)
.map_err(|_| {
dbg("SPAWN-DIAG: interp File::open FAILED -> ENOENT\n");
Errno(ENOENT)
})?;
dbg("SPAWN-DIAG: interp opened ok\n");
.map_err(|_| Errno(ENOENT))?;
redox_rt::proc::fexec_impl(
FdGuard::new(interpreter.fd as usize).to_upper().unwrap(),