Skip to content

Commit

Permalink
Merge pull request #612 from bytedance/fix-link-path
Browse files Browse the repository at this point in the history
fix link path not exist
  • Loading branch information
yoloyyh committed May 17, 2024
2 parents 2fad340 + c4b1a5c commit 1837e8f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rasp/librasp/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(()) => {
Expand Down Expand Up @@ -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(&current_path)?;
}
Ok(())
}

pub fn check_need_mount(pid_mntns: &String) -> AnyhowResult<bool> {
let root_mnt = std::fs::read_link("/proc/1/ns/mnt")?;
debug!(
Expand Down

0 comments on commit 1837e8f

Please sign in to comment.