From 99e08650a498c2b2b04b840f3786a8ad1c04c0e4 Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Thu, 16 Jul 2026 10:41:15 +0900 Subject: [PATCH] DIAG: log service spawn/wait; temporarily revert switch_root chdir to test spawn hang --- init/src/main.rs | 18 +++--------------- init/src/service.rs | 6 ++++++ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/init/src/main.rs b/init/src/main.rs index e99c584b74..bd4a61a76c 100644 --- a/init/src/main.rs +++ b/init/src/main.rs @@ -54,21 +54,9 @@ impl InitConfig { fn switch_root(unit_store: &mut UnitStore, config: &mut InitConfig, prefix: &Path, etcdir: &Path) { status_ok(&format!("switchroot to {} {}", prefix.display(), etcdir.display())); - // Point init's working directory at a valid directory in the new root so - // daemons spawned afterwards don't inherit an invalid CWD (via - // AT_REDOX_CWD_FD). Without this, getcwd() fails in /usr binaries — e.g. - // the 00_base-env `zsh -c` setup printed "zsh: Failed to get current - // directory: path invalid" and then hung, so init (which waits on that - // oneshot) never reached the login stack. The switch is logical (no - // chroot) and `prefix` (e.g. "/usr") is not itself a directory, so try the - // plausible roots in order and keep the first that works. - let cwd_candidates = [prefix.to_path_buf(), std::path::PathBuf::from("/")]; - if !cwd_candidates - .iter() - .any(|cand| std::env::set_current_dir(cand).is_ok()) - { - init_warn("failed to establish a valid working directory after switch_root"); - } + // DIAGNOSTIC: chdir temporarily removed to test whether it was causing the + // first /usr Command::spawn() to hang (relibc posix_spawn opens the cwd + // fd). Re-add a correct CWD fix once the spawn hang is understood. config .envs diff --git a/init/src/service.rs b/init/src/service.rs index 27d9ec0338..f736e48520 100644 --- a/init/src/service.rs +++ b/init/src/service.rs @@ -70,6 +70,8 @@ impl Service { .unwrap_or_else(|e| panic!("pipe() failed in service.spawn for {}: {}", self.cmd, e)); unsafe { pass_fd(&mut command, "INIT_NOTIFY", write_pipe.into()) }; + eprintln!("init-diag: SPAWNING {}", self.cmd); + let _ = io::stderr().flush(); let mut child = match command.spawn() { Ok(child) => child, Err(err) => { @@ -77,6 +79,8 @@ impl Service { return; } }; + eprintln!("init-diag: SPAWNED {} (type {:?})", self.cmd, self.type_); + let _ = io::stderr().flush(); match &self.type_ { ServiceType::Notify => { @@ -126,6 +130,8 @@ impl Service { } ServiceType::Oneshot => { drop(read_pipe); + eprintln!("init-diag: WAITING {}", self.cmd); + let _ = io::stderr().flush(); match child.wait() { Ok(exit_status) => { if !exit_status.success() {