diff --git a/native/src/core/su/connect.rs b/native/src/core/su/connect.rs index bfaf0a9cf..87b5a50f0 100644 --- a/native/src/core/su/connect.rs +++ b/native/src/core/su/connect.rs @@ -6,17 +6,28 @@ use crate::ffi::{SuPolicy, SuRequest, get_magisk_tmp}; use crate::socket::IpcRead; use ExtraVal::{Bool, Int, IntList, Str}; use base::{ - BytesExt, FileAttr, LibcReturn, LoggedResult, ResultExt, Utf8CStrBuf, cstr, fork_dont_care, + BytesExt, FileAttr, LibcReturn, LoggedResult, ResultExt, Utf8CStrBuf, cstr, error, fork_dont_care, }; use nix::fcntl::OFlag; use nix::poll::{PollFd, PollFlags, PollTimeout}; +use nix::sys::signal::SigSet; use num_traits::AsPrimitive; use std::fmt::Write; use std::fs::File; use std::os::fd::AsFd; use std::os::unix::net::UCred; +use std::os::unix::process::CommandExt; use std::process::{Command, exit}; +fn app_process() -> Command { + let mut cmd = Command::new("/system/bin/app_process"); + // daemon thread blocks all signals, unblock it before starting app_process + unsafe { + cmd.pre_exec(|| SigSet::empty().thread_set_mask().map_err(Into::into)); + } + cmd +} + struct Extra<'a> { key: &'static str, value: ExtraVal<'a>, @@ -105,7 +116,7 @@ impl SuAppContext<'_> { if use_provider { let provider = format!("content://{}.provider", self.info.mgr_pkg); - let mut cmd = Command::new("/system/bin/app_process"); + let mut cmd = app_process(); cmd.args([ "/system/bin", "com.android.commands.content.Content", @@ -133,7 +144,7 @@ impl SuAppContext<'_> { } } - let mut cmd = Command::new("/system/bin/app_process"); + let mut cmd = app_process(); cmd.args([ "/system/bin", "com.android.commands.am.Am", @@ -155,13 +166,11 @@ impl SuAppContext<'_> { extras.iter().for_each(|e| e.add_intent(&mut cmd)); cmd.env("CLASSPATH", "/system/framework/am.jar"); - // Sometimes `am start` will fail, keep trying until it works - loop { - if let Ok(output) = cmd.output() - && !output.stdout.is_empty() - { - break; - } + // Async start activity + if fork_dont_care() == 0 { + let err = cmd.exec(); + error!("exec app_process: {err}"); + exit(1); } }