X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fagent%2Fapiv1-exec.go;h=3cb4d234d51f14ebfc94e1d3ce2d288d09a7e0ae;hb=4d843d2bde236ec23810d0904dfb8aebbc53a37b;hp=c1992675df7688f7308b55cb9271cd6b4aac133b;hpb=38c0c21a969e621c725245ce91c78e77076c5ce7;p=src%2Fxds%2Fxds-agent.git diff --git a/lib/agent/apiv1-exec.go b/lib/agent/apiv1-exec.go index c199267..3cb4d23 100644 --- a/lib/agent/apiv1-exec.go +++ b/lib/agent/apiv1-exec.go @@ -5,15 +5,13 @@ import ( "io/ioutil" "net/http" + "github.com/franciscocpg/reflectme" "github.com/gin-gonic/gin" "github.com/iotbzh/xds-agent/lib/apiv1" common "github.com/iotbzh/xds-common/golib" uuid "github.com/satori/go.uuid" ) -var execCmdID = 1 -var fwdFuncID []uuid.UUID - // ExecCmd executes remotely a command func (s *APIService) execCmd(c *gin.Context) { s._execRequest("/exec", c) @@ -81,6 +79,7 @@ func (s *APIService) _execRequest(cmd string, c *gin.Context) { apiv1.ExecInferiorOutEvent, } + var fwdFuncID []uuid.UUID for _, evName := range evtList { evN := evName fwdFunc := func(pData interface{}, evData interface{}) error { @@ -92,6 +91,9 @@ func (s *APIService) _execRequest(cmd string, c *gin.Context) { return nil } + // Add sessionID to event Data + reflectme.SetField(evData, "sessionID", sid) + // Forward event to Client/Dashboard (*so).Emit(evN, evData) return nil @@ -110,15 +112,17 @@ func (s *APIService) _execRequest(cmd string, c *gin.Context) { evN := apiv1.ExecExitEvent sid := pData.(string) + // Add sessionID to event Data + reflectme.SetField(evData, "sessionID", sid) + // IO socket can be nil when disconnected so := s.sessions.IOSocketGet(sid) - if so == nil { + if so != nil { + (*so).Emit(evN, evData) + } else { s.Log.Infof("%s not emitted: WS closed (sid:%s)", evN, sid) - return nil } - (*so).Emit(evN, evData) - // cleanup listener for i, evName := range evtList { svr.EventOff(evName, fwdFuncID[i])