diff --git a/lading/src/observer/linux/procfs.rs b/lading/src/observer/linux/procfs.rs index b89f1de15..df2d89c87 100644 --- a/lading/src/observer/linux/procfs.rs +++ b/lading/src/observer/linux/procfs.rs @@ -118,6 +118,8 @@ impl Sampler { } } } + // Update the process_info map to only hold processes seen by the current poll call. + self.process_info.retain(|pid, _| pids.contains(pid)); let pid = process.pid(); @@ -125,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; @@ -140,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 = { + 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; + } + } } } @@ -186,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; } @@ -254,7 +268,8 @@ 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}/smaps`: {err}"); + warn!("Couldn't process `/proc/{pid}/smaps`, reading next process: {err}"); + continue; } } @@ -263,7 +278,8 @@ impl Sampler { // We don't want to bail out entirely if we can't read smap rollup // which will happen if we don't have permissions or, more // likely, the process has exited. - warn!("Couldn't process `/proc/{pid}/smaps_rollup`: {err}"); + warn!("Couldn't process `/proc/{pid}/smaps_rollup`, reading next process: {err}"); + continue; } } // END pid loop