Skip to content

Commit 141f010

Browse files
authored
ksud: Bring back /sbin as TEMP_DIR_LEGACY
In this commit tiann@fd09ccf TEMP_DIR_LEGACY was removed, so i restore it back. We only use /debug_ramdisk and /sbin because of this tiann@71cb86c#commitcomment-143172576 Cherry-picks from: - https://github.com/bmax121/APatch/blob/main/apd/src/utils.rs - https://github.com/bmax121/APatch/blob/main/apd/src/m_mount.rs Notice: You may will experiencing some issue with module, please backup your modules before update to this manager Signed-off-by: rsuntk <[email protected]>
1 parent 5e1d0a9 commit 141f010

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

userspace/ksud/src/defs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ pub const MODULE_UPDATE_DIR: &str = concatcp!(ADB_DIR, "modules_update/");
2525
pub const KSUD_VERBOSE_LOG_FILE: &str = concatcp!(ADB_DIR, "verbose");
2626

2727
pub const TEMP_DIR: &str = "/debug_ramdisk";
28+
pub const TEMP_DIR_LEGACY: &str = "/sbin";
2829

2930
pub const MODULE_WEB_DIR: &str = "webroot";
3031
pub const MODULE_ACTION_SH: &str = "action.sh";
3132
pub const DISABLE_FILE_NAME: &str = "disable";
3233
pub const UPDATE_FILE_NAME: &str = "update";
3334
pub const REMOVE_FILE_NAME: &str = "remove";
3435
pub const SKIP_MOUNT_FILE_NAME: &str = "skip_mount";
35-
pub const MAGIC_MOUNT_WORK_DIR: &str = concatcp!(TEMP_DIR, "/workdir");
3636

3737
pub const VERSION_CODE: &str = include_str!(concat!(env!("OUT_DIR"), "/VERSION_CODE"));
3838
pub const VERSION_NAME: &str = include_str!(concat!(env!("OUT_DIR"), "/VERSION_NAME"));

userspace/ksud/src/init_event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::defs::{KSU_MOUNT_SOURCE, NO_MOUNT_PATH, NO_TMPFS_PATH, TEMP_DIR};
1+
use crate::defs::{KSU_MOUNT_SOURCE, NO_MOUNT_PATH, NO_TMPFS_PATH};
22
use crate::module::{handle_updated_modules, prune_modules};
33
use crate::{assets, defs, ksucalls, restorecon, utils};
44
use anyhow::{Context, Result};
@@ -102,7 +102,7 @@ pub fn on_post_data_fs() -> Result<()> {
102102

103103
// mount temp dir
104104
if !Path::new(NO_TMPFS_PATH).exists() {
105-
if let Err(e) = mount_tmpfs(TEMP_DIR) {
105+
if let Err(e) = mount_tmpfs(utils::get_tmp_path()) {
106106
warn!("do temp dir mount failed: {}", e);
107107
}
108108
} else {

userspace/ksud/src/magic_mount.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::defs::{
2-
DISABLE_FILE_NAME, KSU_MOUNT_SOURCE, MAGIC_MOUNT_WORK_DIR, MODULE_DIR, SKIP_MOUNT_FILE_NAME,
2+
DISABLE_FILE_NAME, KSU_MOUNT_SOURCE, MODULE_DIR, SKIP_MOUNT_FILE_NAME,
33
};
44
use crate::magic_mount::NodeFileType::{Directory, RegularFile, Symlink, Whiteout};
55
use crate::restorecon::{lgetfilecon, lsetfilecon};
6-
use crate::utils::ensure_dir_exists;
6+
use crate::utils::{ensure_dir_exists, get_work_dir};
77
use anyhow::{bail, Context, Result};
88
use extattr::lgetxattr;
99
use rustix::fs::{
@@ -417,7 +417,7 @@ fn do_magic_mount<P: AsRef<Path>, WP: AsRef<Path>>(
417417
pub fn magic_mount() -> Result<()> {
418418
if let Some(root) = collect_module_files()? {
419419
log::debug!("collected: {:#?}", root);
420-
let tmp_dir = PathBuf::from(MAGIC_MOUNT_WORK_DIR);
420+
let tmp_dir = PathBuf::from(get_work_dir());
421421
ensure_dir_exists(&tmp_dir)?;
422422
mount(KSU_MOUNT_SOURCE, &tmp_dir, "tmpfs", MountFlags::empty(), "").context("mount tmp")?;
423423
mount_change(&tmp_dir, MountPropagationFlags::PRIVATE).context("make tmp private")?;
@@ -431,4 +431,4 @@ pub fn magic_mount() -> Result<()> {
431431
log::info!("no modules to mount, skipping!");
432432
Ok(())
433433
}
434-
}
434+
}

userspace/ksud/src/utils.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::{
1010
};
1111

1212
use crate::{assets, boot_patch, defs, ksucalls, module, restorecon};
13+
use std::fs::metadata;
1314
#[allow(unused_imports)]
1415
use std::fs::{set_permissions, Permissions};
1516
#[cfg(unix)]
@@ -177,6 +178,21 @@ pub fn has_magisk() -> bool {
177178
which::which("magisk").is_ok()
178179
}
179180

181+
pub fn get_tmp_path() -> &'static str {
182+
if metadata(defs::TEMP_DIR_LEGACY).is_ok() {
183+
return defs::TEMP_DIR_LEGACY;
184+
}
185+
if metadata(defs::TEMP_DIR).is_ok() {
186+
return defs::TEMP_DIR;
187+
}
188+
""
189+
}
190+
191+
pub fn get_work_dir() -> String {
192+
let tmp_path = get_tmp_path();
193+
format!("{}/workdir/", tmp_path)
194+
}
195+
180196
#[cfg(target_os = "android")]
181197
fn link_ksud_to_bin() -> Result<()> {
182198
let ksu_bin = PathBuf::from(defs::DAEMON_PATH);

0 commit comments

Comments
 (0)