tmux-resurrect
tmux-resurrect copied to clipboard
resurrect-processes does not play well with `tmux split-window <cmd>`
reproduction steps:
- open a new session of tmux
- run
tmux split-window vim - save the session (e.g.
<prefix> C-s) - exit the session with
tmux kill-server - enter a new session
- restore the session (e.g.
<prefix> C-r)
the pane containing the command is correctly restored, but the process running inside it is not. this is especially confusing when resurrect-capture-pane-contents is enabled, as it looks like the process is running, but it's not.
here is the contents of the state file:
; cat /home/jyn/.local/share/tmux/resurrect/tmux_resurrect_20240813T184703.txt
pane 3 0 1 :* 0 pop-os :/home/jyn/src/tmux 0 zsh :
pane 3 0 1 :* 1 pop-os :/home/jyn/src/tmux 1 vi :
window 3 0 :tmux (vi) 1 :* b187,174x42,0,0[174x21,0,0,4,174x20,0,22,5] :
state 3
it looks like pane_full_command isn't being saved properly, even though pane_command is correct?
it turns out the ps.sh save strategy doesn't work, because ps -a ignores processes without an associated terminal. if i replace full_command with this script:
ps --ppid ${PANE_PID} -o args | tail -n +2
then everything works fine. i'll make a PR with that change.
hmm. no, it's a little more complicated than that. my fix there only works if you pass the script the PID of the tmux server. but when restoring, resurrect needs to know the PID running in that pane, it can't indiscriminately spawn every process at once. the way it normally does that is to take the output of tmux list-panes -F "#{pane_pid}" and look for all the children of that process with a controlling terminal, because that process is normally a shell. but in this case it's not a shell, it's a regular editor, so it has no children.
i am not quite sure what the correct fix is. maybe if there are no children with a controlling terminal, we can fall back to the parent process?