diff options
| author | Rousseau Vincent <vincentrou@gmail.com> | 2025-07-15 10:26:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-15 10:26:43 +0200 |
| commit | 118d5fb877381d207ec7e97262df584b3f4eb606 (patch) | |
| tree | b16bbdf0c7b1dbfcaa6bd4ebfcfcdf34c04a7823 | |
| parent | fix(web-server): thread leak due to excess file watching (#4286) (diff) | |
| download | sl0ppij-118d5fb877381d207ec7e97262df584b3f4eb606.tar.gz sl0ppij-118d5fb877381d207ec7e97262df584b3f4eb606.tar.xz sl0ppij-118d5fb877381d207ec7e97262df584b3f4eb606.zip | |
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.
| -rw-r--r-- | zellij-server/src/os_input_output.rs | 14 | ||||
| -rw-r--r-- | zellij-server/src/pty.rs | 11 |
2 files changed, 18 insertions, 7 deletions
diff --git a/zellij-server/src/os_input_output.rs b/zellij-server/src/os_input_output.rs index 175ec289..a85fab6f 100644 --- a/zellij-server/src/os_input_output.rs +++ b/zellij-server/src/os_input_output.rs @@ -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 diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index 2658188b..26fe7203 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -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 { |
