Skip to content

Commit

Permalink
bad bad
Browse files Browse the repository at this point in the history
  • Loading branch information
adgaultier committed Oct 15, 2024
1 parent da9ce24 commit b3d466f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions oryx-tui/src/pid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,13 @@ fn decode_hex_ipv4(hex_str: &str) -> AppResult<[u8; 4]> {
pub struct ConnectionsInfo {}

impl ConnectionsInfo {
pub fn get_used_inodes(tcp_map: &Arc<Mutex<IpMap>>, udp_map: &Arc<Mutex<IpMap>>) -> Vec<u32> {
pub fn get_used_inodes(tcp_map: &IpMap, udp_map: &IpMap) -> Vec<u32> {
let mut res = Vec::new();

let tcp_map = tcp_map.lock().unwrap();
for (_, conn) in tcp_map.map.iter() {
res.push(conn.inode);
}
let udp_map = udp_map.lock().unwrap();

for (_, conn) in udp_map.map.iter() {
res.push(conn.inode);
}
Expand Down Expand Up @@ -185,8 +184,8 @@ impl ConnectionsInfo {
_ => error!("error parsing tcp conn{:#?}", splits),
}
}

thread::sleep(Duration::from_secs(1));
std::mem::drop(map);
thread::sleep(Duration::from_millis(250));
}
}
});
Expand Down Expand Up @@ -216,7 +215,8 @@ impl ConnectionsInfo {
_ => error!("error parsing udp conn {:#?}", splits),
}
}
thread::sleep(Duration::from_secs(1));
std::mem::drop(map);
thread::sleep(Duration::from_millis(250));
}
}
});
Expand All @@ -225,21 +225,23 @@ impl ConnectionsInfo {
let tcp_map = tcp_map.clone();
let udp_map = udp_map.clone();
move || loop {
let inodes = Self::get_used_inodes(&tcp_map, &udp_map);
//info!("{:#?}", map);
let mut udp_map_copy = udp_map.lock().unwrap();
let mut tcp_map_copy = tcp_map.lock().unwrap();

let inodes = Self::get_used_inodes(&tcp_map_copy, &udp_map_copy);

let inode_pid_map_map = build_inode_map(inodes);
//info!("{:#?}", map);
let mut udp_map_copy = udp_map.lock().unwrap().clone();
let mut tcp_map_copy = tcp_map.lock().unwrap().clone();

for (_, conn) in udp_map_copy.map.iter_mut() {
conn.try_get_pid(&inode_pid_map_map);
}
for (_, conn) in tcp_map_copy.map.iter_mut() {
conn.try_get_pid(&inode_pid_map_map);
}

thread::sleep(Duration::from_secs(1));
std::mem::drop(udp_map_copy);
std::mem::drop(tcp_map_copy);
thread::sleep(Duration::from_millis(250));
}
});

Expand Down

0 comments on commit b3d466f

Please sign in to comment.