ksud: support services. close #60

This commit is contained in:
tiann
2023-01-16 12:22:47 +08:00
parent 2222a999b9
commit f98066cb99
3 changed files with 54 additions and 2 deletions

View File

@@ -190,6 +190,44 @@ pub fn exec_post_fs_data() -> Result<()> {
Ok(())
}
/// execute every modules' service.sh
pub fn exec_services() -> Result<()> {
let modules_dir = Path::new(defs::MODULE_DIR);
let dir = std::fs::read_dir(modules_dir)?;
for entry in dir.flatten() {
let path = entry.path();
let disabled = path.join(defs::DISABLE_FILE_NAME);
if disabled.exists() {
println!("{} is disabled, skip", path.display());
continue;
}
let service = path.join("service.sh");
if !service.exists() {
continue;
}
println!("exec {} service.sh", path.display());
// pre_exec is unsafe!
unsafe {
Command::new("/system/bin/sh")
.arg(&service)
.process_group(0)
.pre_exec(|| {
// ignore the error?
let _ = switch_cgroups();
Ok(())
})
.current_dir(path)
.env("KSU", "true")
.spawn() // don't wait
.with_context(|| format!("Failed to exec {}", service.display()))?;
}
}
Ok(())
}
const RESETPROP: &[u8] = include_bytes!("./resetprop");
const RESETPROP_PATH: &str = concatcp!(defs::WORKING_DIR, "/resetprop");