Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix temp dir on Android 10 or below #1250

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions userspace/ksud/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ enum Commands {
command: Profile,
},

/// Print KernelSU tmpfs path
Path,

/// For developers
Debug {
#[command(subcommand)]
Expand Down Expand Up @@ -228,6 +231,10 @@ pub fn run() -> Result<()> {
Profile::DeleteTemplate { id } => crate::profile::delete_template(id),
Profile::ListTemplates => crate::profile::list_templates(),
},
Commands::Path => {
println!("{}", utils::get_tmp_path());
Ok(())
}

Commands::Debug { command } => match command {
Debug::SetManager { apk } => debug::set_manager(&apk),
Expand Down
3 changes: 2 additions & 1 deletion userspace/ksud/src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub const MODULE_UPDATE_TMP_IMG: &str = concatcp!(WORKING_DIR, "update_tmp.img")
// warning: this directory should not change, or you need to change the code in module_installer.sh!!!
pub const MODULE_UPDATE_TMP_DIR: &str = concatcp!(ADB_DIR, "modules_update/");

pub const TEMP_DIR: &str = "/debug_ramdisk/";
pub const TEMP_DIR: &str = "/debug_ramdisk";
pub const TEMP_DIR_LEGACY: &str = "/sbin";

pub const DISABLE_FILE_NAME: &str = "disable";
pub const UPDATE_FILE_NAME: &str = "update";
Expand Down
2 changes: 1 addition & 1 deletion userspace/ksud/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn on_post_data_fs() -> Result<()> {
}

// mount temp dir
if let Err(e) = mount::mount_tmpfs(defs::TEMP_DIR) {
if let Err(e) = mount::mount_tmpfs(utils::get_tmp_path()) {
warn!("do temp dir mount failed: {}", e);
}

Expand Down
12 changes: 12 additions & 0 deletions userspace/ksud/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{
path::Path,
};

use crate::defs;
use std::fs::metadata;
#[allow(unused_imports)]
use std::fs::{set_permissions, Permissions};
#[cfg(unix)]
Expand Down Expand Up @@ -163,3 +165,13 @@ pub fn umask(_mask: u32) {
pub fn has_magisk() -> bool {
which::which("magisk").is_ok()
}

pub fn get_tmp_path() -> &'static str {
if metadata(defs::TEMP_DIR_LEGACY).is_ok() {
return defs::TEMP_DIR_LEGACY;
}
if metadata(defs::TEMP_DIR).is_ok() {
return defs::TEMP_DIR;
}
""
}
Loading