ksud: remove link manager
This commit is contained in:
@@ -186,16 +186,6 @@ enum Module {
|
|||||||
|
|
||||||
/// Shrink module image size
|
/// Shrink module image size
|
||||||
Shrink,
|
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)]
|
#[derive(clap::Subcommand, Debug)]
|
||||||
@@ -276,9 +266,6 @@ pub fn run() -> Result<()> {
|
|||||||
Module::Disable { id } => module::disable_module(&id),
|
Module::Disable { id } => module::disable_module(&id),
|
||||||
Module::List => module::list_modules(),
|
Module::List => module::list_modules(),
|
||||||
Module::Shrink => module::shrink_ksu_images(),
|
Module::Shrink => module::shrink_ksu_images(),
|
||||||
Module::LinkManager { mid, pid, pkg } => {
|
|
||||||
module::link_module_for_manager(pid, &pkg, &mid)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Commands::Install => event::install(),
|
Commands::Install => event::install(),
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ pub fn grant_root(global_mnt: bool) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
#[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");
|
unimplemented!("grant_root is only available on android");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ use const_format::concatcp;
|
|||||||
use is_executable::is_executable;
|
use is_executable::is_executable;
|
||||||
use java_properties::PropertiesIter;
|
use java_properties::PropertiesIter;
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
||||||
use rustix::{fd::AsFd, fs::CWD, mount::*};
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
@@ -706,60 +704,3 @@ pub fn shrink_ksu_images() -> Result<()> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
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!()
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user