ksud: support common post-fs-data.d and service.d
This commit is contained in:
@@ -139,6 +139,9 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
// 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
|
||||||
|
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
|
||||||
|
warn!("exec common post-fs-data scripts failed: {}", e);
|
||||||
|
}
|
||||||
if let Err(e) = crate::module::exec_post_fs_data() {
|
if let Err(e) = crate::module::exec_post_fs_data() {
|
||||||
warn!("exec post-fs-data scripts failed: {}", e);
|
warn!("exec post-fs-data scripts failed: {}", e);
|
||||||
}
|
}
|
||||||
@@ -155,6 +158,9 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
pub fn on_services() -> Result<()> {
|
pub fn on_services() -> Result<()> {
|
||||||
// exec modules service.sh scripts
|
// exec modules service.sh scripts
|
||||||
if !crate::utils::is_safe_mode() {
|
if !crate::utils::is_safe_mode() {
|
||||||
|
if let Err(e) = crate::module::exec_common_scripts("service.d", false) {
|
||||||
|
warn!("exec common service scripts failed: {}", e);
|
||||||
|
}
|
||||||
if let Err(e) = crate::module::exec_services() {
|
if let Err(e) = crate::module::exec_services() {
|
||||||
warn!("exec service scripts failed: {}", e);
|
warn!("exec service scripts failed: {}", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
defs,
|
assets, defs, mount,
|
||||||
restorecon::{restore_syscon, setsyscon},
|
restorecon::{restore_syscon, setsyscon},
|
||||||
sepolicy,
|
sepolicy,
|
||||||
utils::*,
|
utils::*,
|
||||||
assets,
|
|
||||||
mount,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use const_format::concatcp;
|
use const_format::concatcp;
|
||||||
use java_properties::PropertiesIter;
|
use java_properties::PropertiesIter;
|
||||||
use log::{info, warn, debug};
|
use log::{debug, info, warn};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
env::var as env_var,
|
env::var as env_var,
|
||||||
@@ -217,7 +215,10 @@ pub fn exec_post_fs_data() -> Result<()> {
|
|||||||
let mut command_new;
|
let mut command_new;
|
||||||
let mut command;
|
let mut command;
|
||||||
if !is_executable(&post_fs_data) {
|
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_new = Command::new("sh");
|
||||||
command = command_new.arg(&post_fs_data);
|
command = command_new.arg(&post_fs_data);
|
||||||
} else {
|
} else {
|
||||||
@@ -249,6 +250,59 @@ pub fn exec_post_fs_data() -> Result<()> {
|
|||||||
Ok(())
|
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
|
/// execute every modules' service.sh
|
||||||
pub fn exec_services() -> Result<()> {
|
pub fn exec_services() -> Result<()> {
|
||||||
let modules_dir = Path::new(defs::MODULE_DIR);
|
let modules_dir = Path::new(defs::MODULE_DIR);
|
||||||
@@ -270,7 +324,10 @@ pub fn exec_services() -> Result<()> {
|
|||||||
let mut command_new;
|
let mut command_new;
|
||||||
let mut command;
|
let mut command;
|
||||||
if !is_executable(&service) {
|
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_new = Command::new("sh");
|
||||||
command = command_new.arg(&service);
|
command = command_new.arg(&service);
|
||||||
} else {
|
} else {
|
||||||
@@ -302,7 +359,6 @@ pub fn exec_services() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_system_prop() -> Result<()> {
|
pub fn load_system_prop() -> Result<()> {
|
||||||
|
|
||||||
let modules_dir = Path::new(defs::MODULE_DIR);
|
let modules_dir = Path::new(defs::MODULE_DIR);
|
||||||
let dir = std::fs::read_dir(modules_dir)?;
|
let dir = std::fs::read_dir(modules_dir)?;
|
||||||
for entry in dir.flatten() {
|
for entry in dir.flatten() {
|
||||||
@@ -474,7 +530,7 @@ fn do_install_module(zip: String) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn install_module(zip: String) -> Result<()> {
|
pub fn install_module(zip: String) -> Result<()> {
|
||||||
let result = do_install_module(zip);
|
let result = do_install_module(zip);
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
// error happened, do some cleanup!
|
// error happened, do some cleanup!
|
||||||
|
|||||||
Reference in New Issue
Block a user