fix process check

This commit is contained in:
rustdesk 2023-06-10 22:18:50 +08:00
parent 813231e799
commit f22aa0c97e

View File

@ -1059,27 +1059,28 @@ pub fn check_process(arg: &str, same_uid: bool) -> bool {
use hbb_common::sysinfo::{ProcessExt, System, SystemExt}; use hbb_common::sysinfo::{ProcessExt, System, SystemExt};
let mut sys = System::new(); let mut sys = System::new();
sys.refresh_processes(); sys.refresh_processes();
let app = std::env::current_exe() let mut path = std::env::current_exe().unwrap_or_default();
.unwrap_or_default() if let Ok(linked) = path.read_link() {
.to_string_lossy() path = linked;
.to_string();
if app.is_empty() {
return false;
} }
let my_uid = sys let my_uid = sys
.process((std::process::id() as usize).into()) .process((std::process::id() as usize).into())
.map(|x| x.user_id()) .map(|x| x.user_id())
.unwrap_or_default(); .unwrap_or_default();
for (_, p) in sys.processes().iter() { 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() { if p.pid().to_string() == std::process::id().to_string() {
continue; continue;
} }
if same_uid && p.user_id() != my_uid { if same_uid && p.user_id() != my_uid {
continue; continue;
} }
if p.exe().to_string_lossy() != app {
continue;
}
let parg = if p.cmd().len() <= 1 { "" } else { &p.cmd()[1] }; let parg = if p.cmd().len() <= 1 { "" } else { &p.cmd()[1] };
if arg == parg { if arg == parg {
return true; return true;