support metamodule, remove built-in overlayfs mount
Co-authored-by: weishu <twsxtd@gmail.com> Co-authored-by: YuKongA <70465933+YuKongA@users.noreply.github.com> Co-authored-by: Ylarod <me@ylarod.cn>
This commit is contained in:
@@ -1,28 +1,14 @@
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use crate::kpm;
|
||||
use crate::utils::is_safe_mode;
|
||||
use crate::{
|
||||
assets, defs,
|
||||
defs::{KSU_MOUNT_SOURCE, NO_MOUNT_PATH, NO_TMPFS_PATH},
|
||||
ksucalls,
|
||||
module::{handle_updated_modules, prune_modules},
|
||||
restorecon, uid_scanner, utils,
|
||||
utils::find_tmp_path,
|
||||
};
|
||||
use anyhow::{Context, Result};
|
||||
use log::{info, warn};
|
||||
use rustix::fs::{MountFlags, mount};
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
pub fn mount_modules_systemlessly() -> Result<()> {
|
||||
crate::magic_mount::magic_mount(&find_tmp_path())
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub fn mount_modules_systemlessly() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use crate::kpm;
|
||||
use crate::module::{handle_updated_modules, prune_modules};
|
||||
use crate::utils::is_safe_mode;
|
||||
use crate::{
|
||||
assets, defs, ksucalls, metamodule, restorecon,
|
||||
utils::{self},
|
||||
};
|
||||
|
||||
pub fn on_post_data_fs() -> Result<()> {
|
||||
ksucalls::report_post_fs_data();
|
||||
@@ -39,9 +25,11 @@ pub fn on_post_data_fs() -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let safe_mode = utils::is_safe_mode();
|
||||
let safe_mode = crate::utils::is_safe_mode();
|
||||
|
||||
if safe_mode {
|
||||
// we should still ensure module directory exists in safe mode
|
||||
// because we may need to operate the module dir in safe mode
|
||||
warn!("safe mode, skip common post-fs-data.d scripts");
|
||||
} else {
|
||||
// Then exec common post-fs-data scripts
|
||||
@@ -50,18 +38,18 @@ pub fn on_post_data_fs() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
let module_dir = defs::MODULE_DIR;
|
||||
|
||||
assets::ensure_binaries(true).with_context(|| "Failed to extract bin assets")?;
|
||||
|
||||
// Start UID scanner daemon with highest priority
|
||||
uid_scanner::start_uid_scanner_daemon()?;
|
||||
crate::uid_scanner::uid_scanner::start_uid_scanner_daemon()?;
|
||||
|
||||
if is_safe_mode() {
|
||||
warn!("safe mode, skip load feature config");
|
||||
} else if let Err(e) = crate::umount_manager::load_and_apply_config() {
|
||||
warn!("Failed to load umount config: {e}");
|
||||
}
|
||||
// tell kernel that we've mount the module, so that it can do some optimization
|
||||
ksucalls::report_module_mounted();
|
||||
|
||||
// if we are in safe mode, we should disable all modules
|
||||
if safe_mode {
|
||||
@@ -72,14 +60,14 @@ pub fn on_post_data_fs() -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Err(e) = prune_modules() {
|
||||
warn!("prune modules failed: {e}");
|
||||
}
|
||||
|
||||
if let Err(e) = handle_updated_modules() {
|
||||
warn!("handle updated modules failed: {e}");
|
||||
}
|
||||
|
||||
if let Err(e) = prune_modules() {
|
||||
warn!("prune modules failed: {e}");
|
||||
}
|
||||
|
||||
if let Err(e) = restorecon::restorecon() {
|
||||
warn!("restorecon failed: {e}");
|
||||
}
|
||||
@@ -110,23 +98,9 @@ pub fn on_post_data_fs() -> Result<()> {
|
||||
warn!("KPM: Failed to load KPM modules: {e}");
|
||||
}
|
||||
|
||||
let tmpfs_path = find_tmp_path();
|
||||
// for compatibility
|
||||
let no_mount = Path::new(NO_TMPFS_PATH).exists() || Path::new(NO_MOUNT_PATH).exists();
|
||||
|
||||
// mount temp dir
|
||||
if !no_mount {
|
||||
if let Err(e) = mount(
|
||||
KSU_MOUNT_SOURCE,
|
||||
&tmpfs_path,
|
||||
"tmpfs",
|
||||
MountFlags::empty(),
|
||||
"",
|
||||
) {
|
||||
warn!("do temp dir mount failed: {e}");
|
||||
}
|
||||
} else {
|
||||
info!("no tmpfs requested");
|
||||
// execute metamodule post-fs-data script first (priority)
|
||||
if let Err(e) = metamodule::exec_stage_script("post-fs-data", true) {
|
||||
warn!("exec metamodule post-fs-data script failed: {e}");
|
||||
}
|
||||
|
||||
// exec modules post-fs-data scripts
|
||||
@@ -140,18 +114,15 @@ pub fn on_post_data_fs() -> Result<()> {
|
||||
warn!("load system.prop failed: {e}");
|
||||
}
|
||||
|
||||
// mount module systemlessly by magic mount
|
||||
#[cfg(target_os = "android")]
|
||||
if !no_mount {
|
||||
if let Err(e) = crate::magic_mount::magic_mount(&tmpfs_path) {
|
||||
warn!("do systemless mount failed: {e}");
|
||||
}
|
||||
} else {
|
||||
info!("no mount requested");
|
||||
// execute metamodule mount script
|
||||
if let Err(e) = metamodule::exec_mount_script(module_dir) {
|
||||
warn!("execute metamodule mount failed: {e}");
|
||||
}
|
||||
|
||||
run_stage("post-mount", true);
|
||||
|
||||
std::env::set_current_dir("/").with_context(|| "failed to chdir to /")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -171,6 +142,13 @@ fn run_stage(stage: &str, block: bool) {
|
||||
if let Err(e) = crate::module::exec_common_scripts(&format!("{stage}.d"), block) {
|
||||
warn!("Failed to exec common {stage} scripts: {e}");
|
||||
}
|
||||
|
||||
// execute metamodule stage script first (priority)
|
||||
if let Err(e) = metamodule::exec_stage_script(stage, block) {
|
||||
warn!("Failed to exec metamodule {stage} script: {e}");
|
||||
}
|
||||
|
||||
// execute regular modules stage scripts
|
||||
if let Err(e) = crate::module::exec_stage_script(stage, block) {
|
||||
warn!("Failed to exec {stage} scripts: {e}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user