Skip to content

Commit

Permalink
ksud: fix common post-fs-data.d may not execute if no modules are ena…
Browse files Browse the repository at this point in the history
…bled
  • Loading branch information
tiann committed Jul 24, 2023
1 parent 978178a commit 3664003
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions userspace/ksud/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub fn mount_systemlessly(module_dir: &str) -> Result<()> {
pub fn on_post_data_fs() -> Result<()> {
crate::ksu::report_post_fs_data();

utils::umask(0);

#[cfg(unix)]
let _ = catch_bootlog();

Expand All @@ -100,7 +102,18 @@ pub fn on_post_data_fs() -> Result<()> {
return Ok(());
}

utils::umask(0);
let safe_mode = crate::utils::is_safe_mode();

if safe_mode {
// we should still mount modules.img to `/data/adb/modules` in safe mode
// becuase 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
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
warn!("exec common post-fs-data scripts failed: {}", e);
}
}

let module_update_img = defs::MODULE_UPDATE_IMG;
let module_img = defs::MODULE_IMG;
Expand Down Expand Up @@ -129,7 +142,6 @@ pub fn on_post_data_fs() -> Result<()> {
}
}

// If there isn't any image exist, do nothing for module!
if !Path::new(target_update_img).exists() {
return Ok(());
}
Expand All @@ -140,8 +152,8 @@ pub fn on_post_data_fs() -> Result<()> {
mount::AutoMountExt4::try_new(target_update_img, module_dir, false)
.with_context(|| "mount module image failed".to_string())?;

// check safe mode first.
if crate::utils::is_safe_mode() {
// if we are in safe mode, we should disable all modules
if safe_mode {
warn!("safe mode, skip post-fs-data scripts and disable all modules!");
if let Err(e) = crate::module::disable_all_modules() {
warn!("disable all modules failed: {}", e);
Expand All @@ -153,11 +165,6 @@ pub fn on_post_data_fs() -> Result<()> {
warn!("prune modules failed: {}", e);
}

// Then exec common post-fs-data scripts
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
warn!("exec common post-fs-data scripts failed: {}", e);
}

// load sepolicy.rule
if crate::module::load_sepolicy_rule().is_err() {
warn!("load sepolicy.rule failed");
Expand Down Expand Up @@ -197,7 +204,7 @@ pub fn on_services() -> Result<()> {
}

if crate::utils::is_safe_mode() {
warn!("safe mode, skip module service scripts");
warn!("safe mode, skip service.d scripts");
return Ok(());
}

Expand Down

0 comments on commit 3664003

Please sign in to comment.