Skip to content

Commit c39e73e

Browse files
Maisem Alimafredri
Maisem Ali
authored andcommitted
document behavior of NL to CRNL translation in Write and add a way to disable it.
Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <maisem@tailscale.com>
1 parent 517184b commit c39e73e

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

session.go

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ type Session interface {
8282
// the request handling loop. Registering nil will unregister the channel.
8383
// During the time that no channel is registered, breaks are ignored.
8484
Break(c chan<- bool)
85+
86+
// DisablePTYEmulation disables the session's default minimal PTY emulation.
87+
// If you're setting the pty's termios settings from the Pty request, use
88+
// this method to avoid corruption.
89+
// Currently (2022-03-12) the only emulation implemented is NL-to-CRNL translation (`\n`=>`\r\n`).
90+
// A call of DisablePTYEmulation must precede any call to Write.
91+
DisablePTYEmulation()
8592
}
8693

8794
// maxSigBufSize is how many signals will be buffered
@@ -109,26 +116,31 @@ func DefaultSessionHandler(srv *Server, conn *gossh.ServerConn, newChan gossh.Ne
109116
type session struct {
110117
sync.Mutex
111118
gossh.Channel
112-
conn *gossh.ServerConn
113-
handler Handler
114-
subsystemHandlers map[string]SubsystemHandler
115-
handled bool
116-
exited bool
117-
pty *Pty
118-
winch chan Window
119-
env []string
120-
ptyCb PtyCallback
121-
sessReqCb SessionRequestCallback
122-
rawCmd string
123-
subsystem string
124-
ctx Context
125-
sigCh chan<- Signal
126-
sigBuf []Signal
127-
breakCh chan<- bool
119+
conn *gossh.ServerConn
120+
handler Handler
121+
subsystemHandlers map[string]SubsystemHandler
122+
handled bool
123+
exited bool
124+
pty *Pty
125+
winch chan Window
126+
env []string
127+
ptyCb PtyCallback
128+
sessReqCb SessionRequestCallback
129+
rawCmd string
130+
subsystem string
131+
ctx Context
132+
sigCh chan<- Signal
133+
sigBuf []Signal
134+
breakCh chan<- bool
135+
disablePtyEmulation bool
136+
}
137+
138+
func (sess *session) DisablePTYEmulation() {
139+
sess.disablePtyEmulation = true
128140
}
129141

130142
func (sess *session) Write(p []byte) (n int, err error) {
131-
if sess.pty != nil {
143+
if sess.pty != nil && !sess.disablePtyEmulation {
132144
m := len(p)
133145
// normalize \n to \r\n when pty is accepted.
134146
// this is a hardcoded shortcut since we don't support terminal modes.

0 commit comments

Comments
 (0)