diff --git a/rasp/librasp/src/comm.rs b/rasp/librasp/src/comm.rs index 8f788bb3c..ce51d0a75 100644 --- a/rasp/librasp/src/comm.rs +++ b/rasp/librasp/src/comm.rs @@ -6,7 +6,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Weak}; use std::thread; use std::time::Duration; -use std::fs::{remove_file, read_link, symlink_metadata}; +use std::fs::{remove_file, read_link, symlink_metadata, create_dir_all}; use std::os::unix::fs; use crossbeam::channel::{bounded, Receiver, SendError, Sender}; use libc::{kill, killpg, SIGKILL}; @@ -221,8 +221,7 @@ impl RASPComm for ThreadMode { target = resolved_path; } - // check socket exist - let _ = remove_file(target.clone()); + make_path_exist(target.clone()); match fs::symlink(self.bind_path.clone(), target.clone()) { Ok(()) => { @@ -287,6 +286,16 @@ fn mount(pid: i32, from: &str, to: &str) -> AnyhowResult<()> { }; } +pub fn make_path_exist(path: String) -> AnyhowResult<()> { + // check socket exist or path not exist + let _ = remove_file(path.clone()); + let current_path = std::path::Path::new(&path).parent().unwrap(); + if !current_path.exists() { + create_dir_all(¤t_path)?; + } + Ok(()) +} + pub fn check_need_mount(pid_mntns: &String) -> AnyhowResult { let root_mnt = std::fs::read_link("/proc/1/ns/mnt")?; debug!(