ty clippy
This commit is contained in:
parent
e1c1eae897
commit
65f87d678f
1 changed files with 12 additions and 12 deletions
24
src/main.rs
24
src/main.rs
|
@ -96,16 +96,16 @@ fn get_inodes(inodes: &mut HashMap<usize, INode>) {
|
|||
};
|
||||
|
||||
let target_str = target.to_str().unwrap();
|
||||
let pid = path_str.split("/").nth(2).unwrap().parse();
|
||||
if !pid.is_ok() {
|
||||
let pid = path_str.split('/').nth(2).unwrap().parse();
|
||||
if pid.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if target_str.starts_with("socket") {
|
||||
let inode_str = target_str.splitn(2, ":").nth(1).unwrap();
|
||||
let inode_str = target_str.splitn(2, ':').nth(1).unwrap();
|
||||
let inode = inode_str[1..(inode_str.len() - 1)].parse().unwrap();
|
||||
|
||||
let mut inode = inodes.entry(inode).or_insert(INode::new());
|
||||
let mut inode = inodes.entry(inode).or_insert_with(INode::new);
|
||||
let process = Process { pid: pid.unwrap(), command_line: None };
|
||||
inode.processes.push(process);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ fn get_inodes(inodes: &mut HashMap<usize, INode>) {
|
|||
|
||||
fn get_command_lines(inodes: &mut HashMap<usize, INode>) {
|
||||
for inode in inodes.values_mut() {
|
||||
for process in inode.processes.iter_mut() {
|
||||
for process in &mut inode.processes {
|
||||
let filename = format!("/proc/{}/cmdline", process.pid);
|
||||
let file = File::open(filename).unwrap();
|
||||
let mut buffer = BufReader::new(file);
|
||||
|
@ -130,15 +130,15 @@ fn get_command_lines(inodes: &mut HashMap<usize, INode>) {
|
|||
|
||||
|
||||
fn get_addresses(inodes: &mut HashMap<usize, INode>) {
|
||||
for protocol in [Protocol::Tcp, Protocol::Udp].iter() {
|
||||
for version in ["", "6"].iter() {
|
||||
for protocol in &[Protocol::Tcp, Protocol::Udp] {
|
||||
for version in &["", "6"] {
|
||||
let filename = format!("/proc/net/{}{}", protocol, version);
|
||||
let file = File::open(filename).unwrap();
|
||||
let buffer = BufReader::new(file);
|
||||
|
||||
let connections = buffer.lines().skip(1).map(|line| line.unwrap());
|
||||
for connection in connections {
|
||||
let fields: Vec<&str> = connection.split_whitespace().collect();
|
||||
let fields: Vec<_> = connection.split_whitespace().collect();
|
||||
|
||||
let state = fields[3];
|
||||
if state != "0A" && state != "07" {
|
||||
|
@ -146,8 +146,8 @@ fn get_addresses(inodes: &mut HashMap<usize, INode>) {
|
|||
continue;
|
||||
}
|
||||
|
||||
let address: Vec<&str> = fields[1].split(":").collect();
|
||||
let ip = match version { &"6" => parse_ipv6, _ => parse_ipv4 }(address[0]);
|
||||
let address: Vec<_> = fields[1].split(':').collect();
|
||||
let ip = match *version { "6" => parse_ipv6, _ => parse_ipv4 }(address[0]);
|
||||
let port = u16::from_str_radix(address[1], 16).unwrap();
|
||||
|
||||
let inode_id = fields[9].parse().unwrap();
|
||||
|
@ -168,13 +168,13 @@ fn print_all(inodes: &HashMap<usize, INode>) {
|
|||
None => 80,
|
||||
};
|
||||
|
||||
let mut values: Vec<&INode> = inodes.values().collect();
|
||||
let mut values: Vec<_> = inodes.values().collect();
|
||||
values.sort_unstable_by(|a, b| a.processes[0].pid.cmp(&b.processes[0].pid));
|
||||
|
||||
for inode in values {
|
||||
for address in &inode.addresses {
|
||||
for (i, process) in inode.processes.iter().enumerate() {
|
||||
let command_line = process.command_line.clone().unwrap_or("".to_owned());
|
||||
let command_line = process.command_line.clone().unwrap_or_default();
|
||||
let address_str = if i == 0 { format!("{}", address) } else { String::new() };
|
||||
|
||||
let mut output = format!(
|
||||
|
|
Loading…
Reference in a new issue