From c96b0e8f8b996558e81b6a220bca9e5a13a49fda Mon Sep 17 00:00:00 2001 From: Ylarod Date: Wed, 5 Apr 2023 13:30:21 +0800 Subject: [PATCH] ksud: support .ksurc (#345) --- .gitignore | 1 + userspace/ksud/.gitignore | 1 + userspace/ksud/src/defs.rs | 1 + userspace/ksud/src/ksu.rs | 5 +++++ 4 files changed, 8 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..dbe9c82b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/ \ No newline at end of file diff --git a/userspace/ksud/.gitignore b/userspace/ksud/.gitignore index ea8c4bf7..3c71873d 100644 --- a/userspace/ksud/.gitignore +++ b/userspace/ksud/.gitignore @@ -1 +1,2 @@ /target +.cargo/ \ No newline at end of file diff --git a/userspace/ksud/src/defs.rs b/userspace/ksud/src/defs.rs index 39899c57..71ec132a 100644 --- a/userspace/ksud/src/defs.rs +++ b/userspace/ksud/src/defs.rs @@ -4,6 +4,7 @@ pub const ADB_DIR: &str = "/data/adb/"; pub const WORKING_DIR: &str = concatcp!(ADB_DIR, "ksu/"); pub const BINARY_DIR: &str = concatcp!(WORKING_DIR, "bin/"); +pub const KSURC_PATH: &str = concatcp!(WORKING_DIR, ".ksurc"); pub const DAEMON_PATH: &str = concatcp!(ADB_DIR, "ksud"); #[cfg(target_os = "android")] diff --git a/userspace/ksud/src/ksu.rs b/userspace/ksud/src/ksu.rs index 2bf5fcbf..801df321 100644 --- a/userspace/ksud/src/ksu.rs +++ b/userspace/ksud/src/ksu.rs @@ -214,6 +214,11 @@ pub fn root_shell() -> Result<()> { #[cfg(any(target_os = "linux", target_os = "android"))] add_path_to_env(defs::BINARY_DIR)?; + // when KSURC_PATH exists and ENV is not set, set ENV to KSURC_PATH + if PathBuf::from(defs::KSURC_PATH).exists() && env::var("ENV").is_err() { + command = command.env("ENV", defs::KSURC_PATH); + } + // escape from the current cgroup and become session leader // WARNING!!! This cause some root shell hang forever! // command = command.process_group(0);