mirror of
https://github.com/uutils/procps.git
synced 2026-05-06 06:06:43 -04:00
top: tui impl ^u (show supp group)
This commit is contained in:
@@ -432,6 +432,33 @@ fn mem(pid: u32, _stat: Stat) -> Box<dyn Column> {
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) fn get_supplementary_groups(pid: u32) -> String {
|
||||
use sysinfo::{Gid, Groups};
|
||||
let groups = Groups::new_with_refreshed_list();
|
||||
let path = PathBuf::from_str(&format!("/proc/{pid}/status")).unwrap();
|
||||
if let Ok(file) = File::open(path) {
|
||||
let content = read_to_string(file).unwrap();
|
||||
for line in content.lines() {
|
||||
if line.starts_with("Groups:") {
|
||||
let groups = line
|
||||
.split_whitespace()
|
||||
.skip(1)
|
||||
.filter_map(|s| Gid::from_str(s).ok())
|
||||
.filter_map(|gid| groups.iter().find(|g| g.id() == &gid))
|
||||
.map(|group| group.name())
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
String::new()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) fn get_cgroup(pid: u32) -> String {
|
||||
let path = PathBuf::from_str(&format!("/proc/{pid}/cgroup")).unwrap();
|
||||
if let Ok(file) = File::open(path) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// file that was distributed with this source code.
|
||||
|
||||
use crate::header::Header;
|
||||
use crate::picker::{get_cgroup, get_command};
|
||||
use crate::picker::get_command;
|
||||
use crate::platform::get_numa_nodes;
|
||||
use crate::tui::stat::{CpuValueMode, TuiStat};
|
||||
use crate::Filter::{EUser, User};
|
||||
@@ -98,6 +98,7 @@ pub fn handle_input(
|
||||
data.write().unwrap().1 = ProcList::new(settings, &tui_stat.read().unwrap());
|
||||
should_update.store(true, Ordering::Relaxed);
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
Event::Key(KeyEvent {
|
||||
code: KeyCode::Char('g'),
|
||||
modifiers: KeyModifiers::CONTROL,
|
||||
@@ -121,7 +122,7 @@ pub fn handle_input(
|
||||
pid,
|
||||
get_command(pid, false)
|
||||
);
|
||||
let content = get_cgroup(pid);
|
||||
let content = crate::picker::get_cgroup(pid);
|
||||
data.2 = Some(InfoBar { title, content });
|
||||
}
|
||||
should_update.store(true, Ordering::Relaxed);
|
||||
@@ -199,6 +200,35 @@ pub fn handle_input(
|
||||
stat.cpu_graph_mode = stat.cpu_graph_mode.next();
|
||||
should_update.store(true, Ordering::Relaxed);
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
Event::Key(KeyEvent {
|
||||
code: KeyCode::Char('u'),
|
||||
modifiers: KeyModifiers::CONTROL,
|
||||
..
|
||||
}) => {
|
||||
let mut data = data.write().unwrap();
|
||||
if data.2.is_some() {
|
||||
data.2 = None;
|
||||
} else {
|
||||
let tui_stat = tui_stat.read().unwrap();
|
||||
let mut nth = tui_stat.list_offset;
|
||||
if data.1.collected.is_empty() {
|
||||
return false;
|
||||
}
|
||||
if data.1.collected.len() <= nth {
|
||||
nth = data.1.collected.len() - 1;
|
||||
}
|
||||
let pid = data.1.collected[nth].0;
|
||||
let title = format!(
|
||||
"supplementary groups for pid {}, {}",
|
||||
pid,
|
||||
get_command(pid, false)
|
||||
);
|
||||
let content = crate::picker::get_supplementary_groups(pid);
|
||||
data.2 = Some(InfoBar { title, content });
|
||||
}
|
||||
should_update.store(true, Ordering::Relaxed);
|
||||
}
|
||||
char!('U') => {
|
||||
let mut stat = tui_stat.write().unwrap();
|
||||
stat.input_label = "Which user (blank for all) ".into();
|
||||
|
||||
Reference in New Issue
Block a user