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

Vterm fails to get tty when invoking tmux, but only when vterm is started in a remote location #569

Open
mtekman opened this issue Jan 14, 2022 · 4 comments

Comments

@mtekman
Copy link

mtekman commented Jan 14, 2022

Issue

If you start vterm from a remote org-mode document, then it spawns a remote shell at that location (which is fantastic!)

However, if you try to access a tmux session via vterm, then it fails with the error:

open terminal failed: can't use /dev/tty

You can get around this however by spawning vterm locally, and then ssh-ing into the machine, and then running tmux, which will work successfully

Steps to reproduce

  1. Within emacs, in a remote document spawn vterm
  2. Run tmux new-session -t test
  3. Witness error message

Steps to work around

  1. Within Emacs, in a local document spawn vterm
  2. SSH into the remote machine from this vterm buffer
  3. Run tmux new-session -t test
  4. Witness no error message

Is it to do with the SSH_CONNECTION being the same one that Tramp uses?

@jixiuf
Copy link
Collaborator

jixiuf commented Jan 15, 2022

Maybe it's a bug of tmux,
see https://unix.stackexchange.com/questions/404173/shell-command-tmux-throws-cant-use-dev-tty-error/512979

( exec </dev/tty; exec <&1; tmux )

works for me.

@ning-y
Copy link

ning-y commented Feb 21, 2022

I have the same issue. The fix does work for vterm/tmux, but if I use other terminal emulators, I do not run into the /dev/tty error to begin with.

Don't know enough to comment if its a vterm or tmux bug, though.

@raymond-w-ko
Copy link

I did some investigation and I think this is a tramp feature/bug. The issue happens here: tramp-sh.el

tramp has something called heredoc, which is used to support arguments that exceed command line length.

However, when it thinks it need heredoc it changes stdin (0) to /dev/tty here unconditionally, resulting in mismatched fd 0 vs fd 1 and 2.

I have only started learning Emacs like a few weeks ago, so I have no idea it doing this is a good or bad thing.

Thankfully there is a simple workaround. When it determines if it should enter heredoc mode, it checks is the program argument is surrounded by single quotes, so you can do something like this:

(setq vterm-tramp-shells '(("docker" "sh")
                           ("ssh" "'zsh'")))

Now tmux works!

In fact, this probably should be the default along with sshx (and maybe all the *sh) once someone more experienced than me has checked this reasoning.

@aramirezreyes
Copy link

Thanks for the insights! Both @raymond-w-ko and @jixiuf solutions work.

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

5 participants