Filter process file metadata instead of panicking

Gracefully filter process file metadata instead of panicking, because
there's a non-zero chance this error will be encountered when processes
are being added or removed from procfs.
This commit is contained in:
Xavier Moffett 2024-09-18 16:10:24 -04:00
parent 974307a22d
commit adf9686ec3
Signed by: Sapphirus
GPG key ID: A6C061B2CEA1A7AC

View file

@ -214,10 +214,10 @@ fn procfs() -> Result<Vec<(i32, u64)>, Error> {
Ok(read_dir("/proc/") Ok(read_dir("/proc/")
.prepend_io(|| "/proc/".into())? .prepend_io(|| "/proc/".into())?
.filter_map(StdResult::ok) .filter_map(StdResult::ok)
.filter_map(|s| procfs_meta(s).expect("Unable to obtain procfs metadata")) .filter_map(|s| procfs_meta(s).map_or_else(|_| None, |x| x))
.filter_map(|(name, mtime)| { .filter_map(|(name, mtime)| {
name.to_str() name.to_str()
.expect("Invalid UTF-8 filename in procfs") .expect("UTF-8 filename in procfs")
.parse() .parse()
.map_or_else(|_| None, |v| Some((v, mtime))) .map_or_else(|_| None, |v| Some((v, mtime)))
}) })