ksud: add post_mount stage (#864)

This commit is contained in:
Ylarod
2023-08-16 11:39:32 +08:00
committed by GitHub
parent 8bf33e9aca
commit ae9519de42
6 changed files with 23 additions and 31 deletions

View File

@@ -180,7 +180,7 @@ pub fn on_post_data_fs() -> Result<()> {
// exec modules post-fs-data scripts
// TODO: Add timeout
if let Err(e) = crate::module::exec_post_fs_data() {
if let Err(e) = crate::module::exec_stage_script("post-fs-data", true) {
warn!("exec post-fs-data scripts failed: {}", e);
}
@@ -194,12 +194,14 @@ pub fn on_post_data_fs() -> Result<()> {
warn!("do systemless mount failed: {}", e);
}
run_stage("post-mount", true);
std::env::set_current_dir("/").with_context(|| "failed to chdir to /")?;
Ok(())
}
fn run_stage(stage: &str) {
fn run_stage(stage: &str, block: bool) {
utils::umask(0);
if utils::has_magisk() {
@@ -212,16 +214,17 @@ fn run_stage(stage: &str) {
return;
}
if let Err(e) = crate::module::exec_common_scripts(&format!("{stage}.d"), false) {
if let Err(e) = crate::module::exec_common_scripts(&format!("{stage}.d"), block) {
warn!("Failed to exec common {stage} scripts: {e}");
}
if let Err(e) = crate::module::exec_stage_scripts(stage) {
if let Err(e) = crate::module::exec_stage_script(stage, block) {
warn!("Failed to exec {stage} scripts: {e}");
}
}
pub fn on_services() -> Result<()> {
run_stage("service");
info!("on_services triggered!");
run_stage("service", false);
Ok(())
}
@@ -241,7 +244,7 @@ pub fn on_boot_completed() -> Result<()> {
}
}
run_stage("boot-completed");
run_stage("boot-completed", false);
Ok(())
}

View File

@@ -240,15 +240,14 @@ fn exec_script<T: AsRef<Path>>(path: T, wait: bool) -> Result<()> {
result.map_err(|err| anyhow!("Failed to exec {}: {}", path.as_ref().display(), err))
}
/// execute every modules' post-fs-data.sh
pub fn exec_post_fs_data() -> Result<()> {
pub fn exec_stage_script(stage: &str, block: bool) -> Result<()> {
foreach_active_module(|module| {
let post_fs_data = module.join("post-fs-data.sh");
if !post_fs_data.exists() {
let script_path = module.join(format!("{stage}.sh"));
if !script_path.exists() {
return Ok(());
}
exec_script(&post_fs_data, true)
exec_script(&script_path, block)
})?;
Ok(())
@@ -276,20 +275,6 @@ pub fn exec_common_scripts(dir: &str, wait: bool) -> Result<()> {
Ok(())
}
/// execute every modules' [stage].sh (service.sh, boot-completed.sh)
pub fn exec_stage_scripts(stage: &str) -> Result<()> {
foreach_active_module(|module| {
let service = module.join(format!("{stage}.sh"));
if !service.exists() {
return Ok(());
}
exec_script(&service, false)
})?;
Ok(())
}
pub fn load_system_prop() -> Result<()> {
foreach_active_module(|module| {
let system_prop = module.join("system.prop");