Fix wrong tty pump

See #1463
This commit is contained in:
LoveSy 2025-04-09 22:21:17 +08:00 committed by John Wu
parent c4847ed288
commit 9ddeab034b
4 changed files with 12 additions and 6 deletions

View File

@ -16,7 +16,7 @@ use logging::{android_logging, setup_logfile, zygisk_close_logd, zygisk_get_logd
use mount::{find_preinit_device, revert_unmount};
use resetprop::{persist_delete_prop, persist_get_prop, persist_get_props, persist_set_prop};
use socket::{recv_fd, recv_fds, send_fd, send_fds};
use su::{pump_stdin_stdout, get_pty_num, restore_stdin};
use su::{pump_tty, get_pty_num, restore_stdin};
use std::fs::File;
use std::mem::ManuallyDrop;
use std::ops::DerefMut;
@ -209,7 +209,7 @@ pub mod ffi {
#[namespace = "rust"]
fn daemon_entry();
fn pump_stdin_stdout(infd: i32, outfd: i32);
fn pump_tty(infd: i32, outfd: i32);
fn get_pty_num(fd: i32) -> i32;
fn restore_stdin() -> bool;
}

View File

@ -3,4 +3,4 @@ mod db;
mod pts;
pub use daemon::SuInfo;
pub use pts::{pump_stdin_stdout, get_pty_num, restore_stdin};
pub use pts::{pump_tty, get_pty_num, restore_stdin};

View File

@ -28,10 +28,14 @@ fn set_stdin_raw() -> bool {
return false;
}
let old_c_oflag = termios.c_oflag;
OLD_STDIN = Some(termios);
cfmakeraw(&mut termios);
// don't modify output flags, since we are not setting stdout raw
termios.c_oflag = old_c_oflag;
if tcsetattr(STDIN_FILENO, TCSAFLUSH, &termios) < 0
&& tcsetattr(STDIN_FILENO, TCSADRAIN, &termios) < 0
{
@ -65,7 +69,7 @@ fn resize_pty(outfd: i32) {
}
}
pub fn pump_stdin_stdout(infd: i32, outfd: i32) {
pub fn pump_tty(infd: i32, outfd: i32) {
set_stdin_raw();
let sfd = unsafe {
@ -82,7 +86,7 @@ pub fn pump_stdin_stdout(infd: i32, outfd: i32) {
let mut pfds = [
pollfd {
fd: STDIN_FILENO,
fd: if outfd > 0 { STDIN_FILENO } else { -1 },
events: POLLIN,
revents: 0,
},

View File

@ -239,7 +239,9 @@ int su_client_main(int argc, char *argv[]) {
if (atty) {
setup_sighandlers(sighandler);
pump_stdin_stdout(ptmx, ptmx);
// if stdin is not a tty, if we pump to ptmx, our process may intercept the input to ptmx and
// output to stdout, which cause the target process lost input.
pump_tty(ptmx, (atty & ATTY_IN) ? ptmx : -1);
}
// Get the exit code