From f22aa0c97e96a180a7c67f2d2a3e0c9a74cf0830 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Sat, 10 Jun 2023 22:18:50 +0800 Subject: [PATCH] fix process check --- src/common.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/common.rs b/src/common.rs index 0cd656613..030f76880 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1059,27 +1059,28 @@ pub fn check_process(arg: &str, same_uid: bool) -> bool { use hbb_common::sysinfo::{ProcessExt, System, SystemExt}; let mut sys = System::new(); sys.refresh_processes(); - let app = std::env::current_exe() - .unwrap_or_default() - .to_string_lossy() - .to_string(); - if app.is_empty() { - return false; + let mut path = std::env::current_exe().unwrap_or_default(); + if let Ok(linked) = path.read_link() { + path = linked; } let my_uid = sys .process((std::process::id() as usize).into()) .map(|x| x.user_id()) .unwrap_or_default(); for (_, p) in sys.processes().iter() { + let mut cur_path = p.exe().to_path_buf(); + if let Ok(linked) = cur_path.read_link() { + cur_path = linked; + } + if cur_path != path { + continue; + } if p.pid().to_string() == std::process::id().to_string() { continue; } if same_uid && p.user_id() != my_uid { continue; } - if p.exe().to_string_lossy() != app { - continue; - } let parg = if p.cmd().len() <= 1 { "" } else { &p.cmd()[1] }; if arg == parg { return true;