From 7270f5e4136f63a23d049a295e75a2958be6fcf5 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 2 Oct 2025 02:46:18 -0700 Subject: [PATCH] Several minor fixes/improvements --- native/src/core/bootstages.rs | 2 +- native/src/core/logging.rs | 4 ++-- native/src/core/su/su.cpp | 22 +++++++--------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/native/src/core/bootstages.rs b/native/src/core/bootstages.rs index 9a0045277..bcb51728f 100644 --- a/native/src/core/bootstages.rs +++ b/native/src/core/bootstages.rs @@ -75,8 +75,8 @@ impl MagiskD { let tmp_bb = buf.append_path(get_magisk_tmp()).append_path(BBPATH); tmp_bb.mkdirs(0o755).ok(); tmp_bb.append_path("busybox"); - tmp_bb.follow_link().chmod(0o755).log_ok(); busybox.copy_to(tmp_bb).ok(); + tmp_bb.follow_link().chmod(0o755).log_ok(); // Install busybox applets Command::new(&tmp_bb) diff --git a/native/src/core/logging.rs b/native/src/core/logging.rs index 08e550ae6..422b4404a 100644 --- a/native/src/core/logging.rs +++ b/native/src/core/logging.rs @@ -2,7 +2,7 @@ use crate::consts::{LOG_PIPE, LOGFILE}; use crate::ffi::get_magisk_tmp; use crate::logging::LogFile::{Actual, Buffer}; use base::{ - FsPathBuilder, LogLevel, LoggedResult, ReadExt, Utf8CStr, Utf8CStrBuf, WriteExt, + FsPathBuilder, LogLevel, LoggedResult, ReadExt, ResultExt, Utf8CStr, Utf8CStrBuf, WriteExt, const_format::concatcp, cstr, libc, new_daemon_thread, raw_cstr, update_logger, }; use bytemuck::{Pod, Zeroable, bytes_of, write_zeroes}; @@ -328,7 +328,7 @@ pub fn start_log_daemon() { } let _: LoggedResult<()> = try { - path.mkfifo(0o666)?; + path.mkfifo(0o666).log_ok(); chown(path.as_utf8_cstr(), Some(Uid::from(0)), Some(Gid::from(0)))?; let read = path.open(OFlag::O_RDWR | OFlag::O_CLOEXEC)?; let write = path.open(OFlag::O_WRONLY | OFlag::O_CLOEXEC)?; diff --git a/native/src/core/su/su.cpp b/native/src/core/su/su.cpp index 0c27d54f2..4a3532968 100644 --- a/native/src/core/su/su.cpp +++ b/native/src/core/su/su.cpp @@ -234,14 +234,11 @@ int su_client_main(int argc, char *argv[]) { if (atty) { // We need a PTY. Get one. - write_int(fd, 1); int ptmx = recv_fd(fd); setup_sighandlers(sighandler); // If stdin is not a tty, and 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); - } else { - write_int(fd, 0); } // Get the exit code @@ -335,9 +332,10 @@ void exec_root_shell(int client, int pid, SuRequest &req, MntNsMode mode) { int infd = recv_fd(client); int outfd = recv_fd(client); int errfd = recv_fd(client); + int ptsfd = -1; // App need a PTY - if (read_int(client)) { + if (infd < 0 || outfd < 0 || errfd < 0) { string pts; string ptmx; auto magiskpts = get_magisk_tmp() + "/"s SHELLPTS; @@ -370,24 +368,18 @@ void exec_root_shell(int client, int pid, SuRequest &req, MntNsMode mode) { // Opening the TTY has to occur after the // fork() and setsid() so that it becomes // our controlling TTY and not the daemon's - int ptsfd = xopen(pts_slave.data(), O_RDWR); - - if (infd < 0) - infd = ptsfd; - if (outfd < 0) - outfd = ptsfd; - if (errfd < 0) - errfd = ptsfd; + ptsfd = xopen(pts_slave.data(), O_RDWR); } // Swap out stdin, stdout, stderr - xdup2(infd, STDIN_FILENO); - xdup2(outfd, STDOUT_FILENO); - xdup2(errfd, STDERR_FILENO); + xdup2(infd < 0 ? ptsfd : infd, STDIN_FILENO); + xdup2(outfd < 0 ? ptsfd : outfd, STDOUT_FILENO); + xdup2(errfd < 0 ? ptsfd : errfd, STDERR_FILENO); close(infd); close(outfd); close(errfd); + close(ptsfd); close(client); // Handle namespaces