Skip to content

Commit

Permalink
Handle case where /proc/self/ns/mnt is missing
Browse files Browse the repository at this point in the history
Don't require /proc/self/ns/mnt to exist on linux, if it doesn't exist
just assume that we aren't running in a docker container

Closes #326
  • Loading branch information
benfred committed Jan 19, 2021
1 parent 107d09a commit 361e115
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/python_spy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,12 +836,8 @@ impl PythonProcessInfo {
};

#[cfg(target_os="linux")]
let dockerized = {
let target_ns_filename = format!("/proc/{}/ns/mnt", process.pid);
let self_mnt = std::fs::read_link("/proc/self/ns/mnt")?;
let target_mnt = std::fs::read_link(&target_ns_filename)?;
self_mnt != target_mnt
};
let dockerized = is_dockerized(process.pid).unwrap_or(false);

Ok(PythonProcessInfo{python_binary, libpython_binary, maps, python_filename,
#[cfg(target_os="linux")]
dockerized
Expand All @@ -866,6 +862,13 @@ impl PythonProcessInfo {
}
}

#[cfg(target_os="linux")]
fn is_dockerized(pid: Pid) -> Result<bool, Error> {
let self_mnt = std::fs::read_link("/proc/self/ns/mnt")?;
let target_mnt = std::fs::read_link(&format!("/proc/{}/ns/mnt", pid))?;
Ok(self_mnt != target_mnt)
}

// We can't use goblin to parse external symbol files (like in a separate .pdb file) on windows,
// So use the win32 api to load up the couple of symbols we need on windows. Note:
// we still can get export's from the PE file
Expand Down

0 comments on commit 361e115

Please sign in to comment.