Don't explicitly send interrupt signal to child processes

Apparently the way that process groups work is that child processes will
automatically have all signals propagated to them, so there's no need to
do it explicitly, pmux only needs to wait for them to exit.
main
Brian Picciano 2 years ago
parent 05c959eba7
commit b4c6787a98
  1. 2
      main.go
  2. 8
      pmuxproc/pmuxproc.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

@ -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 {

Loading…
Cancel
Save