X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fxdsserver%2Fapiv1-exec.go;h=57ea1f1ca1bed762a3a0f41c410b4a6d643a547a;hb=17812a0a4388ab0c87084ef7e8118d87e8fadcf7;hp=2337de61bc18b10366fa49adfd939398fbbf3046;hpb=2a7a112bbffcd41a3436c086f1910ea7a9c94744;p=src%2Fxds%2Fxds-server.git diff --git a/lib/xdsserver/apiv1-exec.go b/lib/xdsserver/apiv1-exec.go index 2337de6..57ea1f1 100644 --- a/lib/xdsserver/apiv1-exec.go +++ b/lib/xdsserver/apiv1-exec.go @@ -136,6 +136,7 @@ func (s *APIService) execCmd(c *gin.Context) { // Create new execution over WS context execWS := eows.New(strings.Join(cmd, " "), cmdArgs, sop, sess.ID, args.CmdID) execWS.Log = s.Log + execWS.OutSplit = eows.SplitChar // Append client project dir to environment execWS.Env = append(args.Env, "CLIENT_PROJECT_DIR="+prj.ClientPath) @@ -151,14 +152,17 @@ func (s *APIService) execCmd(c *gin.Context) { // Define callback for input (stdin) execWS.InputEvent = xsapiv1.ExecInEvent - execWS.InputCB = func(e *eows.ExecOverWS, stdin string) (string, error) { + execWS.InputCB = func(e *eows.ExecOverWS, bStdin []byte) ([]byte, error) { + + stdin := string(bStdin) + s.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 + return []byte{}, errMsg } // Set correct path @@ -171,16 +175,19 @@ func (s *APIService) execCmd(c *gin.Context) { // Translate paths from client to server stdin = (*f).ConvPathCli2Svr(stdin) } - - return stdin, nil + return []byte(stdin), nil } // Define callback for output (stdout+stderr) - execWS.OutputCB = func(e *eows.ExecOverWS, stdout, stderr string) { + execWS.OutputCB = func(e *eows.ExecOverWS, bStdout, bStderr []byte) { + + stdout := string(bStdout) + stderr := string(bStderr) + // IO socket can be nil when disconnected so := s.sessions.IOSocketGet(e.Sid) if so == nil { - s.Log.Infof("%s not emitted: WS closed (sid:%s, msgid:%s)", xsapiv1.ExecOutEvent, e.Sid, e.CmdID) + s.Log.Infof("%s not emitted: WS closed (sid:%s, CmdID:%s)", xsapiv1.ExecOutEvent, e.Sid, e.CmdID) return }