MCPcopy Index your code
hub / github.com/coder/coder / applyTerminalModesToFd

Function applyTerminalModesToFd

pty/ssh_other.go:80–128  ·  view source on GitHub ↗

applyTerminalModesToFd applies the terminal settings from the SSH request to the given fd. This is based on code from Tailscale's tailssh package: https://github.com/tailscale/tailscale/blob/main/ssh/tailssh/incubator.go

(logger *log.Logger, fd uintptr, req ssh.Pty)

Source from the content-addressed store, hash-verified

78// This is based on code from Tailscale's tailssh package:
79// https://github.com/tailscale/tailscale/blob/main/ssh/tailssh/incubator.go
80func applyTerminalModesToFd(logger *log.Logger, fd uintptr, req ssh.Pty) error {
81 // Get the current TTY configuration.
82 tios, err := termios.GTTY(int(fd))
83 if err != nil {
84 return xerrors.Errorf("GTTY: %w", err)
85 }
86
87 // Apply the modes from the SSH request.
88 tios.Row = req.Window.Height
89 tios.Col = req.Window.Width
90
91 for c, v := range req.Modes {
92 if c == gossh.TTY_OP_ISPEED {
93 tios.Ispeed = int(v)
94 continue
95 }
96 if c == gossh.TTY_OP_OSPEED {
97 tios.Ospeed = int(v)
98 continue
99 }
100 k, ok := terminalModeFlagNames[c]
101 if !ok {
102 if logger != nil {
103 logger.Printf("unknown terminal mode: %d", c)
104 }
105 continue
106 }
107 if _, ok := tios.CC[k]; ok {
108 // #nosec G115 - Safe conversion for terminal control characters which are all in the uint8 range
109 tios.CC[k] = uint8(v)
110 continue
111 }
112 if _, ok := tios.Opts[k]; ok {
113 tios.Opts[k] = v > 0
114 continue
115 }
116
117 if logger != nil {
118 logger.Printf("unsupported terminal mode: k=%s, c=%d, v=%d", k, c, v)
119 }
120 }
121
122 // Save the new TTY configuration.
123 if _, err := tios.STTY(int(fd)); err != nil {
124 return xerrors.Errorf("STTY: %w", err)
125 }
126
127 return nil
128}

Callers 1

newPtyFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected