ksud: keep pwd after switch mnt ns

This commit is contained in:
tiann
2023-04-06 13:20:23 +08:00
parent fabaa61279
commit 8f4299ef62
2 changed files with 5 additions and 0 deletions

View File

@@ -333,6 +333,7 @@ fn _install_module(zip: &str) -> Result<()> {
let mut buffer: Vec<u8> = Vec::new(); let mut buffer: Vec<u8> = Vec::new();
let entry_path = PathBuf::from_str("module.prop")?; let entry_path = PathBuf::from_str("module.prop")?;
let zip_path = PathBuf::from_str(zip)?; let zip_path = PathBuf::from_str(zip)?;
let zip_path = zip_path.canonicalize()?;
zip_extract_file_to_memory(&zip_path, &entry_path, &mut buffer)?; zip_extract_file_to_memory(&zip_path, &entry_path, &mut buffer)?;
let mut module_prop = HashMap::new(); let mut module_prop = HashMap::new();

View File

@@ -103,7 +103,11 @@ pub fn switch_mnt_ns(pid: i32) -> Result<()> {
use std::os::fd::AsRawFd; use std::os::fd::AsRawFd;
let path = format!("/proc/{pid}/ns/mnt"); let path = format!("/proc/{pid}/ns/mnt");
let fd = std::fs::File::open(path)?; let fd = std::fs::File::open(path)?;
let current_dir = std::env::current_dir();
let ret = unsafe { libc::setns(fd.as_raw_fd(), libc::CLONE_NEWNS) }; let ret = unsafe { libc::setns(fd.as_raw_fd(), libc::CLONE_NEWNS) };
if let std::result::Result::Ok(current_dir) = current_dir {
let _ = std::env::set_current_dir(current_dir);
}
ensure!(ret == 0, "switch mnt ns failed"); ensure!(ret == 0, "switch mnt ns failed");
Ok(()) Ok(())
} }