Squash some errors; only attempt wire communication when necessary

This commit is contained in:
Audrey 2024-04-22 20:03:23 -07:00
parent 90c9d9b784
commit 2f6c583f3a
2 changed files with 13 additions and 8 deletions

View File

@ -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);

View File

@ -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);