Skip to content

Commit

Permalink
fix(rule): upgrade some dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lemos1235 committed Dec 10, 2024
1 parent 24b10bd commit 5a96c75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions leaf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ warp = { version = "0.3", default-features = false, optional = true }
notify = { version = "6", optional = true }

# Process
netstat2 = "0.9.1"
sysinfo = "0.28.4"
netstat2 = "0.11.0"
sysinfo = "0.33.0"

[target.'cfg(target_os = "android")'.dependencies]
jni = "0.21"
Expand Down
17 changes: 12 additions & 5 deletions leaf/src/app/process_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex};

use lazy_static::lazy_static;
use netstat2::{get_sockets_info, AddressFamilyFlags, ProtocolFlags, SocketInfo};
use sysinfo::{Pid, ProcessExt, ProcessRefreshKind, System, SystemExt};
use sysinfo::{Pid, ProcessRefreshKind, ProcessesToUpdate, System};

lazy_static! {
static ref SYSTEM: Arc<Mutex<System>> = {
Expand All @@ -24,10 +24,15 @@ impl ProcessInfo {
fn from_socket_info(socket_info: SocketInfo) -> Option<Self> {
let pid = socket_info.associated_pids.first()?.to_owned();
let mut system = SYSTEM.lock().ok()?;
let mut process = system.process(Pid::from(pid.to_owned() as usize));
let the_pid = Pid::from(pid.to_owned() as usize);
let mut process = system.process(the_pid);
if process.is_none() {
system.refresh_processes_specifics(ProcessRefreshKind::default());
process = system.process(Pid::from(pid.to_owned() as usize));
system.refresh_processes_specifics(
ProcessesToUpdate::Some(&[the_pid]),
true,
ProcessRefreshKind::default(),
);
process = system.process(the_pid);
}
let process = process?;
let name = process.name().to_owned();
Expand Down Expand Up @@ -65,7 +70,9 @@ fn get_socket_info(protocol: &str, ip: &IpAddr, port: u16) -> Option<SocketInfo>
.or_else(|| {
let new_sockets = get_sockets_info(af_flags, proto_flags).unwrap_or_default();
*cache = Some(new_sockets.clone());
new_sockets.into_iter().find(|p| p.local_addr() == ip.to_owned() && p.local_port() == port)
new_sockets
.into_iter()
.find(|p| p.local_addr() == ip.to_owned() && p.local_port() == port)
})
}

Expand Down

0 comments on commit 5a96c75

Please sign in to comment.