Skip to content

Commit

Permalink
ksud: remove link manager
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed Feb 23, 2024
1 parent 9635a00 commit 0c52f24
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 73 deletions.
13 changes: 0 additions & 13 deletions userspace/ksud/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,6 @@ enum Module {

/// Shrink module image size
Shrink,

/// Link modules for manager
LinkManager {
/// module id
mid: String,
/// Manager's pid
pid: i32,
/// Manager's package name
pkg: String,
},
}

#[derive(clap::Subcommand, Debug)]
Expand Down Expand Up @@ -276,9 +266,6 @@ pub fn run() -> Result<()> {
Module::Disable { id } => module::disable_module(&id),
Module::List => module::list_modules(),
Module::Shrink => module::shrink_ksu_images(),
Module::LinkManager { mid, pid, pkg } => {
module::link_module_for_manager(pid, &pkg, &mid)
}
}
}
Commands::Install => event::install(),
Expand Down
2 changes: 1 addition & 1 deletion userspace/ksud/src/ksu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn grant_root(global_mnt: bool) -> Result<()> {
}

#[cfg(not(any(target_os = "linux", target_os = "android")))]
pub fn grant_root() -> Result<()> {
pub fn grant_root(_global_mnt: bool) -> Result<()> {
unimplemented!("grant_root is only available on android");
}

Expand Down
59 changes: 0 additions & 59 deletions userspace/ksud/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use const_format::concatcp;
use is_executable::is_executable;
use java_properties::PropertiesIter;
use log::{info, warn};
#[cfg(any(target_os = "linux", target_os = "android"))]
use rustix::{fd::AsFd, fs::CWD, mount::*};

use std::{
collections::HashMap,
Expand Down Expand Up @@ -706,60 +704,3 @@ pub fn shrink_ksu_images() -> Result<()> {
}
Ok(())
}

#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn link_module_for_manager(pid: i32, pkg: &str, mid: &str) -> Result<()> {
let from = PathBuf::from(defs::MODULE_DIR)
.join(mid)
.join(defs::MODULE_WEB_DIR);

let to = PathBuf::from("/data/data").join(pkg).join("webroot");

if let Result::Ok(tree) = open_tree(
rustix::fs::CWD,
&from,
OpenTreeFlags::OPEN_TREE_CLOEXEC
| OpenTreeFlags::OPEN_TREE_CLONE
| OpenTreeFlags::AT_RECURSIVE,
) {
switch_mnt_ns(pid)?;

// umount previous mount
let _ = mount::umount_dir(&to);

if let Err(e) = move_mount(
tree.as_fd(),
"",
CWD,
&to,
MoveMountFlags::MOVE_MOUNT_F_EMPTY_PATH,
) {
log::error!("move_mount failed: {}", e);
}
} else {
log::info!("fallback to bind mount");
// switch to manager's mnt ns
utils::switch_mnt_ns(pid)?;
if !Path::new(&from).exists() {
// maybe it is umounted, mount it back
log::info!("module web dir not exists, try to mount it back.");
mount::AutoMountExt4::try_new(defs::MODULE_IMG, defs::MODULE_DIR, false)
.with_context(|| "mount module image failed".to_string())?;
}

// umount previous mount
let _ = mount::umount_dir(&to);

if let Err(e) = rustix::mount::mount(&from, &to, "", MountFlags::BIND | MountFlags::REC, "")
{
log::error!("mount failed: {}", e);
}
}

Ok(())
}

#[cfg(not(any(target_os = "linux", target_os = "android")))]
pub fn link_module_for_manager(_pid: i32, _pkg: &str, _mid: &str) -> Result<()> {
unimplemented!()
}

0 comments on commit 0c52f24

Please sign in to comment.