Artturin 2023-12-27 18:57:39 +02:00
parent b4ba996deb
commit 804d794dcb
2 changed files with 5 additions and 8 deletions

View File

@ -1,6 +1,6 @@
use std::{
os::unix::prelude::CommandExt,
path::PathBuf,
path::{PathBuf, Path},
process::Command,
time::{Duration, SystemTime},
};
@ -37,7 +37,7 @@ fn get_database_file() -> PathBuf {
}
/// Test whether the database is more than 30 days old
fn is_database_old(database_file: &std::path::PathBuf) -> bool {
fn is_database_old(database_file: &Path) -> bool {
let Ok(metadata) = database_file.metadata() else {
return false;
};

View File

@ -14,9 +14,6 @@ const KNOWN_SHELLS: &[&str] = &[
];
fn get_process_status_field(pid: u32, field: &str) -> ResultDyn<String> {
if pid <= 0 {
return Err(format!("invalid pid: {pid}").into());
};
let status_bytes =
fs::read(format!("/proc/{pid:?}/status")).map_err(|_| format!("no such pid: {pid:?}"))?;
let status_str = String::from_utf8(status_bytes)?;
@ -26,18 +23,18 @@ fn get_process_status_field(pid: u32, field: &str) -> ResultDyn<String> {
.ok_or_else(|| format!("error parsing /proc/{pid:?}/status"))?;
let field_contents = status_str
.strip_prefix(&format!("{field}:"))
.ok_or_else(|| format!("bad parsing"))?
.ok_or_else(|| "bad parsing".to_string())?
.trim()
.to_owned();
Ok(field_contents)
}
fn get_parent_pid(pid: u32) -> ResultDyn<u32> {
Ok(get_process_status_field(pid, &"PPid")?.parse::<u32>()?)
Ok(get_process_status_field(pid, "PPid")?.parse::<u32>()?)
}
fn get_process_name(pid: u32) -> ResultDyn<String> {
Ok(get_process_status_field(pid, &"Name")?)
get_process_status_field(pid, "Name")
}
fn get_all_parents_pid(pid: u32) -> ResultDyn<Vec<u32>> {