mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-24 04:12:20 +08:00
refactor process id
This commit is contained in:
parent
f47dcd1a8b
commit
8f998771c9
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1726,7 +1726,6 @@ dependencies = [
|
||||
"serde_json 1.0.74",
|
||||
"socket2 0.3.19",
|
||||
"sodiumoxide",
|
||||
"sysinfo",
|
||||
"tokio",
|
||||
"tokio-socks",
|
||||
"tokio-util",
|
||||
@ -3398,6 +3397,7 @@ dependencies = [
|
||||
"serde_json 1.0.74",
|
||||
"sha2",
|
||||
"sys-locale",
|
||||
"sysinfo",
|
||||
"systray",
|
||||
"uuid",
|
||||
"whoami",
|
||||
|
@ -43,6 +43,7 @@ uuid = { version = "0.8", features = ["v4"] }
|
||||
clap = "3.0"
|
||||
rpassword = "5.0"
|
||||
base64 = "0.13"
|
||||
sysinfo = "0.22"
|
||||
|
||||
[target.'cfg(not(any(target_os = "android")))'.dependencies]
|
||||
cpal = { git = "https://github.com/open-trade/cpal" }
|
||||
|
@ -30,7 +30,6 @@ filetime = "0.2"
|
||||
sodiumoxide = "0.2"
|
||||
regex = "1.4"
|
||||
tokio-socks = { git = "https://github.com/fufesou/tokio-socks" }
|
||||
sysinfo = "0.22"
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
mac_address = "1.1"
|
||||
|
@ -27,13 +27,13 @@ pub use anyhow::{self, bail};
|
||||
pub use futures_util;
|
||||
pub mod config;
|
||||
pub mod fs;
|
||||
pub use mac_address;
|
||||
pub use rand;
|
||||
pub use regex;
|
||||
pub use sodiumoxide;
|
||||
pub use sysinfo;
|
||||
pub use tokio_socks;
|
||||
pub use tokio_socks::IntoTargetAddr;
|
||||
pub use tokio_socks::TargetAddr;
|
||||
pub use mac_address;
|
||||
|
||||
#[cfg(feature = "quic")]
|
||||
pub type Stream = quic::Connection;
|
||||
@ -186,17 +186,6 @@ pub fn get_version_number(v: &str) -> i64 {
|
||||
n
|
||||
}
|
||||
|
||||
pub fn get_process(pid: i32) -> Option<sysinfo::Process> {
|
||||
use sysinfo::{System, SystemExt};
|
||||
let mut sys = System::new();
|
||||
sys.refresh_processes();
|
||||
sys.process(pid).cloned()
|
||||
}
|
||||
|
||||
pub fn get_current_process() -> Option<sysinfo::Process> {
|
||||
get_process(std::process::id() as _)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -298,15 +298,17 @@ fn get_pid_file(postfix: &str) -> String {
|
||||
|
||||
#[cfg(not(windows))]
|
||||
async fn check_pid(postfix: &str) {
|
||||
use hbb_common::sysinfo::ProcessExt;
|
||||
let pid_file = get_pid_file(postfix);
|
||||
if let Ok(mut file) = File::open(&pid_file) {
|
||||
let mut content = String::new();
|
||||
file.read_to_string(&mut content).ok();
|
||||
let pid = content.parse::<i32>().unwrap_or(0);
|
||||
if pid > 0 {
|
||||
if let Some(p) = hbb_common::get_process(pid) {
|
||||
if let Some(current) = hbb_common::get_current_process() {
|
||||
use sysinfo::{ProcessExt, System, SystemExt};
|
||||
let mut sys = System::new();
|
||||
sys.refresh_processes();
|
||||
if let Some(p) = sys.process(pid) {
|
||||
if let Some(current) = sys.process(std::process::id() as _) {
|
||||
if current.name() == p.name() {
|
||||
// double check with connect
|
||||
if connect(1000, postfix).await.is_ok() {
|
||||
|
Loading…
Reference in New Issue
Block a user