Classify absent Linux processes correctly
This commit is contained in:
parent
d720825cc9
commit
39748c50bb
1 changed files with 26 additions and 0 deletions
|
|
@ -359,6 +359,17 @@ mod platform {
|
|||
use super::*;
|
||||
use chrono::{DateTime, SecondsFormat, Utc};
|
||||
|
||||
fn is_missing_error(error: &anyhow::Error) -> bool {
|
||||
error.chain().any(|cause| {
|
||||
cause
|
||||
.downcast_ref::<std::io::Error>()
|
||||
.is_some_and(|error| {
|
||||
error.kind() == std::io::ErrorKind::NotFound
|
||||
|| error.raw_os_error() == Some(libc::ESRCH)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn stat(process_id: u32) -> Result<(u64, char)> {
|
||||
let raw = std::fs::read_to_string(format!("/proc/{process_id}/stat"))
|
||||
.with_context(|| format!("read /proc/{process_id}/stat"))?;
|
||||
|
|
@ -546,6 +557,21 @@ mod tests {
|
|||
));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn absent_linux_pid_is_missing_not_indeterminate() {
|
||||
let identity = ProcessInstanceIdentity {
|
||||
process_id: u32::MAX,
|
||||
creation_token: 1,
|
||||
created_at_rfc3339: None,
|
||||
executable_path: PathBuf::from("/definitely/absent"),
|
||||
};
|
||||
assert_eq!(
|
||||
observe_process_instance(&identity),
|
||||
ProcessInstanceObservation::Missing
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn child_exit_is_observed_for_the_exact_instance() {
|
||||
let mut child = if cfg!(windows) {
|
||||
|
|
|
|||
Reference in a new issue