fix: populate layount metadata with the right cmd and cwd (#4287)
Add cmd from sysinfo in terminal_ids_to_commands if no cmd are return by ps. So then, cmd and cwd are udpated in "session-layout.kdl" even if no cmd is runing in pane.
This commit is contained in:
parent
fd90067e7b
commit
118d5fb877
2 changed files with 18 additions and 7 deletions
|
|
@ -508,8 +508,8 @@ pub trait ServerOsApi: Send + Sync {
|
|||
/// Returns the current working directory for a given pid
|
||||
fn get_cwd(&self, pid: Pid) -> Option<PathBuf>;
|
||||
/// Returns the current working directory for multiple pids
|
||||
fn get_cwds(&self, _pids: Vec<Pid>) -> HashMap<Pid, PathBuf> {
|
||||
HashMap::new()
|
||||
fn get_cwds(&self, _pids: Vec<Pid>) -> (HashMap<Pid, PathBuf>, HashMap<Pid, Vec<String>>) {
|
||||
(HashMap::new(), HashMap::new())
|
||||
}
|
||||
/// Get a list of all running commands by their parent process id
|
||||
fn get_all_cmds_by_ppid(&self, _post_hook: &Option<String>) -> HashMap<String, Vec<String>> {
|
||||
|
|
@ -755,9 +755,10 @@ impl ServerOsApi for ServerOsInputOutput {
|
|||
None
|
||||
}
|
||||
|
||||
fn get_cwds(&self, pids: Vec<Pid>) -> HashMap<Pid, PathBuf> {
|
||||
fn get_cwds(&self, pids: Vec<Pid>) -> (HashMap<Pid, PathBuf>, HashMap<Pid, Vec<String>>) {
|
||||
let mut system_info = System::new();
|
||||
let mut cwds = HashMap::new();
|
||||
let mut cmds = HashMap::new();
|
||||
|
||||
for pid in pids {
|
||||
// Update by minimizing information.
|
||||
|
|
@ -767,15 +768,20 @@ impl ServerOsApi for ServerOsInputOutput {
|
|||
if is_found {
|
||||
if let Some(process) = system_info.process(pid.into()) {
|
||||
let cwd = process.cwd();
|
||||
let cmd = process.cmd();
|
||||
let cwd_is_empty = cwd.iter().next().is_none();
|
||||
if !cwd_is_empty {
|
||||
cwds.insert(pid, process.cwd().to_path_buf());
|
||||
}
|
||||
let cmd_is_empty = cmd.iter().next().is_none();
|
||||
if !cmd_is_empty {
|
||||
cmds.insert(pid, process.cmd().to_vec());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cwds
|
||||
(cwds, cmds)
|
||||
}
|
||||
fn get_all_cmds_by_ppid(&self, post_hook: &Option<String>) -> HashMap<String, Vec<String>> {
|
||||
// the key is the stringified ppid
|
||||
|
|
|
|||
|
|
@ -1425,7 +1425,7 @@ impl Pty {
|
|||
.filter_map(|id| self.id_to_child_pid.get(&id))
|
||||
.map(|pid| Pid::from_raw(*pid))
|
||||
.collect();
|
||||
let pids_to_cwds = self
|
||||
let (pids_to_cwds, pids_to_cmds) = self
|
||||
.bus
|
||||
.os_input
|
||||
.as_ref()
|
||||
|
|
@ -1443,10 +1443,15 @@ impl Pty {
|
|||
let cwd = process_id
|
||||
.as_ref()
|
||||
.and_then(|pid| pids_to_cwds.get(&Pid::from_raw(**pid)));
|
||||
let cmd = process_id
|
||||
let cmd_sysinfo = process_id
|
||||
.as_ref()
|
||||
.and_then(|pid| pids_to_cmds.get(&Pid::from_raw(**pid)));
|
||||
let cmd_ps = process_id
|
||||
.as_ref()
|
||||
.and_then(|pid| ppids_to_cmds.get(&format!("{}", pid)));
|
||||
if let Some(cmd) = cmd {
|
||||
if let Some(cmd) = cmd_ps {
|
||||
terminal_ids_to_commands.insert(terminal_id, cmd.clone());
|
||||
} else if let Some(cmd) = cmd_sysinfo {
|
||||
terminal_ids_to_commands.insert(terminal_id, cmd.clone());
|
||||
}
|
||||
if let Some(cwd) = cwd {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue