login: remove diagnostics; keep the validated-cwd shell spawn fix
This commit is contained in:
+1
-5
@@ -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("/");
|
||||
}
|
||||
|
||||
|
||||
+1
-47
@@ -86,26 +86,6 @@ pub fn spawn_shell<T: Default>(user: &User<T>) -> IoResult<i32> {
|
||||
}
|
||||
}
|
||||
|
||||
// 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<T: Default>(user: &User<T>) -> IoResult<i32> {
|
||||
}
|
||||
}
|
||||
|
||||
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<T: Default>(user: &User<T>) -> IoResult<i32> {
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user