ksud: add /data/adb/ksu/bin to PATH (#343)

This commit is contained in:
Ylarod
2023-04-05 11:47:35 +08:00
committed by GitHub
parent ddbc71b273
commit 862d12a904
3 changed files with 38 additions and 4 deletions

View File

@@ -3,8 +3,10 @@ use anyhow::{Ok, Result};
#[cfg(unix)]
use anyhow::ensure;
use getopts::Options;
use std::env;
#[cfg(unix)]
use std::os::unix::process::CommandExt;
use std::path::PathBuf;
use std::{ffi::CStr, process::Command};
use crate::{
@@ -84,7 +86,7 @@ pub fn root_shell() -> Result<()> {
"COMMAND",
);
opts.optflag("h", "help", "display this help message and exit");
opts.optflag("l", "login", "force run in the global mount namespace");
opts.optflag("l", "login", "pretend the shell to be a login shell");
opts.optflag(
"p",
"preserve-environment",
@@ -208,6 +210,10 @@ pub fn root_shell() -> Result<()> {
}
}
// add /data/adb/ksu/bin to PATH
#[cfg(any(target_os = "linux", target_os = "android"))]
add_path_to_env(defs::BINARY_DIR)?;
// escape from the current cgroup and become session leader
// WARNING!!! This cause some root shell hang forever!
// command = command.process_group(0);
@@ -233,6 +239,16 @@ pub fn root_shell() -> Result<()> {
Err(command.exec().into())
}
fn add_path_to_env(path: &str) -> Result<()> {
let mut paths =
env::var_os("PATH").map_or(Vec::new(), |val| env::split_paths(&val).collect::<Vec<_>>());
let new_path = PathBuf::from(path);
paths.push(new_path);
let new_path_env = env::join_paths(paths)?;
env::set_var("PATH", new_path_env);
Ok(())
}
pub fn get_version() -> i32 {
let mut result: i32 = 0;
#[cfg(any(target_os = "linux", target_os = "android"))]