rename to proxy_file

This commit is contained in:
Ylarod
2025-11-08 10:52:14 +08:00
committed by ShirkNeko
parent bf5cb885b5
commit 776bcc4d5d
11 changed files with 382 additions and 400 deletions

View File

@@ -9,9 +9,7 @@ use log::{debug, error, info};
#[cfg(unix)]
use std::os::unix::process::CommandExt;
use std::{env, ffi::CStr, path::PathBuf, process::Command};
use crate::defs::NO_FD_WRAPPER_PATH;
use crate::ksucalls::get_wrapped_fd;
use crate::ksucalls::proxy_file;
#[cfg(any(target_os = "linux", target_os = "android"))]
use rustix::{
@@ -70,10 +68,10 @@ fn set_identity(uid: u32, gid: u32, groups: &[u32]) {
fn wrap_tty(fd: c_int) {
let inner_fn = move || -> Result<()> {
if unsafe { libc::isatty(fd) != 1 } {
debug!("not a tty: {fd}");
warn!("not a tty: {fd}");
return Ok(());
}
let new_fd = get_wrapped_fd(fd).context("get_wrapped_fd")?;
let new_fd = proxy_file(fd).context("proxy_file")?;
if unsafe { libc::dup2(new_fd, fd) } == -1 {
bail!("dup {new_fd} -> {fd} errno: {}", unsafe {
*libc::__errno()
@@ -149,8 +147,6 @@ pub fn root_shell() -> Result<()> {
"Specify a supplementary group. The first specified supplementary group is also used as a primary group if the option -g is not specified.",
"GROUP",
);
opts.optflag("w", "wrapper", "Use mksu fd wrapper");
opts.optflag("W", "no-wrapper", "Don't use mksu fd wrapper");
// Replace -cn with -z, -mm with -M for supporting getopt_long
let args = args
@@ -194,11 +190,6 @@ pub fn root_shell() -> Result<()> {
let mut is_login = matches.opt_present("l");
let preserve_env = matches.opt_present("p");
let mount_master = matches.opt_present("M");
let use_fd_wrapper = (!std::path::Path::new(NO_FD_WRAPPER_PATH).exists()
|| matches.opt_present("w"))
&& !matches.opt_present("W");
info!("use_fd_wrapper={use_fd_wrapper}");
let groups = matches
.opt_strs("G")
@@ -298,7 +289,7 @@ pub fn root_shell() -> Result<()> {
}
#[cfg(target_os = "android")]
if use_fd_wrapper {
if true {
wrap_tty(0);
wrap_tty(1);
wrap_tty(2);