X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fxdsserver%2Fapiv1-exec.go;h=5efef2a968025220a961136abce99333a60c692f;hb=5dc2ff003106f0ced38caadb06033f24c792f9b9;hp=bc45fdbd881de57c7c60c4bb02c708183089fc7e;hpb=963931e04d44a5b40d38817163f52f56241a9f33;p=src%2Fxds%2Fxds-server.git diff --git a/lib/xdsserver/apiv1-exec.go b/lib/xdsserver/apiv1-exec.go index bc45fdb..5efef2a 100644 --- a/lib/xdsserver/apiv1-exec.go +++ b/lib/xdsserver/apiv1-exec.go @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 "IoT.bzh" + * Copyright (C) 2017-2018 "IoT.bzh" * Author Sebastien Douheret * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,10 +26,10 @@ import ( "strings" "time" + common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/eows" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xsapiv1" "github.com/gin-gonic/gin" - common "github.com/iotbzh/xds-common/golib" - "github.com/iotbzh/xds-common/golib/eows" - "github.com/iotbzh/xds-server/lib/xsapiv1" "github.com/kr/pty" ) @@ -83,6 +83,15 @@ func (s *APIService) execCmd(c *gin.Context) { // Build command line cmd := []string{} + + // Reset by default LD_LIBRARY_PATH + // With new AGL SDK, New environment-setup-*-agl-linux file checks if + // LD_LIBRARY_PATH is set or not and not empty LD_LIBRARY_PATH is considered + // as misconfigured and prevent to use SDK + if !args.LdLibPathNoReset { + cmd = append(cmd, "unset LD_LIBRARY_PATH; ") + } + // Setup env var regarding Sdk ID (used for example to setup cross toolchain) if envCmd := s.sdks.GetEnvCmd(args.SdkID, prj.DefaultSdk); len(envCmd) > 0 { cmd = append(cmd, envCmd...) @@ -136,6 +145,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 +161,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 +184,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 } @@ -254,6 +270,7 @@ func (s *APIService) execCmd(c *gin.Context) { execWS.ExitCB = func(e *eows.ExecOverWS, code int, err error) { s.Log.Debugf("Command [Cmd ID %s] exited: code %d, error: %v", e.CmdID, code, err) + defer LockXdsUpdateCounter(s.Context, false) // Close client tty defer func() { if gdbPty != nil { @@ -323,8 +340,10 @@ func (s *APIService) execCmd(c *gin.Context) { // Start command execution s.Log.Infof("Execute [Cmd ID %s]: %v %v", execWS.CmdID, execWS.Cmd, execWS.Args) + LockXdsUpdateCounter(s.Context, true) err = execWS.Start() if err != nil { + LockXdsUpdateCounter(s.Context, false) common.APIError(c, err.Error()) return }