From f47dcd1a8ba94c7645fa80267cb20242375a3f75 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Sat, 15 Jan 2022 13:47:57 +0800 Subject: [PATCH] remove psutil which is too old --- Cargo.lock | 203 +++++++++++++++++++++++++------------ Cargo.toml | 5 +- libs/hbb_common/Cargo.toml | 1 + libs/hbb_common/src/lib.rs | 14 ++- src/ipc.rs | 8 +- src/server.rs | 14 +-- 6 files changed, 157 insertions(+), 88 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8959e3b88..9dc71966d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -217,7 +217,7 @@ dependencies = [ "bitflags", "cexpr 0.6.0", "clang-sys", - "clap", + "clap 2.34.0", "env_logger 0.9.0", "lazy_static", "lazycell", @@ -368,11 +368,26 @@ dependencies = [ "atty", "bitflags", "strsim 0.8.0", - "textwrap", + "textwrap 0.11.0", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12e8611f9ae4e068fa3e56931fded356ff745e70987ff76924a6e0ab1c8ef2e3" +dependencies = [ + "atty", + "bitflags", + "indexmap", + "os_str_bytes", + "strsim 0.10.0", + "termcolor", + "textwrap 0.14.2", +] + [[package]] name = "clipboard-master" version = "3.1.3" @@ -630,6 +645,50 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", + "lazy_static", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120" +dependencies = [ + "cfg-if 1.0.0", + "lazy_static", +] + [[package]] name = "crypto-common" version = "0.1.1" @@ -735,26 +794,6 @@ dependencies = [ "syn", ] -[[package]] -name = "darwin-libproc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc629b7cf42586fee31dae31f9ab73fa5ff5f0170016aa61be5fcbc12a90c516" -dependencies = [ - "darwin-libproc-sys", - "libc", - "memchr", -] - -[[package]] -name = "darwin-libproc-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef0aa083b94c54aa4cfd9bbfd37856714c139d1dc511af80270558c7ba3b4816" -dependencies = [ - "libc", -] - [[package]] name = "dasp" version = "0.11.0" @@ -895,17 +934,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "digest" version = "0.10.1" @@ -1666,6 +1694,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "hbb_common" version = "0.1.0" @@ -1692,6 +1726,7 @@ dependencies = [ "serde_json 1.0.74", "socket2 0.3.19", "sodiumoxide", + "sysinfo", "tokio", "tokio-socks", "tokio-util", @@ -1771,6 +1806,16 @@ dependencies = [ "quote", ] +[[package]] +name = "indexmap" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +dependencies = [ + "autocfg 1.0.1", + "hashbrown", +] + [[package]] name = "inotify" version = "0.7.1" @@ -2083,9 +2128,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.3.4" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "memoffset" @@ -2576,6 +2621,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] + [[package]] name = "pango" version = "0.9.1" @@ -2731,12 +2785,6 @@ version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" -[[package]] -name = "platforms" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8d0eef3571242013a0d5dc84861c3ae4a652e56e12adf8bdc26ff5f8cb34c94" - [[package]] name = "png" version = "0.16.8" @@ -2878,24 +2926,6 @@ dependencies = [ "which 4.2.2", ] -[[package]] -name = "psutil" -version = "3.2.1" -source = "git+https://github.com/open-trade/rust-psutil#22b2e1bb4e29433a6ddb0c1bb259fe01e894c94f" -dependencies = [ - "cfg-if 1.0.0", - "darwin-libproc", - "derive_more", - "glob", - "mach", - "nix 0.23.1", - "num_cpus", - "once_cell", - "platforms", - "thiserror", - "unescape", -] - [[package]] name = "quest" version = "0.3.0" @@ -3127,6 +3157,31 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "rayon" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +dependencies = [ + "autocfg 1.0.1", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + [[package]] name = "rdev" version = "0.5.0" @@ -3304,7 +3359,7 @@ dependencies = [ "base64", "cc", "cfg-if 1.0.0", - "clap", + "clap 3.0.7", "clipboard-master", "cocoa 0.24.0", "core-foundation 0.9.2", @@ -3329,7 +3384,6 @@ dependencies = [ "notify", "objc", "parity-tokio-ipc", - "psutil", "rdev", "repng", "rpassword 5.0.1", @@ -3746,6 +3800,21 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "sysinfo" +version = "0.22.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f1bfab07306a27332451a662ca9c8156e3a9986f82660ba9c8e744fe8455d43" +dependencies = [ + "cfg-if 1.0.0", + "core-foundation-sys 0.8.3", + "libc", + "ntapi", + "once_cell", + "rayon", + "winapi 0.3.9", +] + [[package]] name = "system-deps" version = "1.3.2" @@ -3826,6 +3895,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" + [[package]] name = "thiserror" version = "1.0.30" @@ -4008,12 +4083,6 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" -[[package]] -name = "unescape" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccb97dac3243214f8d8507998906ca3e2e0b900bf9bf4870477f125b82e68f6e" - [[package]] name = "unicode-segmentation" version = "1.8.0" diff --git a/Cargo.toml b/Cargo.toml index 4f10ec7d5..33516b6ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ samplerate = { version = "0.2", optional = true } async-trait = "0.1" crc32fast = "1.3" uuid = { version = "0.8", features = ["v4"] } -clap = "2.34" +clap = "3.0" rpassword = "5.0" base64 = "0.13" @@ -76,9 +76,6 @@ libpulse-simple-binding = "2.24" libpulse-binding = "2.25" rust-pulsectl = { git = "https://github.com/open-trade/pulsectl" } -[target.'cfg(not(any(target_os = "windows", target_os = "android", target_os = "ios")))'.dependencies] -psutil = { version = "3.2", features = [ "process" ], git = "https://github.com/open-trade/rust-psutil" } - [target.'cfg(target_os = "android")'.dependencies] android_logger = "0.10" diff --git a/libs/hbb_common/Cargo.toml b/libs/hbb_common/Cargo.toml index d1868f5b5..b8a8258cf 100644 --- a/libs/hbb_common/Cargo.toml +++ b/libs/hbb_common/Cargo.toml @@ -30,6 +30,7 @@ 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" diff --git a/libs/hbb_common/src/lib.rs b/libs/hbb_common/src/lib.rs index 10975e573..79f72b136 100644 --- a/libs/hbb_common/src/lib.rs +++ b/libs/hbb_common/src/lib.rs @@ -27,12 +27,13 @@ pub use anyhow::{self, bail}; pub use futures_util; pub mod config; pub mod fs; +pub use mac_address; 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; @@ -185,6 +186,17 @@ pub fn get_version_number(v: &str) -> i64 { n } +pub fn get_process(pid: i32) -> Option { + use sysinfo::{System, SystemExt}; + let mut sys = System::new(); + sys.refresh_processes(); + sys.process(pid).cloned() +} + +pub fn get_current_process() -> Option { + get_process(std::process::id() as _) +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/ipc.rs b/src/ipc.rs index 8bd206f67..6c3f87478 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -298,16 +298,16 @@ 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::().unwrap_or(0); if pid > 0 { - if let Ok(p) = psutil::process::Process::new(pid as _) { - if let Ok(current) = psutil::process::Process::current() { - if current.name().unwrap_or("".to_owned()) == p.name().unwrap_or("".to_owned()) - { + if let Some(p) = hbb_common::get_process(pid) { + if let Some(current) = hbb_common::get_current_process() { + if current.name() == p.name() { // double check with connect if connect(1000, postfix).await.is_ok() { return; diff --git a/src/server.rs b/src/server.rs index b2ec31bc3..fdba83b14 100644 --- a/src/server.rs +++ b/src/server.rs @@ -275,18 +275,6 @@ pub async fn start_server(is_server: bool, _tray: bool) { log::info!("XAUTHORITY={:?}", std::env::var("XAUTHORITY")); } - #[cfg(target_os = "macos")] - { - loop { - if crate::platform::macos::is_installed_daemon(false) { - break; - } - - sleep(1.0).await; - } - sync_and_watch_config_dir().await; - } - if is_server { std::thread::spawn(move || { if let Err(err) = crate::ipc::start("") { @@ -295,6 +283,8 @@ pub async fn start_server(is_server: bool, _tray: bool) { } }); input_service::fix_key_down_timeout_loop(); + #[cfg(target_os = "macos")] + tokio::spawn(async { sync_and_watch_config_dir().await }); crate::RendezvousMediator::start_all().await; } else { match crate::ipc::connect(1000, "").await {