login: drop spawn_shell CWD workaround and diagnostics

The real fix is in init (no longer leaves an initfs-scheme CWD that is
invalid in the restricted login namespace), so spawn_shell can stay
minimal again.
This commit is contained in:
2026-07-18 10:43:07 +09:00
parent 36526f66a7
commit b6fb5ca2da
+1 -27
View File
@@ -72,35 +72,9 @@ impl AllGroupsExt for AllGroups {
/// spawn_shell(user).unwrap();
/// ```
pub fn spawn_shell<T: Default>(user: &User<T>) -> IoResult<i32> {
// Ensure the process has a working directory that is valid in the current
// (possibly restricted) login namespace before spawning the shell. After
// `apply_login_schemes` swaps to a namespace that only contains the schemes
// in DEFAULT_SCHEMES, the CWD inherited from init (e.g. `/scheme/initfs` on
// the live image) is no longer resolvable, and file operations that consult
// the CWD fd (including the child's exec) then hang. Point the CWD at the
// user's home (falling back to `/`), both of which live on the `file`
// scheme that is always present in the login namespace.
let chdir_ok = std::env::set_current_dir(&user.home).is_ok()
|| std::env::set_current_dir("/").is_ok();
eprintln!(
"spawn-diag: chdir_ok={} cwd={:?}; about to spawn {:?}",
chdir_ok,
std::env::current_dir().ok(),
user.shell
);
let mut command = user.shell_cmd();
let mut child = match command.spawn() {
Ok(c) => {
eprintln!("spawn-diag: command.spawn() returned Ok (child created)");
c
}
Err(e) => {
eprintln!("spawn-diag: command.spawn() FAILED: {} ({:?})", e, e.raw_os_error());
return Err(e);
}
};
let mut child = command.spawn()?;
match child.wait()?.code() {
Some(code) => Ok(code),
None => Ok(1),