ksud: fix bind mount failed again (#395)
This fixes https://github.com/Dr-TSNG/ZygiskOnKernelSU/issues/18
This commit is contained in:
@@ -164,11 +164,13 @@ pub fn on_post_data_fs() -> Result<()> {
|
|||||||
warn!("load system.prop failed: {}", e);
|
warn!("load system.prop failed: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mount moduke systemlessly by overlay
|
// mount module systemlessly by overlay
|
||||||
if let Err(e) = mount_systemlessly(module_dir) {
|
if let Err(e) = mount_systemlessly(module_dir) {
|
||||||
warn!("do systemless mount failed: {}", e);
|
warn!("do systemless mount failed: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::env::set_current_dir("/").with_context(|| "failed to chdir to /")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,6 @@ use crate::defs::KSU_OVERLAY_SOURCE;
|
|||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use procfs::process::Process;
|
use procfs::process::Process;
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
||||||
use std::fs::File;
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
||||||
use std::os::fd::AsRawFd;
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
|
||||||
use std::os::unix::fs::OpenOptionsExt;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub struct AutoMountExt4 {
|
pub struct AutoMountExt4 {
|
||||||
@@ -32,6 +26,7 @@ impl AutoMountExt4 {
|
|||||||
let result = Mount::builder()
|
let result = Mount::builder()
|
||||||
.fstype(FilesystemType::from("ext4"))
|
.fstype(FilesystemType::from("ext4"))
|
||||||
.flags(MountFlags::empty())
|
.flags(MountFlags::empty())
|
||||||
|
.create_loop(true)
|
||||||
.mount(src, mnt)
|
.mount(src, mnt)
|
||||||
.map(|mount| {
|
.map(|mount| {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
@@ -106,6 +101,7 @@ fn mount_image(src: &str, target: &str, autodrop: bool) -> Result<()> {
|
|||||||
if autodrop {
|
if autodrop {
|
||||||
Mount::builder()
|
Mount::builder()
|
||||||
.fstype(FilesystemType::from("ext4"))
|
.fstype(FilesystemType::from("ext4"))
|
||||||
|
.create_loop(true)
|
||||||
.mount_autodrop(src, target, UnmountFlags::empty())
|
.mount_autodrop(src, target, UnmountFlags::empty())
|
||||||
.with_context(|| format!("Failed to do mount: {src} -> {target}"))?;
|
.with_context(|| format!("Failed to do mount: {src} -> {target}"))?;
|
||||||
} else {
|
} else {
|
||||||
@@ -225,11 +221,8 @@ fn mount_overlay_child(
|
|||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
pub fn mount_overlay(root: &String, module_roots: &Vec<String>) -> Result<()> {
|
pub fn mount_overlay(root: &String, module_roots: &Vec<String>) -> Result<()> {
|
||||||
info!("mount overlay for {}", root);
|
info!("mount overlay for {}", root);
|
||||||
let stock_root = File::options()
|
std::env::set_current_dir(root).with_context(|| format!("failed to chdir to {root}"))?;
|
||||||
.read(true)
|
let stock_root = ".";
|
||||||
.custom_flags(libc::O_PATH)
|
|
||||||
.open(root)?;
|
|
||||||
let stock_root = format!("/proc/self/fd/{}", stock_root.as_raw_fd());
|
|
||||||
|
|
||||||
// collect child mounts before mounting the root
|
// collect child mounts before mounting the root
|
||||||
let mounts = Process::myself()?
|
let mounts = Process::myself()?
|
||||||
|
|||||||
Reference in New Issue
Block a user