Use go module as dependency tool instead of glide
[src/xds/xds-server.git] / lib / xdsserver / terminal-ssh.go
index 3f4a344..89a8b40 100644 (file)
@@ -22,8 +22,8 @@ import (
        "strings"
        "time"
 
-       "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib/eows"
-       "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
+       "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/eows"
+       "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xsapiv1"
        socketio "github.com/googollee/go-socket.io"
        uuid "github.com/satori/go.uuid"
 )
@@ -128,26 +128,19 @@ func (t *TermSSH) Open(sock *socketio.Socket, sessID string) (*xsapiv1.TerminalC
 
        t.sshWS = eows.New(cmd, args, sock, sessID, cmdID)
        t.sshWS.Log = t.Log
-       t.sshWS.OutSplit = eows.SplitChar
-       t.sshWS.PtsMode = true
+       t.sshWS.PtyMode = true
 
        // Define callback for input (stdin)
        t.sshWS.InputEvent = xsapiv1.TerminalInEvent
-       t.sshWS.InputCB = func(e *eows.ExecOverWS, stdin string) (string, error) {
-               t.Log.Debugf("STDIN <<%v>>", strings.Replace(stdin, "\n", "\\n", -1))
-
-               // Handle Ctrl-D
-               if len(stdin) == 1 && stdin == "\x04" {
-                       // Close stdin
-                       errMsg := fmt.Errorf("close stdin: %v", stdin)
-                       return "", errMsg
+       t.sshWS.InputCB = func(e *eows.ExecOverWS, stdin []byte) ([]byte, error) {
+               if t.LogLevelSilly {
+                       t.Log.Debugf("STDIN <<%v>> %s", stdin, string(stdin))
                }
-
                return stdin, nil
        }
 
        // Define callback for output (stdout+stderr)
-       t.sshWS.OutputCB = func(e *eows.ExecOverWS, stdout, stderr string) {
+       t.sshWS.OutputCB = func(e *eows.ExecOverWS, stdout, stderr []byte) {
                // IO socket can be nil when disconnected
                so := t.sessions.IOSocketGet(e.Sid)
                if so == nil {
@@ -159,12 +152,14 @@ func (t *TermSSH) Open(sock *socketio.Socket, sessID string) (*xsapiv1.TerminalC
                data := e.UserData
                termID := (*data)["ID"].(string)
 
-               t.Log.Debugf("%s emitted - WS sid[4:] %s - id:%s - termID:%s", xsapiv1.TerminalOutEvent, e.Sid[4:], e.CmdID, termID)
-               if stdout != "" {
-                       t.Log.Debugf("STDOUT <<%v>>", strings.Replace(stdout, "\n", "\\n", -1))
-               }
-               if stderr != "" {
-                       t.Log.Debugf("STDERR <<%v>>", strings.Replace(stderr, "\n", "\\n", -1))
+               if t.LogLevelSilly {
+                       t.Log.Debugf("%s emitted - WS sid[4:] %s - id:%s - termID:%s", xsapiv1.TerminalOutEvent, e.Sid[4:], e.CmdID, termID)
+                       if len(stdout) > 0 {
+                               t.Log.Debugf("STDOUT <<%v>>", strings.Replace(string(stdout), "\n", "\\n", -1))
+                       }
+                       if len(stderr) > 0 {
+                               t.Log.Debugf("STDERR <<%v>>", strings.Replace(string(stderr), "\n", "\\n", -1))
+                       }
                }
 
                // FIXME replace by .BroadcastTo a room
@@ -228,13 +223,15 @@ func (t *TermSSH) Open(sock *socketio.Socket, sessID string) (*xsapiv1.TerminalC
 
 // Close a terminal
 func (t *TermSSH) Close() (*xsapiv1.TerminalConfig, error) {
-       // nothing to do when not open
-       if t.termCfg.Status != xsapiv1.StatusTermOpen {
+       // nothing to do when not open or closing
+       if !(t.termCfg.Status == xsapiv1.StatusTermOpen || t.termCfg.Status == xsapiv1.StatusTermClosing) {
                return &t.termCfg, nil
        }
 
        err := t.sshWS.Signal("SIGTERM")
 
+       t.termCfg.Status = xsapiv1.StatusTermClosing
+
        return &t.termCfg, err
 }
 
@@ -251,6 +248,8 @@ func (t *TermSSH) Resize(cols, rows uint16) (*xsapiv1.TerminalConfig, error) {
                t.termCfg.Rows = rows
        }
 
+       t.LogSillyf("Terminal resize id=%v, cols=%v, rows=%v", t.termCfg.ID, cols, rows)
+
        err := t.sshWS.TerminalSetSize(t.termCfg.Rows, t.termCfg.Cols)
        if err != nil {
                t.Log.Errorf("Error ssh TerminalSetSize: %v", err)