From 7258c1445052df00754185538fe1c11b1af519ed Mon Sep 17 00:00:00 2001 From: Daniel Huckins Date: Tue, 23 May 2023 16:20:17 -0400 Subject: [PATCH] add diff channels back Signed-off-by: Daniel Huckins --- command/agent/exec/exec.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/command/agent/exec/exec.go b/command/agent/exec/exec.go index 0f8c4fcc20eb..ecdc5886b2d8 100644 --- a/command/agent/exec/exec.go +++ b/command/agent/exec/exec.go @@ -63,7 +63,7 @@ type Server struct { childProcessState childProcessState // exit channel of the child process - childProcessExitCh <-chan int + childProcessExitCh chan int } type ProcessExitError struct { @@ -76,9 +76,10 @@ func (e *ProcessExitError) Error() string { func NewServer(cfg *ServerConfig) *Server { server := Server{ - logger: cfg.Logger, - config: cfg, - childProcessState: childProcessStateNotStarted, + logger: cfg.Logger, + config: cfg, + childProcessState: childProcessStateNotStarted, + childProcessExitCh: make(chan int), } return &server @@ -247,7 +248,15 @@ func (s *Server) bounceCmd(newEnvVars []string) error { return err } s.childProcess = proc - s.childProcessExitCh = s.childProcess.ExitCh() + // did not work + // s.childProcessExitCh = s.childProcess.ExitCh() + go func() { + select { + case exitCode := <-proc.ExitCh(): + s.childProcessExitCh <- exitCode + return + } + }() if err := s.childProcess.Start(); err != nil { return fmt.Errorf("error starting child process: %w", err)