Skip to content

Commit

Permalink
Added error handing for process_info entry creation
Browse files Browse the repository at this point in the history
Signed-off-by: Caleb Metz <[email protected]>
  • Loading branch information
cmetz100 committed Dec 18, 2024
1 parent 3b411eb commit 3aa83cb
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions lading/src/observer/linux/procfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl Sampler {
let status = match process.status() {
Ok(status) => status,
Err(e) => {
warn!("Couldn't read status: {:?}", e);
warn!("Couldn't read status: {:?}, reading next process", e);
// The pid may have exited since we scanned it or we may not
// have sufficient permission.
continue;
Expand All @@ -142,19 +142,31 @@ impl Sampler {
match self.process_info.entry(pid) {
Entry::Occupied(_) => { /* Already initialized */ }
Entry::Vacant(entry) => {
let exe = proc_exe(pid).await?;
let comm = proc_comm(pid).await?;
let cmdline = proc_cmdline(pid).await?;
let pid_s = format!("{pid}");
let stat_sampler = stat::Sampler::new();
let process_info = {

Check failure on line 145 in lading/src/observer/linux/procfs.rs

View workflow job for this annotation

GitHub Actions / Rust Actions (Check/Fmt/Clippy) (ubuntu-latest)

type annotations needed for `std::result::Result<observer::linux::procfs::ProcessInfo, _>`

Check failure on line 145 in lading/src/observer/linux/procfs.rs

View workflow job for this annotation

GitHub Actions / Test Suite

type annotations needed for `Result<ProcessInfo, _>`
let exe = proc_exe(pid).await?;
let comm = proc_comm(pid).await?;
let cmdline = proc_cmdline(pid).await?;
let pid_s = format!("{pid}");
let stat_sampler = stat::Sampler::new();

entry.insert(ProcessInfo {
cmdline,
exe,
comm,
pid_s,
stat_sampler,
});
Ok(ProcessInfo {
cmdline,
exe,
comm,
pid_s,
stat_sampler,
})
};

match process_info {
Ok(info) => {
entry.insert(info);
}
Err(e) => {
warn!("Couldn't create process_info entry for `/proc/{pid}`, reading next process: {e}");
continue;
}
}
}
}

Expand Down Expand Up @@ -188,7 +200,7 @@ impl Sampler {
// We don't want to bail out entirely if we can't read stats
// which will happen if we don't have permissions or, more
// likely, the process has exited.
warn!("Couldn't process `/proc/{pid}/stat`: {e}");
warn!("Couldn't process `/proc/{pid}/stat`, reading next process: {e}");
continue;
}

Expand Down

0 comments on commit 3aa83cb

Please sign in to comment.