From 2b38c3dd32754373c5b8f894da661f4fee026854 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 31 Dec 2021 16:25:03 -0700 Subject: [PATCH] mux: macos: add missing status and comm/name fields to procinfo --- mux/src/procinfo.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/mux/src/procinfo.rs b/mux/src/procinfo.rs index 227f5d3e9..b4974992f 100644 --- a/mux/src/procinfo.rs +++ b/mux/src/procinfo.rs @@ -57,6 +57,20 @@ impl From<&str> for LocalProcessStatus { } } +#[cfg(target_os = "macos")] +impl From for LocalProcessStatus { + fn from(s: u32) -> Self { + match s { + 1 => Self::Idle, + 2 => Self::Run, + 3 => Self::Sleep, + 4 => Self::Stop, + 5 => Self::Zombie, + _ => Self::Unknown, + } + } +} + #[derive(Debug, Serialize, Deserialize, Clone)] pub struct LocalProcessInfo { pub pid: u32, @@ -373,11 +387,8 @@ impl LocalProcessInfo { let (executable, argv) = exe_and_args_for_pid_sysctl(info.pbi_pid as _) .unwrap_or_else(|| (exe_for_pid(info.pbi_pid as _), vec![])); - let name = executable - .file_name() - .and_then(|e| e.to_str()) - .unwrap_or("") - .to_string(); + let name = unsafe { std::ffi::CStr::from_ptr(info.pbi_comm.as_ptr() as _) }; + let name = name.to_str().unwrap_or("").to_string(); LocalProcessInfo { pid: info.pbi_pid, @@ -387,7 +398,7 @@ impl LocalProcessInfo { cwd: cwd_for_pid(info.pbi_pid as _), argv, start_time: info.pbi_start_tvsec, - status: LocalProcessStatus::Idle, + status: LocalProcessStatus::from(info.pbi_status), children, } }