From 2f6c583f3adc9cf2619e88a16d54fa9f7fee325c Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Mon, 22 Apr 2024 20:03:23 -0700 Subject: [PATCH] Squash some errors; only attempt wire communication when necessary --- src/filestore.rs | 3 +-- src/tracer/client.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/filestore.rs b/src/filestore.rs index 2a7e005..8d2432d 100644 --- a/src/filestore.rs +++ b/src/filestore.rs @@ -295,8 +295,7 @@ pub fn parse_format(fp: &mut (impl io::Read + io::Seek)) -> anyhow::Result<(File // was moved between compilation and ingestion. but how... let metadata = match fs::metadata(&filename) { Ok(m) => m, - Err(e) if e.kind() == io::ErrorKind::NotFound => return Ok(None), - Err(e) => return Err(e)?, + Err(_) => return Ok(None), }; if !metadata.is_file() { return Ok(None); diff --git a/src/tracer/client.rs b/src/tracer/client.rs index 45fdc9d..42cc1c8 100644 --- a/src/tracer/client.rs +++ b/src/tracer/client.rs @@ -421,8 +421,17 @@ impl TracerClient { ptrace::setoptions(root_child.into(), ptrace_opts)?; // restart child ptrace::syscall(nix::unistd::Pid::from(root_child.into()), None)?; - loop { - let status = waitpid(None, Some(WaitPidFlag::__WALL))?; + let mut continuing = true; + while continuing { + let status = { + let status = waitpid(None, Some(WaitPidFlag::__WALL)); + if status.is_err_and(|e| e == nix::errno::Errno::ECHILD) { + continuing = false; + Ok(WaitStatus::StillAlive) + } else { + status + } + }?; // log::trace!("waitpid: {:?}", status); let signal = match status { WaitStatus::Stopped(pid, sig) => { @@ -467,9 +476,6 @@ impl TracerClient { self.log_root(pid, Event::Exit { code }); self.store.get_current_mut(pid).unwrap().status = ProcessStatus::Exited(code); - if pid == root_child { - break; - } None } WaitStatus::PtraceEvent(pid, sig, evt) => { @@ -559,7 +565,7 @@ impl TracerClient { _ => None }; - if !self.pending_files.is_empty() || !self.pending_events.is_empty() { + if !self.pending_files.is_empty() || !continuing { let mut events = vec![]; let mut files = BTreeSet::new(); std::mem::swap(&mut events, &mut self.pending_events);