diff --git a/main.go b/main.go index 87d2a4f..a4b2714 100644 --- a/main.go +++ b/main.go @@ -193,7 +193,7 @@ func main() { signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM) sig := <-sigCh - sysLogger.Printf("%v signal received, killing all sub-processes", sig) + sysLogger.Printf("%v signal received, waiting for child processes to exit", sig) cancel() <-sigCh diff --git a/pmuxproc/pmuxproc.go b/pmuxproc/pmuxproc.go index 1e140dd..53cdde6 100644 --- a/pmuxproc/pmuxproc.go +++ b/pmuxproc/pmuxproc.go @@ -134,16 +134,11 @@ func RunProcessOnce( return -1, fmt.Errorf("starting process: %w", err) } - // go-routine which will sent interrupt if the context is cancelled. Also - // waits on a secondary channel, which is closed when this function returns, - // in order to ensure this go-routine always gets cleaned up. stopCh := make(chan struct{}) - defer close(stopCh) go func(proc *os.Process) { select { case <-ctx.Done(): - _ = proc.Signal(os.Interrupt) case <-stopCh: return } @@ -153,13 +148,14 @@ func RunProcessOnce( sysLogger.Println("forcefully killing process") _ = proc.Signal(os.Kill) case <-stopCh: - return } }(cmd.Process) wg.Wait() err = cmd.Wait() + close(stopCh) + exitCode := cmd.ProcessState.ExitCode() if err != nil {