diff --git a/userspace/ksud/src/init_event.rs b/userspace/ksud/src/init_event.rs index 32bccedd..7885788e 100644 --- a/userspace/ksud/src/init_event.rs +++ b/userspace/ksud/src/init_event.rs @@ -101,10 +101,23 @@ pub fn on_post_data_fs() -> Result<()> { run_stage("post-mount", true); + // load kpm modules for entry in std::fs::read_dir(kpm::KPM_DIR)? { let path = entry?.path(); + if let Some(file_name) = path.file_stem() { + if let Some(file_name_str) = file_name.to_str() { + if file_name_str.is_empty() { + log::warn!("Invalid KPM file name: {}", path.display()); + continue; + } + } + } + if path.extension().is_some_and(|ext| ext == "kpm") { - let _ = kpm::load_kpm(&path); + match kpm::load_kpm(&path) { + Ok(()) => log::info!("Successfully loaded KPM module: {}", path.display()), + Err(e) => log::warn!("Failed to load KPM module {}: {}", path.display(), e), + } } } diff --git a/userspace/ksud/src/kpm.rs b/userspace/ksud/src/kpm.rs index 0e0e84bc..b730678b 100644 --- a/userspace/ksud/src/kpm.rs +++ b/userspace/ksud/src/kpm.rs @@ -75,15 +75,28 @@ fn handle_remove_event(paths: Vec) { } // 加载 KPM 模块 -pub fn load_kpm(path: &Path) -> Result<()> { - let path_str = path.to_str().ok_or_else(|| anyhow!("Invalid path: {}", path.display()))?; - let status = std::process::Command::new(KPMMGR_PATH) - .args(["load", path_str, ""]) - .status()?; - - if status.success() { - log::info!("Loaded KPM: {}", path.display()); +fn load_kpm_modules() -> Result<()> { + if !Path::new(kpm::KPM_DIR).exists() { + log::warn!("KPM directory does not exist: {}", kpm::KPM_DIR); + return Ok(()); } + + for entry in std::fs::read_dir(kpm::KPM_DIR)? { + let path = entry?.path(); + if let Some(file_name) = path.file_stem() { + if let Some(file_name_str) = file_name.to_str() { + log::info!("Loading KPM module: {}", file_name_str); + } + } + + if path.extension().is_some_and(|ext| ext == "kpm") { + match kpm::load_kpm(&path) { + Ok(()) => log::info!("Successfully loaded KPM module: {}", path.display()), + Err(e) => log::warn!("Failed to load KPM module {}: {}", path.display(), e), + } + } + } + Ok(()) }