ksud: use logcat log
This commit is contained in:
19
userspace/ksud/Cargo.lock
generated
19
userspace/ksud/Cargo.lock
generated
@@ -35,6 +35,24 @@ version = "0.2.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
|
checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "android_log-sys"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85965b6739a430150bdd138e2374a98af0c3ee0d030b3bb7fc3bddff58d0102e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "android_logger"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "037f3e1da32ddba7770530e69258b742c15ad67bdf90e5f6b35f4b6db9a60eb7"
|
||||||
|
dependencies = [
|
||||||
|
"android_log-sys",
|
||||||
|
"env_logger",
|
||||||
|
"log",
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.68"
|
version = "1.0.68"
|
||||||
@@ -601,6 +619,7 @@ name = "ksud"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-properties",
|
"android-properties",
|
||||||
|
"android_logger",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
"const_format",
|
"const_format",
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ derive-new = "0.5"
|
|||||||
[target.'cfg(target_os = "android")'.dependencies]
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
sys-mount = "2.0.1"
|
sys-mount = "2.0.1"
|
||||||
android-properties = { version = "0.2.2", features = ["bionic-deprecated"] }
|
android-properties = { version = "0.2.2", features = ["bionic-deprecated"] }
|
||||||
|
android_logger = "0.12"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true
|
strip = true
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
use anyhow::{Ok, Result};
|
use anyhow::{Ok, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
#[cfg(target_os="android")]
|
||||||
|
use android_logger::Config;
|
||||||
|
use log::LevelFilter;
|
||||||
|
|
||||||
use crate::{apk_sign, debug, event, module};
|
use crate::{apk_sign, debug, event, module};
|
||||||
|
|
||||||
@@ -117,15 +120,26 @@ enum Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn run() -> Result<()> {
|
pub fn run() -> Result<()> {
|
||||||
|
#[cfg(target_os="android")]
|
||||||
|
android_logger::init_once(
|
||||||
|
Config::default()
|
||||||
|
.with_max_level(LevelFilter::Trace) // limit log level
|
||||||
|
.with_tag("KernelSU") // logs will show under mytag tag
|
||||||
|
);
|
||||||
|
|
||||||
|
#[cfg(not(target_os="android"))]
|
||||||
|
env_logger::init();
|
||||||
|
|
||||||
let cli = Args::parse();
|
let cli = Args::parse();
|
||||||
|
|
||||||
|
log::info!("command: {:?}", cli.command);
|
||||||
|
|
||||||
let result = match cli.command {
|
let result = match cli.command {
|
||||||
Commands::Daemon => event::daemon(),
|
Commands::Daemon => event::daemon(),
|
||||||
Commands::PostFsData => event::on_post_data_fs(),
|
Commands::PostFsData => event::on_post_data_fs(),
|
||||||
Commands::BootCompleted => event::on_boot_completed(),
|
Commands::BootCompleted => event::on_boot_completed(),
|
||||||
|
|
||||||
Commands::Module { command } => {
|
Commands::Module { command } => {
|
||||||
env_logger::init();
|
|
||||||
|
|
||||||
match command {
|
match command {
|
||||||
Module::Install { zip } => module::install_module(zip),
|
Module::Install { zip } => module::install_module(zip),
|
||||||
@@ -138,7 +152,7 @@ pub fn run() -> Result<()> {
|
|||||||
Commands::Install => event::install(),
|
Commands::Install => event::install(),
|
||||||
Commands::Sepolicy { command } => match command {
|
Commands::Sepolicy { command } => match command {
|
||||||
Sepolicy::Patch { sepolicy } => crate::sepolicy::live_patch(&sepolicy),
|
Sepolicy::Patch { sepolicy } => crate::sepolicy::live_patch(&sepolicy),
|
||||||
Sepolicy::Apply { file } => crate::sepolicy::apply_file(&file),
|
Sepolicy::Apply { file } => crate::sepolicy::apply_file(file),
|
||||||
},
|
},
|
||||||
Commands::Services => event::on_services(),
|
Commands::Services => event::on_services(),
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,17 @@ use crate::{
|
|||||||
utils::{ensure_clean_dir, ensure_dir_exists},
|
utils::{ensure_clean_dir, ensure_dir_exists},
|
||||||
};
|
};
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
|
use log::{info, warn};
|
||||||
|
|
||||||
fn mount_partition(partition: &str, lowerdir: &mut Vec<String>) -> Result<()> {
|
fn mount_partition(partition: &str, lowerdir: &mut Vec<String>) -> Result<()> {
|
||||||
if lowerdir.is_empty() {
|
if lowerdir.is_empty() {
|
||||||
println!("partition: {partition} lowerdir is empty");
|
warn!("partition: {partition} lowerdir is empty");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if /partition is a symlink and linked to /system/partition, then we don't need to overlay it separately
|
// 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() {
|
if Path::new(&format!("/{partition}")).read_link().is_ok() {
|
||||||
println!("partition: {} is a symlink", partition);
|
warn!("partition: {partition} is a symlink");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
// add /partition as the lowerest dir
|
// 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());
|
lowerdir.push(lowest_dir.clone());
|
||||||
|
|
||||||
let lowerdir = lowerdir.join(":");
|
let lowerdir = lowerdir.join(":");
|
||||||
println!("partition: {partition} lowerdir: {lowerdir}");
|
info!("partition: {partition} lowerdir: {lowerdir}");
|
||||||
|
|
||||||
mount::mount_overlay(&lowerdir, &lowest_dir)
|
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();
|
let disabled = module.join(defs::DISABLE_FILE_NAME).exists();
|
||||||
if disabled {
|
if disabled {
|
||||||
println!("module: {} is disabled, ignore!", module.display());
|
info!("module: {} is disabled, ignore!", module.display());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let module_system = Path::new(&module).join("system");
|
let module_system = Path::new(&module).join("system");
|
||||||
if !module_system.as_path().exists() {
|
if !module_system.as_path().exists() {
|
||||||
println!("module: {} has no system overlay.", module.display());
|
info!("module: {} has no system overlay.", module.display());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
system_lowerdir.push(format!("{}", module_system.display()));
|
system_lowerdir.push(format!("{}", module_system.display()));
|
||||||
@@ -74,11 +75,15 @@ pub fn do_systemless_mount(module_dir: &str) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mount /system first
|
// 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
|
// mount other partitions
|
||||||
for (k, mut v) in partition_lowerdir {
|
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(())
|
Ok(())
|
||||||
@@ -118,26 +123,30 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
return Ok(());
|
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)?;
|
mount::mount_ext4(target_update_img, module_dir)?;
|
||||||
|
|
||||||
// load sepolicy.rule
|
// load sepolicy.rule
|
||||||
if crate::module::load_sepolicy_rule().is_err() {
|
if crate::module::load_sepolicy_rule().is_err() {
|
||||||
println!("load sepolicy.rule failed");
|
warn!("load sepolicy.rule failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// mount systemless overlay
|
// mount systemless overlay
|
||||||
if let Err(e) = do_systemless_mount(module_dir) {
|
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
|
// module mounted, exec modules post-fs-data scripts
|
||||||
if !crate::utils::is_safe_mode() {
|
if !crate::utils::is_safe_mode() {
|
||||||
// todo: Add timeout
|
// todo: Add timeout
|
||||||
let _ = crate::module::exec_post_fs_data();
|
if let Err(e) = crate::module::exec_post_fs_data() {
|
||||||
let _ = crate::module::load_system_prop();
|
warn!("exec post-fs-data scripts failed: {}", e);
|
||||||
|
}
|
||||||
|
if let Err(e) = crate::module::load_system_prop() {
|
||||||
|
warn!("load system.prop failed: {}", e);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("safe mode, skip module post-fs-data scripts");
|
warn!("safe mode, skip module post-fs-data scripts");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -148,7 +157,7 @@ pub fn on_services() -> Result<()> {
|
|||||||
if !crate::utils::is_safe_mode() {
|
if !crate::utils::is_safe_mode() {
|
||||||
let _ = crate::module::exec_services();
|
let _ = crate::module::exec_services();
|
||||||
} else {
|
} else {
|
||||||
println!("safe mode, skip module service scripts");
|
warn!("safe mode, skip module service scripts");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ pub fn exec_post_fs_data() -> Result<()> {
|
|||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let disabled = path.join(defs::DISABLE_FILE_NAME);
|
let disabled = path.join(defs::DISABLE_FILE_NAME);
|
||||||
if disabled.exists() {
|
if disabled.exists() {
|
||||||
println!("{} is disabled, skip", path.display());
|
warn!("{} is disabled, skip", path.display());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ pub fn exec_post_fs_data() -> Result<()> {
|
|||||||
if !post_fs_data.exists() {
|
if !post_fs_data.exists() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
println!("exec {} post-fs-data.sh", path.display());
|
info!("exec {} post-fs-data.sh", path.display());
|
||||||
|
|
||||||
let mut command_new;
|
let mut command_new;
|
||||||
let mut command;
|
let mut command;
|
||||||
@@ -255,7 +255,7 @@ pub fn exec_services() -> Result<()> {
|
|||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let disabled = path.join(defs::DISABLE_FILE_NAME);
|
let disabled = path.join(defs::DISABLE_FILE_NAME);
|
||||||
if disabled.exists() {
|
if disabled.exists() {
|
||||||
println!("{} is disabled, skip", path.display());
|
warn!("{} is disabled, skip", path.display());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +263,7 @@ pub fn exec_services() -> Result<()> {
|
|||||||
if !service.exists() {
|
if !service.exists() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
println!("exec {} service.sh", path.display());
|
info!("exec {} service.sh", path.display());
|
||||||
|
|
||||||
let mut command_new;
|
let mut command_new;
|
||||||
let mut command;
|
let mut command;
|
||||||
@@ -305,7 +305,7 @@ pub fn load_system_prop() -> Result<()> {
|
|||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let disabled = path.join(defs::DISABLE_FILE_NAME);
|
let disabled = path.join(defs::DISABLE_FILE_NAME);
|
||||||
if disabled.exists() {
|
if disabled.exists() {
|
||||||
println!("{} is disabled, skip", path.display());
|
info!("{} is disabled, skip", path.display());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +313,7 @@ pub fn load_system_prop() -> Result<()> {
|
|||||||
if !system_prop.exists() {
|
if !system_prop.exists() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
println!("load {} system.prop", path.display());
|
info!("load {} system.prop", path.display());
|
||||||
|
|
||||||
// resetprop -n --file system.prop
|
// resetprop -n --file system.prop
|
||||||
Command::new(assets::RESETPROP_PATH)
|
Command::new(assets::RESETPROP_PATH)
|
||||||
@@ -355,7 +355,6 @@ fn do_install_module(zip: String) -> Result<()> {
|
|||||||
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!");
|
||||||
};
|
};
|
||||||
info!("module id: {}", module_id);
|
|
||||||
|
|
||||||
let modules_img = Path::new(defs::MODULE_IMG);
|
let modules_img = Path::new(defs::MODULE_IMG);
|
||||||
let modules_update_img = Path::new(defs::MODULE_UPDATE_IMG);
|
let modules_update_img = Path::new(defs::MODULE_UPDATE_IMG);
|
||||||
@@ -532,9 +531,7 @@ where
|
|||||||
pub fn uninstall_module(id: String) -> Result<()> {
|
pub fn uninstall_module(id: String) -> Result<()> {
|
||||||
do_module_update(defs::MODULE_UPDATE_TMP_DIR, &id, |mid, update_dir| {
|
do_module_update(defs::MODULE_UPDATE_TMP_DIR, &id, |mid, update_dir| {
|
||||||
let dir = Path::new(update_dir);
|
let dir = Path::new(update_dir);
|
||||||
if !dir.exists() {
|
ensure!(dir.exists(), "No module installed");
|
||||||
bail!("No module installed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// iterate the modules_update dir, find the module to be removed
|
// iterate the modules_update dir, find the module to be removed
|
||||||
let dir = std::fs::read_dir(dir)?;
|
let dir = std::fs::read_dir(dir)?;
|
||||||
@@ -574,9 +571,7 @@ pub fn uninstall_module(id: String) -> Result<()> {
|
|||||||
fn do_enable_module(module_dir: &str, mid: &str, enable: bool) -> Result<()> {
|
fn do_enable_module(module_dir: &str, mid: &str, enable: bool) -> Result<()> {
|
||||||
let src_module_path = format!("{module_dir}/{mid}");
|
let src_module_path = format!("{module_dir}/{mid}");
|
||||||
let src_module = Path::new(&src_module_path);
|
let src_module = Path::new(&src_module_path);
|
||||||
if !src_module.exists() {
|
ensure!(src_module.exists(), "module: {} not found!", mid);
|
||||||
bail!("module: {} not found!", mid);
|
|
||||||
}
|
|
||||||
|
|
||||||
let disable_path = src_module.join(defs::DISABLE_FILE_NAME);
|
let disable_path = src_module.join(defs::DISABLE_FILE_NAME);
|
||||||
if enable {
|
if enable {
|
||||||
|
|||||||
Reference in New Issue
Block a user