Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin shouldn't try to update DISPLAY in terminals with commands running #6

Open
gdevenyi opened this issue Sep 20, 2023 · 4 comments

Comments

@gdevenyi
Copy link

I reattached to a terminal running a long-running process:

 1DIAGNOSTIC,    18, -7.935733157733e-01, 1.406903197646e-04, 2.0919e+02, 2.8901e+00,
 1DIAGNOSTIC,    19, -7.937877553669e-01, 1.257404152091e-04, 2.1222e+02, 3.0357e+00,
 1DIAGNOSTIC,    20, -7.939809356403e-01, 1.071559425018e-04, 2.1510e+02, 2.8797e+00,
 1DIAGNOSTIC,    21, -7.941505775429e-01, 9.199177494057e-05, 2.1806e+02, 2.9602e+00,
 1DIAGNOSTIC,    22, -7.943189270297e-01, 7.959182752991e-05, 2.2100e+02, 2.9360e+00,
 1DIAGNOSTIC,    23, -7.944663358188e-01, 6.925990685979e-05, 2.2397e+02, 2.9742e+00,
export DISPLAY=localhost:10.0
^Y^E 1DIAGNOSTIC,    24, -7.945946343480e-01, 6.038876707249e-05, 2.2694e+02, 2.9681e+00,
 1DIAGNOSTIC,    25, -7.947273889852e-01, 5.318326378018e-05, 2.2987e+02, 2.9348e+00,
 1DIAGNOSTIC,    26, -7.948426131488e-01, 4.708124614868e-05, 2.3282e+02, 2.9503e+00,
 1DIAGNOSTIC,    27, -7.949588066154e-01, 4.187493615680e-05, 2.3594e+02, 3.1119e+00,
 1DIAGNOSTIC,    28, -7.950441584962e-01, 3.711652228192e-05, 2.3891e+02, 2.9699e+00,
 1DIAGNOSTIC,    29, -7.951499278730e-01, 3.321119810994e-05, 2.4190e+02, 2.9899e+00,
 1DIAGNOSTIC,    30, -7.952380088433e-01, 2.984903517993e-05, 2.4477e+02, 2.8709e+00,

Probably shouldn't happen. Not sure if tmux can wait?

@lljbash
Copy link
Owner

lljbash commented Oct 9, 2023

It shouldn't happen when the current process is not bash/zsh/vim.

What process are you running and what's the output of

tmux list-panes -s -F "#{session_name}:#{window_index}.#{pane_index} #{pane_current_command}"

when you are running the process?

@gdevenyi
Copy link
Author

The problem appears to be that I'm running a bash script:

tmux list-panes -s -F "#{session_name}:#{window_index}.#{pane_index} #{pane_current_command}"
0:1.1 bash
0:2.1 ssh
0:3.1 bash
0:4.1 tmux

pane 0:1.1 is running a script which has #!/bin/bash and is +x, run with ./script.sh

@lljbash
Copy link
Owner

lljbash commented Oct 17, 2023

Do you have any ideas about how to fix this?

I thought of a possible solution: using #{pane_pid} and ps to figure out the actual running command (inspired by tmux/tmux#733).

@gdevenyi
Copy link
Author

I went looking and here's how I think I would do it.

  1. Find the PID of the process in the pane (usually a shell) tmux list-panes -s -F "#{session_name}:#{window_index}.#{pane_index} #{pane_pid}"
  2. Use ps to find the process tree of this PID ps -f -g<PID>
    For "interactive" shells, the PID will be the top-level:
    gdevenyi 1132575 2796022 0 11:53 pts/3 00:00:00 -bash
    For shells running something else, the process tree is deeper
UID          PID    PPID  C STIME TTY          TIME CMD
gdevenyi   1196269 2796022  0 12:36 pts/0    00:00:00 -bash
gdevenyi  1198602 1196269  0 12:37 pts/0    00:00:00 bash /tmp/test.sh
gdevenyi   1199345 1198602  0 12:38 pts/0    00:00:00 sleep 5

This I don't think will work for the following situations

  1. tmux is launched directly with some non-shell in the pane (I think you can fix this by whitelisting toplevel apps, bash, zsh, dash, fish, shell)
  2. The user launches a shell in a shell (runs zsh after bash spawns)

But I think this is at least more reliable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants