From b0cfab717ed207e2bffd02b82eef56619d7acc6e Mon Sep 17 00:00:00 2001 From: vasilito Date: Sat, 18 Jul 2026 23:07:58 +0900 Subject: [PATCH] login: remove diagnostics; keep the validated-cwd shell spawn fix --- src/bin/login.rs | 6 +----- src/lib.rs | 48 +----------------------------------------------- 2 files changed, 2 insertions(+), 52 deletions(-) diff --git a/src/bin/login.rs b/src/bin/login.rs index d0c209bbe1..5e28e50733 100644 --- a/src/bin/login.rs +++ b/src/bin/login.rs @@ -166,11 +166,7 @@ pub fn main() { // this chdir here, while still in the full namespace, points // the CWD at `file:` (home, fallback `/`), which remains // valid inside the restricted login namespace. - if let Err(e) = std::env::set_current_dir(&user.home) { - eprintln!( - "login-diag: chdir home {:?} FAILED: {:?}", - user.home, e - ); + if std::env::set_current_dir(&user.home).is_err() { let _ = std::env::set_current_dir("/"); } diff --git a/src/lib.rs b/src/lib.rs index d82cbaa93f..d1eb98a8b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,26 +86,6 @@ pub fn spawn_shell(user: &User) -> IoResult { } } - // The relibc Redox spawn closes, in the child, every inherited fd that has - // FD_CLOEXEC set in the parent's filetable (see relibc - // platform/redox/mod.rs, the fds_to_close loop). A login shell MUST inherit - // its console stdio, but the pty-slave fds can arrive here still carrying - // FD_CLOEXEC (login itself keeps using them fine, since CLOEXEC only affects - // exec, not use) — which then silently drops the shell's stdin/stdout/stderr - // and leaves an interactive shell with no console. Explicitly clear - // FD_CLOEXEC on 0/1/2 so they survive the exec into the shell. - const F_GETFD: usize = 1; - const F_SETFD: usize = 2; - const FD_CLOEXEC: usize = 1; - for fd in 0..=2 { - let fl = fcntl(fd, F_GETFL, 0); - let fd_fl = fcntl(fd, F_GETFD, 0); - eprintln!("login-diag: fd{fd} F_GETFL={fl:?} F_GETFD={fd_fl:?}"); - if let Ok(flags) = fd_fl { - let _ = fcntl(fd, F_SETFD, flags & !FD_CLOEXEC); - } - } - // The login name is read with the `liner` line editor, which switches the // console pty into raw mode (ICANON/ECHO cleared) and does not restore it. // In raw mode the pty's line discipline never flushes a completed line to @@ -130,22 +110,6 @@ pub fn spawn_shell(user: &User) -> IoResult { } } - eprintln!("login-diag: cwd={:?}", std::env::current_dir()); - eprintln!( - "login-diag: open home {:?} = {:?}", - user.home, - std::fs::File::open(&user.home).map(|_| "OK") - ); - eprintln!( - "login-diag: open shell {:?} = {:?}", - user.shell, - std::fs::File::open(&user.shell).map(|_| "OK") - ); - eprintln!( - "login-diag: open /usr/bin = {:?}", - std::fs::File::open("/usr/bin").map(|_| "OK") - ); - let mut command = user.shell_cmd(); // redox_users' shell_cmd() forces current_dir(home). Rust's pre-exec child // runs chdir(home) before execvp; if that chdir fails (observed on the live @@ -157,18 +121,8 @@ pub fn spawn_shell(user: &User) -> IoResult { if let Ok(cwd) = std::env::current_dir() { command.current_dir(cwd); } - eprintln!("login-diag: spawning shell {:?}", user.shell); - let mut child = match command.spawn() { - Ok(c) => { - eprintln!("login-diag: spawn OK"); - c - } - Err(e) => { - eprintln!("login-diag: spawn ERR {:?}", e); - return Err(e); - } - }; + let mut child = command.spawn()?; match child.wait()?.code() { Some(code) => Ok(code), None => Ok(1),