Skip to content

Commit

Permalink
Merge pull request #1522 from gravitational/rjones/fix-term
Browse files Browse the repository at this point in the history
Consolidated terminal type handling.
  • Loading branch information
russjones authored Dec 21, 2017
2 parents ca7f859 + 3b51d60 commit 6f255fd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
1 change: 0 additions & 1 deletion lib/client/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func (ns *NodeSession) interactiveSession(callback interactiveCallback) error {
if termType == "" {
termType = teleport.SafeTerminalType
}
ns.env["TERM"] = termType
// create the server-side session:
sess, err := ns.createServerSession()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions lib/srv/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ func prepareCommand(ctx *ServerContext) (*exec.Cmd, error) {
for n, v := range ctx.env {
c.Env = append(c.Env, fmt.Sprintf("%s=%s", n, v))
}
// if a terminal was allocated, apply terminal type variable
if ctx.session != nil {
c.Env = append(c.Env, fmt.Sprintf("TERM=%v", ctx.session.term.GetTermType()))
}

// apply SSH_xx environment variables
remoteHost, remotePort, err := net.SplitHostPort(ctx.Conn.RemoteAddr().String())
if err != nil {
Expand Down
30 changes: 24 additions & 6 deletions lib/srv/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ type Terminal interface {
// and avoid extra system call.
GetTerminalParams() rsession.TerminalParams

// SetTermType sets the terminal type from "pty-req"
SetTermType(string)

// SetTerminalModes sets the terminal modes from "pty-req"
SetTerminalModes(ssh.TerminalModes)

// GetTermType gets the terminal type set in "pty-req"
GetTermType() string

// SetTermType sets the terminal type from "pty-req"
SetTermType(string)
}

// NewTerminal returns a new terminal. Terminal can be local or remote
Expand Down Expand Up @@ -113,7 +116,8 @@ type terminal struct {
pty *os.File
tty *os.File

params rsession.TerminalParams
termType string
params rsession.TerminalParams
}

// NewLocalTerminal creates and returns a local PTY.
Expand Down Expand Up @@ -277,11 +281,17 @@ func (t *terminal) GetTerminalParams() rsession.TerminalParams {
return t.params
}

// GetTermType gets the terminal type set in "pty-req"
func (t *terminal) GetTermType() string {
return t.termType
}

// SetTermType sets the terminal type from "req-pty" request.
func (t *terminal) SetTermType(term string) {
if t.cmd != nil {
t.cmd.Env = append(t.cmd.Env, "TERM="+term)
if term == "" {
term = defaultTerm
}
t.termType = term
}

func (t *terminal) SetTerminalModes(termModes ssh.TerminalModes) {
Expand Down Expand Up @@ -465,7 +475,15 @@ func (t *remoteTerminal) GetTerminalParams() rsession.TerminalParams {
return t.params
}

// GetTermType gets the terminal type set in "pty-req"
func (t *remoteTerminal) GetTermType() string {
return t.termType
}

func (t *remoteTerminal) SetTermType(term string) {
if term == "" {
term = defaultTerm
}
t.termType = term
}

Expand Down
2 changes: 1 addition & 1 deletion lib/srv/termhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (t *TermHandlers) HandlePTYReq(ch ssh.Channel, req *ssh.Request, ctx *Serve
if err != nil {
return trace.Wrap(err)
}
ctx.Debugf("Requested terminal of size %v", *params)
ctx.Debugf("Requested terminal %q of size %v", ptyRequest.Env, *params)

// get an existing terminal or create a new one
term := ctx.GetTerm()
Expand Down

0 comments on commit 6f255fd

Please sign in to comment.