You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
ksud: fix clippy errors
This commit is contained in:
@@ -348,7 +348,7 @@ pub fn restore(
|
|||||||
do_cpio_cmd(
|
do_cpio_cmd(
|
||||||
&magiskboot,
|
&magiskboot,
|
||||||
workdir,
|
workdir,
|
||||||
&format!("extract {0} {0}", BACKUP_FILENAME),
|
&format!("extract {BACKUP_FILENAME} {BACKUP_FILENAME}"),
|
||||||
)?;
|
)?;
|
||||||
let sha = std::fs::read(workdir.join(BACKUP_FILENAME))?;
|
let sha = std::fs::read(workdir.join(BACKUP_FILENAME))?;
|
||||||
let sha = String::from_utf8(sha)?;
|
let sha = String::from_utf8(sha)?;
|
||||||
@@ -515,7 +515,7 @@ fn do_patch(
|
|||||||
match get_current_kmi() {
|
match get_current_kmi() {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("- {}", e);
|
println!("- {e}");
|
||||||
if let Some(image_path) = &image {
|
if let Some(image_path) = &image {
|
||||||
println!(
|
println!(
|
||||||
"- Trying to auto detect KMI version for {}",
|
"- Trying to auto detect KMI version for {}",
|
||||||
@@ -713,7 +713,7 @@ fn calculate_sha1(file_path: impl AsRef<Path>) -> Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let result = hasher.finalize();
|
let result = hasher.finalize();
|
||||||
Ok(format!("{:x}", result))
|
Ok(format!("{result:x}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
@@ -729,7 +729,7 @@ fn do_backup(magiskboot: &Path, workdir: &Path, image: &str) -> Result<()> {
|
|||||||
do_cpio_cmd(
|
do_cpio_cmd(
|
||||||
magiskboot,
|
magiskboot,
|
||||||
workdir,
|
workdir,
|
||||||
&format!("add 0755 {0} {0}", BACKUP_FILENAME),
|
&format!("add 0755 {BACKUP_FILENAME} {BACKUP_FILENAME}"),
|
||||||
)?;
|
)?;
|
||||||
println!("- Stock image has been backup to");
|
println!("- Stock image has been backup to");
|
||||||
println!("- {target}");
|
println!("- {target}");
|
||||||
@@ -739,7 +739,7 @@ fn do_backup(magiskboot: &Path, workdir: &Path, image: &str) -> Result<()> {
|
|||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
fn clean_backup(sha1: &str) -> Result<()> {
|
fn clean_backup(sha1: &str) -> Result<()> {
|
||||||
println!("- Clean up backup");
|
println!("- Clean up backup");
|
||||||
let backup_name = format!("{}{}", KSU_BACKUP_FILE_PREFIX, sha1);
|
let backup_name = format!("{KSU_BACKUP_FILE_PREFIX}{sha1}");
|
||||||
let dir = std::fs::read_dir(defs::KSU_BACKUP_DIR)?;
|
let dir = std::fs::read_dir(defs::KSU_BACKUP_DIR)?;
|
||||||
for entry in dir.flatten() {
|
for entry in dir.flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|||||||
@@ -370,13 +370,13 @@ pub fn run() -> Result<()> {
|
|||||||
Commands::BootInfo { command } => match command {
|
Commands::BootInfo { command } => match command {
|
||||||
BootInfo::CurrentKmi => {
|
BootInfo::CurrentKmi => {
|
||||||
let kmi = crate::boot_patch::get_current_kmi()?;
|
let kmi = crate::boot_patch::get_current_kmi()?;
|
||||||
println!("{}", kmi);
|
println!("{kmi}");
|
||||||
// return here to avoid printing the error message
|
// return here to avoid printing the error message
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
BootInfo::SupportedKmi => {
|
BootInfo::SupportedKmi => {
|
||||||
let kmi = crate::assets::list_supported_kmi()?;
|
let kmi = crate::assets::list_supported_kmi()?;
|
||||||
kmi.iter().for_each(|kmi| println!("{}", kmi));
|
kmi.iter().for_each(|kmi| println!("{kmi}"));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -388,7 +388,7 @@ pub fn run() -> Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = &result {
|
if let Err(e) = &result {
|
||||||
log::error!("Error: {:?}", e);
|
log::error!("Error: {e:?}");
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ fn set_kernel_param(uid: u32) -> Result<()> {
|
|||||||
fn get_pkg_uid(pkg: &str) -> Result<u32> {
|
fn get_pkg_uid(pkg: &str) -> Result<u32> {
|
||||||
// stat /data/data/<pkg>
|
// stat /data/data/<pkg>
|
||||||
let uid = rustix::fs::stat(format!("/data/data/{pkg}"))
|
let uid = rustix::fs::stat(format!("/data/data/{pkg}"))
|
||||||
.with_context(|| format!("stat /data/data/{}", pkg))?
|
.with_context(|| format!("stat /data/data/{pkg}"))?
|
||||||
.st_uid;
|
.st_uid;
|
||||||
Ok(uid)
|
Ok(uid)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
} else {
|
} else {
|
||||||
// Then exec common post-fs-data scripts
|
// Then exec common post-fs-data scripts
|
||||||
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
|
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
|
||||||
warn!("exec common post-fs-data scripts failed: {}", e);
|
warn!("exec common post-fs-data scripts failed: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,21 +41,21 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
if safe_mode {
|
if safe_mode {
|
||||||
warn!("safe mode, skip post-fs-data scripts and disable all modules!");
|
warn!("safe mode, skip post-fs-data scripts and disable all modules!");
|
||||||
if let Err(e) = crate::module::disable_all_modules() {
|
if let Err(e) = crate::module::disable_all_modules() {
|
||||||
warn!("disable all modules failed: {}", e);
|
warn!("disable all modules failed: {e}");
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = prune_modules() {
|
if let Err(e) = prune_modules() {
|
||||||
warn!("prune modules failed: {}", e);
|
warn!("prune modules failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = handle_updated_modules() {
|
if let Err(e) = handle_updated_modules() {
|
||||||
warn!("handle updated modules failed: {}", e);
|
warn!("handle updated modules failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = restorecon::restorecon() {
|
if let Err(e) = restorecon::restorecon() {
|
||||||
warn!("restorecon failed: {}", e);
|
warn!("restorecon failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// load sepolicy.rule
|
// load sepolicy.rule
|
||||||
@@ -64,13 +64,13 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = crate::profile::apply_sepolies() {
|
if let Err(e) = crate::profile::apply_sepolies() {
|
||||||
warn!("apply root profile sepolicy failed: {}", e);
|
warn!("apply root profile sepolicy failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// mount temp dir
|
// mount temp dir
|
||||||
if !Path::new(NO_TMPFS_PATH).exists() {
|
if !Path::new(NO_TMPFS_PATH).exists() {
|
||||||
if let Err(e) = mount(KSU_MOUNT_SOURCE, TEMP_DIR, "tmpfs", MountFlags::empty(), "") {
|
if let Err(e) = mount(KSU_MOUNT_SOURCE, TEMP_DIR, "tmpfs", MountFlags::empty(), "") {
|
||||||
warn!("do temp dir mount failed: {}", e);
|
warn!("do temp dir mount failed: {e}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info!("no tmpfs requested");
|
info!("no tmpfs requested");
|
||||||
@@ -79,18 +79,18 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
// exec modules post-fs-data scripts
|
// exec modules post-fs-data scripts
|
||||||
// TODO: Add timeout
|
// TODO: Add timeout
|
||||||
if let Err(e) = crate::module::exec_stage_script("post-fs-data", true) {
|
if let Err(e) = crate::module::exec_stage_script("post-fs-data", true) {
|
||||||
warn!("exec post-fs-data scripts failed: {}", e);
|
warn!("exec post-fs-data scripts failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// load system.prop
|
// load system.prop
|
||||||
if let Err(e) = crate::module::load_system_prop() {
|
if let Err(e) = crate::module::load_system_prop() {
|
||||||
warn!("load system.prop failed: {}", e);
|
warn!("load system.prop failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// mount module systemlessly by magic mount
|
// mount module systemlessly by magic mount
|
||||||
if !Path::new(NO_MOUNT_PATH).exists() {
|
if !Path::new(NO_MOUNT_PATH).exists() {
|
||||||
if let Err(e) = mount_modules_systemlessly() {
|
if let Err(e) = mount_modules_systemlessly() {
|
||||||
warn!("do systemless mount failed: {}", e);
|
warn!("do systemless mount failed: {e}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info!("no mount requested");
|
info!("no mount requested");
|
||||||
@@ -180,7 +180,7 @@ fn catch_bootlog(logname: &str, command: Vec<&str>) -> Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
warn!("Failed to start logcat: {:#}", e);
|
warn!("Failed to start logcat: {e:#}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -416,14 +416,14 @@ fn do_magic_mount<P: AsRef<Path>, WP: AsRef<Path>>(
|
|||||||
|
|
||||||
pub fn magic_mount() -> Result<()> {
|
pub fn magic_mount() -> Result<()> {
|
||||||
if let Some(root) = collect_module_files()? {
|
if let Some(root) = collect_module_files()? {
|
||||||
log::debug!("collected: {:#?}", root);
|
log::debug!("collected: {root:#?}");
|
||||||
let tmp_dir = PathBuf::from(MAGIC_MOUNT_WORK_DIR);
|
let tmp_dir = PathBuf::from(MAGIC_MOUNT_WORK_DIR);
|
||||||
ensure_dir_exists(&tmp_dir)?;
|
ensure_dir_exists(&tmp_dir)?;
|
||||||
mount(KSU_MOUNT_SOURCE, &tmp_dir, "tmpfs", MountFlags::empty(), "").context("mount tmp")?;
|
mount(KSU_MOUNT_SOURCE, &tmp_dir, "tmpfs", MountFlags::empty(), "").context("mount tmp")?;
|
||||||
mount_change(&tmp_dir, MountPropagationFlags::PRIVATE).context("make tmp private")?;
|
mount_change(&tmp_dir, MountPropagationFlags::PRIVATE).context("make tmp private")?;
|
||||||
let result = do_magic_mount("/", &tmp_dir, root, false);
|
let result = do_magic_mount("/", &tmp_dir, root, false);
|
||||||
if let Err(e) = unmount(&tmp_dir, UnmountFlags::DETACH) {
|
if let Err(e) = unmount(&tmp_dir, UnmountFlags::DETACH) {
|
||||||
log::error!("failed to unmount tmp {}", e);
|
log::error!("failed to unmount tmp {e}");
|
||||||
}
|
}
|
||||||
fs::remove_dir(tmp_dir).ok();
|
fs::remove_dir(tmp_dir).ok();
|
||||||
result
|
result
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ pub fn prune_modules() -> Result<()> {
|
|||||||
let uninstaller = module.join("uninstall.sh");
|
let uninstaller = module.join("uninstall.sh");
|
||||||
if uninstaller.exists() {
|
if uninstaller.exists() {
|
||||||
if let Err(e) = exec_script(uninstaller, true) {
|
if let Err(e) = exec_script(uninstaller, true) {
|
||||||
warn!("Failed to exec uninstaller: {}", e);
|
warn!("Failed to exec uninstaller: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +323,7 @@ pub fn install_module(zip: &str) -> Result<()> {
|
|||||||
module_prop.insert(k, v);
|
module_prop.insert(k, v);
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
info!("module prop: {:?}", module_prop);
|
info!("module prop: {module_prop:?}");
|
||||||
|
|
||||||
let Some(module_id) = module_prop.get("id") else {
|
let Some(module_id) = module_prop.get("id") else {
|
||||||
bail!("module id not found in module.prop!");
|
bail!("module id not found in module.prop!");
|
||||||
@@ -401,7 +401,7 @@ pub fn restore_module(id: &str) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_action(id: &str) -> Result<()> {
|
pub fn run_action(id: &str) -> Result<()> {
|
||||||
let action_script_path = format!("/data/adb/modules/{}/action.sh", id);
|
let action_script_path = format!("/data/adb/modules/{id}/action.sh");
|
||||||
exec_script(&action_script_path, true)
|
exec_script(&action_script_path, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,9 +70,9 @@ pub fn apply_sepolies() -> Result<()> {
|
|||||||
};
|
};
|
||||||
let sepolicy = sepolicy.path();
|
let sepolicy = sepolicy.path();
|
||||||
if sepolicy::apply_file(&sepolicy).is_ok() {
|
if sepolicy::apply_file(&sepolicy).is_ok() {
|
||||||
log::info!("profile sepolicy applied: {:?}", sepolicy);
|
log::info!("profile sepolicy applied: {sepolicy:?}");
|
||||||
} else {
|
} else {
|
||||||
log::info!("profile sepolicy apply failed: {:?}", sepolicy);
|
log::info!("profile sepolicy apply failed: {sepolicy:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -697,7 +697,7 @@ fn apply_one_rule<'a>(statement: &'a PolicyStatement<'a>, strict: bool) -> Resul
|
|||||||
|
|
||||||
for policy in policies {
|
for policy in policies {
|
||||||
if !rustix::process::ksu_set_policy(&FfiPolicy::from(policy)) {
|
if !rustix::process::ksu_set_policy(&FfiPolicy::from(policy)) {
|
||||||
log::warn!("apply rule: {:?} failed.", statement);
|
log::warn!("apply rule: {statement:?} failed.");
|
||||||
if strict {
|
if strict {
|
||||||
return Err(anyhow::anyhow!("apply rule {:?} failed.", statement));
|
return Err(anyhow::anyhow!("apply rule {:?} failed.", statement));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,12 +104,12 @@ pub fn is_safe_mode() -> bool {
|
|||||||
|| getprop("ro.sys.safemode")
|
|| getprop("ro.sys.safemode")
|
||||||
.filter(|prop| prop == "1")
|
.filter(|prop| prop == "1")
|
||||||
.is_some();
|
.is_some();
|
||||||
log::info!("safemode: {}", safemode);
|
log::info!("safemode: {safemode}");
|
||||||
if safemode {
|
if safemode {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let safemode = ksucalls::check_kernel_safemode();
|
let safemode = ksucalls::check_kernel_safemode();
|
||||||
log::info!("kernel_safemode: {}", safemode);
|
log::info!("kernel_safemode: {safemode}");
|
||||||
safemode
|
safemode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ pub fn restore(
|
|||||||
do_cpio_cmd(
|
do_cpio_cmd(
|
||||||
&magiskboot,
|
&magiskboot,
|
||||||
workdir,
|
workdir,
|
||||||
&format!("extract {0} {0}", BACKUP_FILENAME),
|
&format!("extract {BACKUP_FILENAME} {BACKUP_FILENAME}"),
|
||||||
)?;
|
)?;
|
||||||
let sha = std::fs::read(workdir.join(BACKUP_FILENAME))?;
|
let sha = std::fs::read(workdir.join(BACKUP_FILENAME))?;
|
||||||
let sha = String::from_utf8(sha)?;
|
let sha = String::from_utf8(sha)?;
|
||||||
@@ -515,7 +515,7 @@ fn do_patch(
|
|||||||
match get_current_kmi() {
|
match get_current_kmi() {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("- {}", e);
|
println!("- {e}");
|
||||||
if let Some(image_path) = &image {
|
if let Some(image_path) = &image {
|
||||||
println!(
|
println!(
|
||||||
"- Trying to auto detect KMI version for {}",
|
"- Trying to auto detect KMI version for {}",
|
||||||
@@ -713,7 +713,7 @@ fn calculate_sha1(file_path: impl AsRef<Path>) -> Result<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let result = hasher.finalize();
|
let result = hasher.finalize();
|
||||||
Ok(format!("{:x}", result))
|
Ok(format!("{result:x}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
@@ -729,7 +729,7 @@ fn do_backup(magiskboot: &Path, workdir: &Path, image: &str) -> Result<()> {
|
|||||||
do_cpio_cmd(
|
do_cpio_cmd(
|
||||||
magiskboot,
|
magiskboot,
|
||||||
workdir,
|
workdir,
|
||||||
&format!("add 0755 {0} {0}", BACKUP_FILENAME),
|
&format!("add 0755 {BACKUP_FILENAME} {BACKUP_FILENAME}"),
|
||||||
)?;
|
)?;
|
||||||
println!("- Stock image has been backup to");
|
println!("- Stock image has been backup to");
|
||||||
println!("- {target}");
|
println!("- {target}");
|
||||||
@@ -739,7 +739,7 @@ fn do_backup(magiskboot: &Path, workdir: &Path, image: &str) -> Result<()> {
|
|||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
fn clean_backup(sha1: &str) -> Result<()> {
|
fn clean_backup(sha1: &str) -> Result<()> {
|
||||||
println!("- Clean up backup");
|
println!("- Clean up backup");
|
||||||
let backup_name = format!("{}{}", KSU_BACKUP_FILE_PREFIX, sha1);
|
let backup_name = format!("{KSU_BACKUP_FILE_PREFIX}{sha1}");
|
||||||
let dir = std::fs::read_dir(defs::KSU_BACKUP_DIR)?;
|
let dir = std::fs::read_dir(defs::KSU_BACKUP_DIR)?;
|
||||||
for entry in dir.flatten() {
|
for entry in dir.flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|||||||
@@ -385,13 +385,13 @@ pub fn run() -> Result<()> {
|
|||||||
Commands::BootInfo { command } => match command {
|
Commands::BootInfo { command } => match command {
|
||||||
BootInfo::CurrentKmi => {
|
BootInfo::CurrentKmi => {
|
||||||
let kmi = crate::boot_patch::get_current_kmi()?;
|
let kmi = crate::boot_patch::get_current_kmi()?;
|
||||||
println!("{}", kmi);
|
println!("{kmi}");
|
||||||
// return here to avoid printing the error message
|
// return here to avoid printing the error message
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
BootInfo::SupportedKmi => {
|
BootInfo::SupportedKmi => {
|
||||||
let kmi = crate::assets::list_supported_kmi()?;
|
let kmi = crate::assets::list_supported_kmi()?;
|
||||||
kmi.iter().for_each(|kmi| println!("{}", kmi));
|
kmi.iter().for_each(|kmi| println!("{kmi}"));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -403,7 +403,7 @@ pub fn run() -> Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = &result {
|
if let Err(e) = &result {
|
||||||
log::error!("Error: {:?}", e);
|
log::error!("Error: {e:?}");
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ fn set_kernel_param(uid: u32) -> Result<()> {
|
|||||||
fn get_pkg_uid(pkg: &str) -> Result<u32> {
|
fn get_pkg_uid(pkg: &str) -> Result<u32> {
|
||||||
// stat /data/data/<pkg>
|
// stat /data/data/<pkg>
|
||||||
let uid = rustix::fs::stat(format!("/data/data/{pkg}"))
|
let uid = rustix::fs::stat(format!("/data/data/{pkg}"))
|
||||||
.with_context(|| format!("stat /data/data/{}", pkg))?
|
.with_context(|| format!("stat /data/data/{pkg}"))?
|
||||||
.st_uid;
|
.st_uid;
|
||||||
Ok(uid)
|
Ok(uid)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,13 +83,13 @@ pub fn mount_modules_systemlessly(module_dir: &str) -> Result<()> {
|
|||||||
|
|
||||||
// mount /system first
|
// mount /system first
|
||||||
if let Err(e) = mount_partition("system", &system_lowerdir) {
|
if let Err(e) = mount_partition("system", &system_lowerdir) {
|
||||||
warn!("mount system failed: {:#}", e);
|
warn!("mount system failed: {e:#}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// mount other partitions
|
// mount other partitions
|
||||||
for (k, v) in partition_lowerdir {
|
for (k, v) in partition_lowerdir {
|
||||||
if let Err(e) = mount_partition(&k, &v) {
|
if let Err(e) = mount_partition(&k, &v) {
|
||||||
warn!("mount {k} failed: {:#}", e);
|
warn!("mount {k} failed: {e:#}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
} else {
|
} else {
|
||||||
// Then exec common post-fs-data scripts
|
// Then exec common post-fs-data scripts
|
||||||
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
|
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
|
||||||
warn!("exec common post-fs-data scripts failed: {}", e);
|
warn!("exec common post-fs-data scripts failed: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,17 +168,17 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
if safe_mode {
|
if safe_mode {
|
||||||
warn!("safe mode, skip post-fs-data scripts and disable all modules!");
|
warn!("safe mode, skip post-fs-data scripts and disable all modules!");
|
||||||
if let Err(e) = crate::module::disable_all_modules() {
|
if let Err(e) = crate::module::disable_all_modules() {
|
||||||
warn!("disable all modules failed: {}", e);
|
warn!("disable all modules failed: {e}");
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = prune_modules() {
|
if let Err(e) = prune_modules() {
|
||||||
warn!("prune modules failed: {}", e);
|
warn!("prune modules failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = restorecon::restorecon() {
|
if let Err(e) = restorecon::restorecon() {
|
||||||
warn!("restorecon failed: {}", e);
|
warn!("restorecon failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// load sepolicy.rule
|
// load sepolicy.rule
|
||||||
@@ -187,28 +187,28 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = crate::profile::apply_sepolies() {
|
if let Err(e) = crate::profile::apply_sepolies() {
|
||||||
warn!("apply root profile sepolicy failed: {}", e);
|
warn!("apply root profile sepolicy failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// mount temp dir
|
// mount temp dir
|
||||||
if let Err(e) = mount::mount_tmpfs(utils::get_tmp_path()) {
|
if let Err(e) = mount::mount_tmpfs(utils::get_tmp_path()) {
|
||||||
warn!("do temp dir mount failed: {}", e);
|
warn!("do temp dir mount failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// exec modules post-fs-data scripts
|
// exec modules post-fs-data scripts
|
||||||
// TODO: Add timeout
|
// TODO: Add timeout
|
||||||
if let Err(e) = crate::module::exec_stage_script("post-fs-data", true) {
|
if let Err(e) = crate::module::exec_stage_script("post-fs-data", true) {
|
||||||
warn!("exec post-fs-data scripts failed: {}", e);
|
warn!("exec post-fs-data scripts failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// load system.prop
|
// load system.prop
|
||||||
if let Err(e) = crate::module::load_system_prop() {
|
if let Err(e) = crate::module::load_system_prop() {
|
||||||
warn!("load system.prop failed: {}", e);
|
warn!("load system.prop failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// mount module systemlessly by overlay
|
// mount module systemlessly by overlay
|
||||||
if let Err(e) = mount_modules_systemlessly(module_dir) {
|
if let Err(e) = mount_modules_systemlessly(module_dir) {
|
||||||
warn!("do systemless mount failed: {}", e);
|
warn!("do systemless mount failed: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
run_stage("post-mount", true);
|
run_stage("post-mount", true);
|
||||||
@@ -298,7 +298,7 @@ fn catch_bootlog(logname: &str, command: Vec<&str>) -> Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
warn!("Failed to start logcat: {:#}", e);
|
warn!("Failed to start logcat: {e:#}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ pub fn prune_modules() -> Result<()> {
|
|||||||
let uninstaller = module.join("uninstall.sh");
|
let uninstaller = module.join("uninstall.sh");
|
||||||
if uninstaller.exists() {
|
if uninstaller.exists() {
|
||||||
if let Err(e) = exec_script(uninstaller, true) {
|
if let Err(e) = exec_script(uninstaller, true) {
|
||||||
warn!("Failed to exec uninstaller: {}", e);
|
warn!("Failed to exec uninstaller: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,7 +346,7 @@ fn _install_module(zip: &str) -> Result<()> {
|
|||||||
module_prop.insert(k, v);
|
module_prop.insert(k, v);
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
info!("module prop: {:?}", module_prop);
|
info!("module prop: {module_prop:?}");
|
||||||
|
|
||||||
let Some(module_id) = module_prop.get("id") else {
|
let Some(module_id) = module_prop.get("id") else {
|
||||||
bail!("module id not found in module.prop!");
|
bail!("module id not found in module.prop!");
|
||||||
@@ -475,13 +475,13 @@ fn _install_module(zip: &str) -> Result<()> {
|
|||||||
|
|
||||||
let _dontdrop = mount::AutoMountExt4::try_new(tmp_module_img, module_update_tmp_dir, true)?;
|
let _dontdrop = mount::AutoMountExt4::try_new(tmp_module_img, module_update_tmp_dir, true)?;
|
||||||
|
|
||||||
info!("mounted {} to {}", tmp_module_img, module_update_tmp_dir);
|
info!("mounted {tmp_module_img} to {module_update_tmp_dir}");
|
||||||
|
|
||||||
setsyscon(module_update_tmp_dir)?;
|
setsyscon(module_update_tmp_dir)?;
|
||||||
|
|
||||||
let module_dir = format!("{module_update_tmp_dir}/{module_id}");
|
let module_dir = format!("{module_update_tmp_dir}/{module_id}");
|
||||||
ensure_clean_dir(&module_dir)?;
|
ensure_clean_dir(&module_dir)?;
|
||||||
info!("module dir: {}", module_dir);
|
info!("module dir: {module_dir}");
|
||||||
|
|
||||||
// unzip the image and move it to modules_update/<id> dir
|
// unzip the image and move it to modules_update/<id> dir
|
||||||
let file = File::open(zip)?;
|
let file = File::open(zip)?;
|
||||||
@@ -673,7 +673,7 @@ pub fn restore_module(id: &str) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_action(id: &str) -> Result<()> {
|
pub fn run_action(id: &str) -> Result<()> {
|
||||||
let action_script_path = format!("/data/adb/modules/{}/action.sh", id);
|
let action_script_path = format!("/data/adb/modules/{id}/action.sh");
|
||||||
exec_script(&action_script_path, true)
|
exec_script(&action_script_path, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ pub fn mount_overlayfs(
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
warn!("fsopen mount failed: {:#}, fallback to mount", e);
|
warn!("fsopen mount failed: {e:#}, fallback to mount");
|
||||||
let mut data = format!("lowerdir={lowerdir_config}");
|
let mut data = format!("lowerdir={lowerdir_config}");
|
||||||
if let (Some(upperdir), Some(workdir)) = (upperdir, workdir) {
|
if let (Some(upperdir), Some(workdir)) = (upperdir, workdir) {
|
||||||
data = format!("{data},upperdir={upperdir},workdir={workdir}");
|
data = format!("{data},upperdir={upperdir},workdir={workdir}");
|
||||||
@@ -246,7 +246,7 @@ fn mount_overlay_child(
|
|||||||
}
|
}
|
||||||
// merge modules and stock
|
// merge modules and stock
|
||||||
if let Err(e) = mount_overlayfs(&lower_dirs, stock_root, None, None, mount_point) {
|
if let Err(e) = mount_overlayfs(&lower_dirs, stock_root, None, None, mount_point) {
|
||||||
warn!("failed: {:#}, fallback to bind mount", e);
|
warn!("failed: {e:#}, fallback to bind mount");
|
||||||
bind_mount(stock_root, mount_point)?;
|
bind_mount(stock_root, mount_point)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -259,7 +259,7 @@ pub fn mount_overlay(
|
|||||||
workdir: Option<PathBuf>,
|
workdir: Option<PathBuf>,
|
||||||
upperdir: Option<PathBuf>,
|
upperdir: Option<PathBuf>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
info!("mount overlay for {}", root);
|
info!("mount overlay for {root}");
|
||||||
std::env::set_current_dir(root).with_context(|| format!("failed to chdir to {root}"))?;
|
std::env::set_current_dir(root).with_context(|| format!("failed to chdir to {root}"))?;
|
||||||
let stock_root = ".";
|
let stock_root = ".";
|
||||||
|
|
||||||
@@ -290,10 +290,7 @@ pub fn mount_overlay(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Err(e) = mount_overlay_child(mount_point, &relative, module_roots, &stock_root) {
|
if let Err(e) = mount_overlay_child(mount_point, &relative, module_roots, &stock_root) {
|
||||||
warn!(
|
warn!("failed to mount overlay for child {mount_point}: {e:#}, revert");
|
||||||
"failed to mount overlay for child {}: {:#}, revert",
|
|
||||||
mount_point, e
|
|
||||||
);
|
|
||||||
umount_dir(root).with_context(|| format!("failed to revert {root}"))?;
|
umount_dir(root).with_context(|| format!("failed to revert {root}"))?;
|
||||||
bail!(e);
|
bail!(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,9 +70,9 @@ pub fn apply_sepolies() -> Result<()> {
|
|||||||
};
|
};
|
||||||
let sepolicy = sepolicy.path();
|
let sepolicy = sepolicy.path();
|
||||||
if sepolicy::apply_file(&sepolicy).is_ok() {
|
if sepolicy::apply_file(&sepolicy).is_ok() {
|
||||||
log::info!("profile sepolicy applied: {:?}", sepolicy);
|
log::info!("profile sepolicy applied: {sepolicy:?}");
|
||||||
} else {
|
} else {
|
||||||
log::info!("profile sepolicy apply failed: {:?}", sepolicy);
|
log::info!("profile sepolicy apply failed: {sepolicy:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -697,7 +697,7 @@ fn apply_one_rule<'a>(statement: &'a PolicyStatement<'a>, strict: bool) -> Resul
|
|||||||
|
|
||||||
for policy in policies {
|
for policy in policies {
|
||||||
if !rustix::process::ksu_set_policy(&FfiPolicy::from(policy)) {
|
if !rustix::process::ksu_set_policy(&FfiPolicy::from(policy)) {
|
||||||
log::warn!("apply rule: {:?} failed.", statement);
|
log::warn!("apply rule: {statement:?} failed.");
|
||||||
if strict {
|
if strict {
|
||||||
return Err(anyhow::anyhow!("apply rule {:?} failed.", statement));
|
return Err(anyhow::anyhow!("apply rule {:?} failed.", statement));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,12 +110,12 @@ pub fn is_safe_mode() -> bool {
|
|||||||
|| getprop("ro.sys.safemode")
|
|| getprop("ro.sys.safemode")
|
||||||
.filter(|prop| prop == "1")
|
.filter(|prop| prop == "1")
|
||||||
.is_some();
|
.is_some();
|
||||||
log::info!("safemode: {}", safemode);
|
log::info!("safemode: {safemode}");
|
||||||
if safemode {
|
if safemode {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let safemode = ksucalls::check_kernel_safemode();
|
let safemode = ksucalls::check_kernel_safemode();
|
||||||
log::info!("kernel_safemode: {}", safemode);
|
log::info!("kernel_safemode: {safemode}");
|
||||||
safemode
|
safemode
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +240,7 @@ pub fn get_tmp_path() -> &'static str {
|
|||||||
|
|
||||||
CHOSEN_TMP_PATH.get_or_init(|| {
|
CHOSEN_TMP_PATH.get_or_init(|| {
|
||||||
let r = find_temp_path();
|
let r = find_temp_path();
|
||||||
log::info!("Chosen temp_path: {}", r);
|
log::info!("Chosen temp_path: {r}");
|
||||||
r
|
r
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -367,7 +367,7 @@ fn copy_xattrs(src_path: impl AsRef<Path>, dest_path: impl AsRef<Path>) -> Resul
|
|||||||
if let Err(e) =
|
if let Err(e) =
|
||||||
extattr::lsetxattr(dest_path.as_ref(), &xattr, &value, extattr::Flags::empty())
|
extattr::lsetxattr(dest_path.as_ref(), &xattr, &value, extattr::Flags::empty())
|
||||||
{
|
{
|
||||||
log::warn!("Failed to set xattr: {}", e);
|
log::warn!("Failed to set xattr: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -400,7 +400,7 @@ pub fn copy_module_files(source: impl AsRef<Path>, destination: impl AsRef<Path>
|
|||||||
std::fs::remove_file(&dest_path).context("Failed to remove file")?;
|
std::fs::remove_file(&dest_path).context("Failed to remove file")?;
|
||||||
}
|
}
|
||||||
let target = std::fs::read_link(entry.path()).context("Failed to read symlink")?;
|
let target = std::fs::read_link(entry.path()).context("Failed to read symlink")?;
|
||||||
log::info!("Symlink: {:?} -> {:?}", dest_path, target);
|
log::info!("Symlink: {dest_path:?} -> {target:?}");
|
||||||
std::os::unix::fs::symlink(target, &dest_path).context("Failed to create symlink")?;
|
std::os::unix::fs::symlink(target, &dest_path).context("Failed to create symlink")?;
|
||||||
copy_xattrs(&source_path, &dest_path)?;
|
copy_xattrs(&source_path, &dest_path)?;
|
||||||
} else if entry.file_type().is_dir() {
|
} else if entry.file_type().is_dir() {
|
||||||
|
|||||||
Reference in New Issue
Block a user