DIAG: log service spawn/wait; temporarily revert switch_root chdir to test spawn hang
This commit is contained in:
+3
-15
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user