-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
ssh/tailssh: set pty termios settings #4146
Comments
Even if I So something beyond just the termios, it seems. |
Still not sure the exact rules of how/when/who's supposed to set these, but this works for now on making them match. Baby steps. Will research more and adjust later. Updates #4146 (but not enough to fix it, something's still wrong) Updates #3802 Change-Id: I496d8cd7e31d45fe9ede88fc8894f35dc096de67 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Still not sure the exact rules of how/when/who's supposed to set these, but this works for now on making them match. Baby steps. Will research more and adjust later. Updates #4146 (but not enough to fix it, something's still wrong) Updates #3802 Change-Id: I496d8cd7e31d45fe9ede88fc8894f35dc096de67 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Still not sure the exact rules of how/when/who's supposed to set these, but this works for now on making them match. Baby steps. Will research more and adjust later. Updates #4146 (but not enough to fix it, something's still wrong) Updates #3802 Change-Id: I496d8cd7e31d45fe9ede88fc8894f35dc096de67 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Well, with #4151 my And yet.... If I run And whenever I switch back & forth between screen windows, it goes corrupt again. Terminals!!! termcaps!! ptys!!! termios!! rawwrggh!! Any clues welcome. |
Still not sure the exact rules of how/when/who's supposed to set these, but this works for now on making them match. Baby steps. Will research more and adjust later. Updates #4146 (but not enough to fix it, something's still wrong) Updates #3802 Change-Id: I496d8cd7e31d45fe9ede88fc8894f35dc096de67 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Still not sure the exact rules of how/when/who's supposed to set these, but this works for now on making them match. Baby steps. Will research more and adjust later. Updates #4146 (but not enough to fix it, something's still wrong) Updates #3802 Change-Id: I496d8cd7e31d45fe9ede88fc8894f35dc096de67 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
@maisem has a change to do my dirty hacky properly: #4154 (it could reference this bug too) But even with the hacky hard-coded tty settings it currently does, we still see corruption in emacs+vim (even without screen or tmux involved). On a whim, I tried changing the io.Copy between the tty/pty halves to be ANSI-escape sequence aware to not split a sequence in half between writes, but that didn't help, even if it was doing one write per escape sequence. |
(Corruption happens in both macOS Terminal and iTerm2.) |
Local hack, I set the termio Clag to 189 (it was 191) to unset bit 2 (whatever that is), and now my diff --git a/ssh/tailssh/incubator.go b/ssh/tailssh/incubator.go
index 53ede705..0727190f 100644
--- a/ssh/tailssh/incubator.go
+++ b/ssh/tailssh/incubator.go
@@ -210,12 +210,12 @@ func startWithPTY(cmd *exec.Cmd, ptyReq ssh.Pty) (ptyFile *os.File, err error) {
tty.Close()
}
}()
- ptyRawConn, err := ptyFile.SyscallConn()
+ ttyRawConn, err := tty.SyscallConn()
if err != nil {
return nil, fmt.Errorf("SyscallConn: %w", err)
}
var ctlErr error
- if err := ptyRawConn.Control(func(fd uintptr) {
+ if err := ttyRawConn.Control(func(fd uintptr) {
// Load existing PTY settings to modify them & save them back.
tios, err := termios.GTTY(int(fd))
if err != nil {
@@ -249,6 +249,18 @@ func startWithPTY(cmd *exec.Cmd, ptyReq ssh.Pty) (ptyFile *os.File, err error) {
ctlErr = fmt.Errorf("STTY: %w", err)
return
}
+
+ term, err := unix.IoctlGetTermios(int(fd), unix.TCGETS)
+ if err != nil {
+ ctlErr = fmt.Errorf("unix.IoctlGetTermios: %w", err)
+ return
+ }
+ term.Cflag = 189 // *shrug* HACK HACK HACK
+ if err := unix.IoctlSetTermios(int(fd), unix.TCSETS, term); err != nil {
+ ctlErr = fmt.Errorf("unix.IoctlSetTermios: %w", err)
+ return
+ }
+
}); err != nil {
return nil, fmt.Errorf("ptyRawConn.Control: %w", err)
} And now:
... everything's identical ( But despite all that matching, Emacs shows corruption only over Tailscale SSH. |
Ah, @maisem figured it out... gliderlabs/ssh had this hack, which not only do we not need, but actively breaks us when we have the terminal properly configured: func (sess *session) Write(p []byte) (n int, err error) {
if sess.pty != nil {
m := len(p)
// normalize \n to \r\n when pty is accepted.
// this is a hardcoded shortcut since we don't support terminal modes.
p = bytes.Replace(p, []byte{'\n'}, []byte{'\r', '\n'}, -1)
p = bytes.Replace(p, []byte{'\r', '\r', '\n'}, []byte{'\r', '\n'}, -1)
n, err = sess.Channel.Write(p)
if n > m {
n = m
}
return
}
return sess.Channel.Write(p)
} Deleting all that makes it work. |
Maisem figured out the real problem but will take several commits (e.g. tailscale/ssh#2) in different repos to get it fixed properly. This is an interim hack. Details of real fix: #4146 (comment) Updates #4146 Updates #3802 Change-Id: I7b7dc5713baa3e5de75b87b69e7179a6e7549b0b Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Maisem figured out the real problem but will take several commits (e.g. tailscale/ssh#2) in different repos to get it fixed properly. This is an interim hack. Details of real fix: #4146 (comment) Updates #4146 Updates #3802 Change-Id: I7b7dc5713baa3e5de75b87b69e7179a6e7549b0b Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Didn't mean to close. |
Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
… disable it. Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
… disable it. Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
… disable it. Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
Updates #4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
Updates #4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
Updates #4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
Updates #4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
This should be fixed as of #4154 |
Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
… disable it. Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com> Co-Authored-By: Ayman Bagabas <ayman.bagabas@gmail.com>
Our SSH server isn't yet setting the pty termio settings. Using
stty -a
, you can see the difference. This Go-based JSON-supporting stty makes it easier to see:https://github.com/u-root/u-root/tree/main/cmds/core/stty
Diff from normal to ours:
(Ignore the Row/Col differences, of course)
/cc @maisem
The text was updated successfully, but these errors were encountered: