in xar/clean_xar_mounts/src/main.rs [130:168]
fn get_mounts(
nsinfo: &MountNamespaceInfo,
logger: &slog::Logger,
) -> Result<Vec<MountedFilesystem>> {
// Read the process' mounts from our own process and mount
// namespace.
let proc_mounts_path = PathBuf::from(format!("/proc/{}/mounts", nsinfo.pid));
let file = BufReader::new(File::open(proc_mounts_path)?);
let mut mounts = Vec::new();
for line in file.lines() {
if let Ok(line) = line {
let mut fields = line.split(' ').skip(1).take(2).map(str::to_string);
// mtab can be escaped; fix it up before calling umount.
// Details:
// https://gnu.org/software/libc/manual/html_node/mtab.html
// Note backslashes are just '\134' and not '\0134' - special
// case.
let mut mountpoint = fields
.next()
.expect("missing mountpoint field")
.replace("\\134", "\\");
for ch in "\t\r\n ".chars() {
let replacement = ch.to_string();
let needle = format!("\\{:o}", ch as u8);
mountpoint = mountpoint.replace(&needle, &replacement);
}
let fstype = fields.next().unwrap();
mounts.push(MountedFilesystem {
mountpoint,
chroot: nsinfo.chroot_path.clone(),
fstype,
})
} else if let Err(ref e) = line {
info!(logger, "Skipping invalid line: {:?} ({})", line, e);
}
}
return Ok(mounts);
}