diff --git a/userspace/ksud/src/event.rs b/userspace/ksud/src/event.rs index 87e20a50..869288dd 100644 --- a/userspace/ksud/src/event.rs +++ b/userspace/ksud/src/event.rs @@ -124,7 +124,8 @@ pub fn on_post_data_fs() -> Result<()> { } info!("mount {target_update_img} to {module_dir}"); - mount::mount_ext4(target_update_img, module_dir, false)?; + mount::AutoMountExt4::try_new(target_update_img, module_dir, false) + .with_context(|| "mount module image failed".to_string())?; // load sepolicy.rule if crate::module::load_sepolicy_rule().is_err() { diff --git a/userspace/ksud/src/module.rs b/userspace/ksud/src/module.rs index 98b16a2a..c7d53108 100644 --- a/userspace/ksud/src/module.rs +++ b/userspace/ksud/src/module.rs @@ -11,9 +11,9 @@ use log::{debug, info, warn}; use std::{ collections::HashMap, env::var as env_var, - fs::{remove_dir_all, File, OpenOptions, set_permissions, Permissions}, + fs::{remove_dir_all, set_permissions, File, OpenOptions, Permissions}, io::{Cursor, Read, Write}, - os::unix::{process::CommandExt, prelude::PermissionsExt}, + os::unix::{prelude::PermissionsExt, process::CommandExt}, path::{Path, PathBuf}, process::{Command, Stdio}, str::FromStr, @@ -490,7 +490,7 @@ fn do_install_module(zip: String) -> Result<()> { // mount the modules_update.img to mountpoint println!("- Mounting image"); - let _dontdrop = mount::AutoMountExt4::try_new(tmp_module_img, module_update_tmp_dir)?; + let _dontdrop = mount::AutoMountExt4::try_new(tmp_module_img, module_update_tmp_dir, true)?; info!("mounted {} to {}", tmp_module_img, module_update_tmp_dir); @@ -573,7 +573,7 @@ where ensure_clean_dir(update_dir)?; // mount the modules_update img - let _dontdrop = mount::AutoMountExt4::try_new(defs::MODULE_UPDATE_TMP_IMG, update_dir)?; + let _dontdrop = mount::AutoMountExt4::try_new(defs::MODULE_UPDATE_TMP_IMG, update_dir, true)?; // call the operation func let result = func(id, update_dir); diff --git a/userspace/ksud/src/mount.rs b/userspace/ksud/src/mount.rs index c60e3351..827a11b3 100644 --- a/userspace/ksud/src/mount.rs +++ b/userspace/ksud/src/mount.rs @@ -12,12 +12,13 @@ pub struct AutoMountExt4 { mnt: String, #[cfg(target_os = "android")] mount: Option, + auto_umount: bool, } #[allow(dead_code)] impl AutoMountExt4 { #[cfg(target_os = "android")] - pub fn try_new(src: &str, mnt: &str) -> Result { + pub fn try_new(src: &str, mnt: &str, auto_umount: bool) -> Result { let result = Mount::builder() .fstype(FilesystemType::from("ext4")) .flags(MountFlags::empty()) @@ -26,6 +27,7 @@ impl AutoMountExt4 { Ok(Self { mnt: mnt.to_string(), mount: Some(mount), + auto_umount }) }); if let Err(e) = result { @@ -44,6 +46,7 @@ impl AutoMountExt4 { Ok(Self { mnt: mnt.to_string(), mount: None, + auto_umount }) } } else { @@ -52,7 +55,7 @@ impl AutoMountExt4 { } #[cfg(not(target_os = "android"))] - pub fn try_new(_src: &str, _mnt: &str) -> Result { + pub fn try_new(_src: &str, _mnt: &str, _auto_umount: bool) -> Result { unimplemented!() } @@ -77,8 +80,10 @@ impl AutoMountExt4 { #[cfg(target_os = "android")] impl Drop for AutoMountExt4 { fn drop(&mut self) { - log::info!("AutoMountExt4 drop: {}", self.mnt); - let _ = self.umount(); + log::info!("AutoMountExt4 drop: {}, auto_umount: {}", self.mnt, self.auto_umount); + if self.auto_umount { + let _ = self.umount(); + } } }