diff --git a/arelo.go b/arelo.go index e410f28..289e7a8 100644 --- a/arelo.go +++ b/arelo.go @@ -295,33 +295,19 @@ type bytesErr struct { // cmd.Wait() blocks until stdin.Read() returns. // so stdinReader.Read() returns EOF when the child process exited. type stdinReader struct { - ch <-chan bytesErr + input <-chan bytesErr chldDone <-chan struct{} - done <-chan struct{} -} - -func (s *stdinReader) discard() { - for { - select { - case <-s.ch: - case <-s.chldDone: - case <-s.done: - return - } - } } func (s *stdinReader) Read(b []byte) (int, error) { select { - case be, ok := <-s.ch: + case be, ok := <-s.input: if !ok { return 0, io.EOF } return copy(b, be.bytes), be.err case <-s.chldDone: return 0, io.EOF - case <-s.done: - return 0, io.EOF } } @@ -387,7 +373,7 @@ func runner(ctx context.Context, wg *sync.WaitGroup, cmd []string, delay time.Du go func() { log.Printf("[ARELO] start: %s", pcmd) clearChBuf(chldDone) - stdin := &stdinReader{stdinC, chldDone, cmdctx.Done()} + stdin := &stdinReader{stdinC, chldDone} err := runCmd(cmdctx, cmd, sig, stdin) if err != nil { log.Printf("[ARELO] command error: %v", err) @@ -398,7 +384,6 @@ func runner(ctx context.Context, wg *sync.WaitGroup, cmd []string, delay time.Du close(restart) } - stdin.discard() close(done) }() diff --git a/arelo_windows.go b/arelo_windows.go index 3f83dc7..0bf270b 100644 --- a/arelo_windows.go +++ b/arelo_windows.go @@ -40,11 +40,17 @@ func makeChildDoneChan() <-chan struct{} { err := windows.GetExitCodeProcess(p, &code) if err != nil { log.Printf("GetExitCodeProcess: %v", err) - c <- struct{}{} + select { + case c <- struct{}{}: + default: + } break } if code != STILL_ACTIVE { - c <- struct{}{} + select { + case c <- struct{}{}: + default: + } break } } @@ -57,7 +63,6 @@ func makeChildDoneChan() <-chan struct{} { func waitCmd(cmd *exec.Cmd) error { p, err := windows.OpenProcess( windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(cmd.Process.Pid)) - log.Printf("pid=%v handle=%v", cmd.Process.Pid, p) if err != nil { return xerrors.Errorf("OpenProcess: %w", err) }