From ba23f3ac2cd84b1f3b9ade8ed212e4a977c4d850 Mon Sep 17 00:00:00 2001 From: Francisco Jimenez Cabrera Date: Mon, 20 May 2024 18:41:47 +0100 Subject: [PATCH] v1 changes for Linux --- src/linux.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/linux.rs b/src/linux.rs index e6f8987..de0151a 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -1,4 +1,9 @@ +use crate::killport::NativeProcess; + +use log::debug; +use nix::unistd::Pid; use procfs::process::FDTarget; +use std::io::Error; /// Finds the inodes associated with the specified `port`. /// @@ -70,7 +75,7 @@ fn find_target_inodes(port: u16) -> Vec { /// # Arguments /// /// * `inodes` - Target inodes -fn find_target_processes(port: u16) -> Result, Error> { +pub fn find_target_processes(port: u16) -> Result, Error> { let mut target_pids: Vec = vec![]; let inodes = find_target_inodes(port); @@ -86,9 +91,14 @@ fn find_target_processes(port: u16) -> Result, Error> { if let FDTarget::Socket(sock_inode) = fd.target { if inode == sock_inode { - debug!("Found process with PID {}", process.pid); + let name = process + .cmdline() + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))? + .join(" "); + debug!("Found process '{}' with PID {}", name, process.pid()); target_pids.push(NativeProcess { pid: Pid::from_raw(process.pid), + name: name, }); } }