ksud: use logcat log

This commit is contained in:
tiann
2023-02-01 20:23:42 +08:00
parent 4f2b8b7077
commit 85bf01eb65
5 changed files with 68 additions and 30 deletions

View File

@@ -5,16 +5,17 @@ use crate::{
utils::{ensure_clean_dir, ensure_dir_exists},
};
use anyhow::{bail, Context, Result};
use log::{info, warn};
fn mount_partition(partition: &str, lowerdir: &mut Vec<String>) -> Result<()> {
if lowerdir.is_empty() {
println!("partition: {partition} lowerdir is empty");
warn!("partition: {partition} lowerdir is empty");
return Ok(());
}
// if /partition is a symlink and linked to /system/partition, then we don't need to overlay it separately
if Path::new(&format!("/{}", partition)).read_link().is_ok() {
println!("partition: {} is a symlink", partition);
if Path::new(&format!("/{partition}")).read_link().is_ok() {
warn!("partition: {partition} is a symlink");
return Ok(());
}
// add /partition as the lowerest dir
@@ -22,7 +23,7 @@ fn mount_partition(partition: &str, lowerdir: &mut Vec<String>) -> Result<()> {
lowerdir.push(lowest_dir.clone());
let lowerdir = lowerdir.join(":");
println!("partition: {partition} lowerdir: {lowerdir}");
info!("partition: {partition} lowerdir: {lowerdir}");
mount::mount_overlay(&lowerdir, &lowest_dir)
}
@@ -49,13 +50,13 @@ pub fn do_systemless_mount(module_dir: &str) -> Result<()> {
}
let disabled = module.join(defs::DISABLE_FILE_NAME).exists();
if disabled {
println!("module: {} is disabled, ignore!", module.display());
info!("module: {} is disabled, ignore!", module.display());
continue;
}
let module_system = Path::new(&module).join("system");
if !module_system.as_path().exists() {
println!("module: {} has no system overlay.", module.display());
info!("module: {} has no system overlay.", module.display());
continue;
}
system_lowerdir.push(format!("{}", module_system.display()));
@@ -74,11 +75,15 @@ pub fn do_systemless_mount(module_dir: &str) -> Result<()> {
}
// mount /system first
let _ = mount_partition("system", &mut system_lowerdir);
if let Err(e) = mount_partition("system", &mut system_lowerdir) {
warn!("mount system failed: {e}");
}
// mount other partitions
for (k, mut v) in partition_lowerdir {
let _ = mount_partition(&k, &mut v);
if let Err(e) = mount_partition(&k, &mut v) {
warn!("mount {k} failed: {e}");
}
}
Ok(())
@@ -118,26 +123,30 @@ pub fn on_post_data_fs() -> Result<()> {
return Ok(());
}
println!("mount {} to {}", target_update_img, module_dir);
info!("mount {target_update_img} to {module_dir}");
mount::mount_ext4(target_update_img, module_dir)?;
// load sepolicy.rule
if crate::module::load_sepolicy_rule().is_err() {
println!("load sepolicy.rule failed");
warn!("load sepolicy.rule failed");
}
// mount systemless overlay
if let Err(e) = do_systemless_mount(module_dir) {
println!("do systemless mount failed: {}", e);
warn!("do systemless mount failed: {}", e);
}
// module mounted, exec modules post-fs-data scripts
if !crate::utils::is_safe_mode() {
// todo: Add timeout
let _ = crate::module::exec_post_fs_data();
let _ = crate::module::load_system_prop();
if let Err(e) = crate::module::exec_post_fs_data() {
warn!("exec post-fs-data scripts failed: {}", e);
}
if let Err(e) = crate::module::load_system_prop() {
warn!("load system.prop failed: {}", e);
}
} else {
println!("safe mode, skip module post-fs-data scripts");
warn!("safe mode, skip module post-fs-data scripts");
}
Ok(())
@@ -148,7 +157,7 @@ pub fn on_services() -> Result<()> {
if !crate::utils::is_safe_mode() {
let _ = crate::module::exec_services();
} else {
println!("safe mode, skip module service scripts");
warn!("safe mode, skip module service scripts");
}
Ok(())