ksud: support common post-fs-data.d and service.d
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
use crate::{
|
||||
defs,
|
||||
assets, defs, mount,
|
||||
restorecon::{restore_syscon, setsyscon},
|
||||
sepolicy,
|
||||
utils::*,
|
||||
assets,
|
||||
mount,
|
||||
};
|
||||
|
||||
use const_format::concatcp;
|
||||
use java_properties::PropertiesIter;
|
||||
use log::{info, warn, debug};
|
||||
use log::{debug, info, warn};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env::var as env_var,
|
||||
@@ -217,7 +215,10 @@ pub fn exec_post_fs_data() -> Result<()> {
|
||||
let mut command_new;
|
||||
let mut command;
|
||||
if !is_executable(&post_fs_data) {
|
||||
debug!("{} is not executable, use /system/bin/sh!", post_fs_data.display());
|
||||
debug!(
|
||||
"{} is not executable, use /system/bin/sh!",
|
||||
post_fs_data.display()
|
||||
);
|
||||
command_new = Command::new("sh");
|
||||
command = command_new.arg(&post_fs_data);
|
||||
} else {
|
||||
@@ -249,6 +250,59 @@ pub fn exec_post_fs_data() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn exec_common_scripts(dir: &str, wait: bool) -> Result<()> {
|
||||
let script_dir = Path::new(defs::WORKING_DIR).join(dir);
|
||||
if !script_dir.exists() {
|
||||
info!("{} not exists, skip", script_dir.display());
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let dir = std::fs::read_dir(&script_dir)?;
|
||||
for entry in dir.flatten() {
|
||||
let path = entry.path();
|
||||
if !path.ends_with(".sh") {
|
||||
warn!("{} is not a shell script, skip", path.display());
|
||||
continue;
|
||||
}
|
||||
|
||||
if !is_executable(&path) {
|
||||
warn!("{} is not executable, skip", path.display());
|
||||
continue;
|
||||
}
|
||||
|
||||
info!("exec {}", path.display());
|
||||
|
||||
let mut command = Command::new(&path);
|
||||
let command = command
|
||||
.process_group(0)
|
||||
.current_dir(&script_dir)
|
||||
.env(
|
||||
"PATH",
|
||||
format!("{}:{}", env_var("PATH").unwrap(), defs::BINARY_DIR),
|
||||
)
|
||||
.env("KSU", "true");
|
||||
|
||||
let command = unsafe {
|
||||
command.pre_exec(|| {
|
||||
switch_cgroups();
|
||||
Ok(())
|
||||
})
|
||||
};
|
||||
|
||||
if !wait {
|
||||
command
|
||||
.spawn() // don't wait
|
||||
.with_context(|| format!("Failed to exec {}", path.display()))?;
|
||||
} else {
|
||||
command
|
||||
.status()
|
||||
.with_context(|| format!("Failed to exec {}", path.display()))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// execute every modules' service.sh
|
||||
pub fn exec_services() -> Result<()> {
|
||||
let modules_dir = Path::new(defs::MODULE_DIR);
|
||||
@@ -270,7 +324,10 @@ pub fn exec_services() -> Result<()> {
|
||||
let mut command_new;
|
||||
let mut command;
|
||||
if !is_executable(&service) {
|
||||
debug!("{} is not executable, use /system/bin/sh!", service.display());
|
||||
debug!(
|
||||
"{} is not executable, use /system/bin/sh!",
|
||||
service.display()
|
||||
);
|
||||
command_new = Command::new("sh");
|
||||
command = command_new.arg(&service);
|
||||
} else {
|
||||
@@ -302,7 +359,6 @@ pub fn exec_services() -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn load_system_prop() -> Result<()> {
|
||||
|
||||
let modules_dir = Path::new(defs::MODULE_DIR);
|
||||
let dir = std::fs::read_dir(modules_dir)?;
|
||||
for entry in dir.flatten() {
|
||||
@@ -474,7 +530,7 @@ fn do_install_module(zip: String) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn install_module(zip: String) -> Result<()> {
|
||||
pub fn install_module(zip: String) -> Result<()> {
|
||||
let result = do_install_module(zip);
|
||||
if result.is_err() {
|
||||
// error happened, do some cleanup!
|
||||
|
||||
Reference in New Issue
Block a user