ksud: use busybox to exec all shell scripts

This commit is contained in:
tiann
2023-02-02 20:37:02 +08:00
parent 2a4675e25b
commit 6a706de09e

View File

@@ -30,8 +30,9 @@ fn exec_install_script(module_file: &str) -> Result<()> {
let realpath = std::fs::canonicalize(module_file) let realpath = std::fs::canonicalize(module_file)
.with_context(|| format!("realpath: {module_file} failed"))?; .with_context(|| format!("realpath: {module_file} failed"))?;
let result = Command::new("sh") let result = Command::new(assets::BUSYBOX_PATH)
.args(["-c", INSTALL_MODULE_SCRIPT]) .args(["sh", "-c", INSTALL_MODULE_SCRIPT])
.env("ASH_STANDALONE", "1")
.env( .env(
"PATH", "PATH",
format!("{}:{}", env_var("PATH").unwrap(), defs::MODULE_DIR), format!("{}:{}", env_var("PATH").unwrap(), defs::MODULE_DIR),
@@ -214,36 +215,26 @@ pub fn exec_post_fs_data() -> Result<()> {
} }
info!("exec {} post-fs-data.sh", path.display()); info!("exec {} post-fs-data.sh", path.display());
let mut command_new; let mut command = Command::new(assets::BUSYBOX_PATH);
let mut command; let command = command.arg("sh");
if !is_executable(&post_fs_data) { let command = command.arg(&post_fs_data);
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 {
debug!("{} is executable, exec directly!", post_fs_data.display());
command_new = Command::new(&post_fs_data);
command = &mut command_new;
};
command = command let command = command
.process_group(0) .process_group(0)
.current_dir(path) .current_dir(path)
.env("ASH_STANDALONE", "1")
.env( .env(
"PATH", "PATH",
format!("{}:{}", env_var("PATH").unwrap(), defs::MODULE_DIR), format!("{}:{}", env_var("PATH").unwrap(), defs::MODULE_DIR),
) )
.env("KSU", "true"); .env("KSU", "true");
unsafe { let command = unsafe {
command = command.pre_exec(|| { command.pre_exec(|| {
// ignore the error? // ignore the error?
switch_cgroups(); switch_cgroups();
Ok(()) Ok(())
}); })
} };
command command
.status() .status()
.with_context(|| format!("Failed to exec {}", post_fs_data.display()))?; .with_context(|| format!("Failed to exec {}", post_fs_data.display()))?;
@@ -274,10 +265,13 @@ pub fn exec_common_scripts(dir: &str, wait: bool) -> Result<()> {
info!("exec {}", path.display()); info!("exec {}", path.display());
let mut command = Command::new(&path); let mut command = Command::new(assets::BUSYBOX_PATH);
let command = command.arg("sh");
let command = command.arg(&path);
let command = command let command = command
.process_group(0) .process_group(0)
.current_dir(&script_dir) .current_dir(&script_dir)
.env("ASH_STANDALONE", "1")
.env( .env(
"PATH", "PATH",
format!("{}:{}", env_var("PATH").unwrap(), defs::BINARY_DIR), format!("{}:{}", env_var("PATH").unwrap(), defs::BINARY_DIR),
@@ -323,35 +317,26 @@ pub fn exec_services() -> Result<()> {
} }
info!("exec {} service.sh", path.display()); info!("exec {} service.sh", path.display());
let mut command_new; let mut command = Command::new(assets::BUSYBOX_PATH);
let mut command; let command = command.arg("sh");
if !is_executable(&service) { let command = command.arg(&service);
debug!(
"{} is not executable, use /system/bin/sh!", let command = command
service.display()
);
command_new = Command::new("sh");
command = command_new.arg(&service);
} else {
debug!("{} is executable, exec directly!", service.display());
command_new = Command::new(&service);
command = &mut command_new;
};
command = command
.process_group(0) .process_group(0)
.current_dir(path) .current_dir(path)
.env("ASH_STANDALONE", "1")
.env( .env(
"PATH", "PATH",
format!("{}:{}", env_var("PATH").unwrap(), defs::MODULE_DIR), format!("{}:{}", env_var("PATH").unwrap(), defs::MODULE_DIR),
) )
.env("KSU", "true"); .env("KSU", "true");
unsafe { let command = unsafe {
command = command.pre_exec(|| { command.pre_exec(|| {
// ignore the error? // ignore the error?
switch_cgroups(); switch_cgroups();
Ok(()) Ok(())
}); })
} };
command command
.spawn() // don't wait .spawn() // don't wait
.with_context(|| format!("Failed to exec {}", service.display()))?; .with_context(|| format!("Failed to exec {}", service.display()))?;