Skip to content

Commit ccf5d54

Browse files
committed
Correctly handle signals
See leafac#77
1 parent 2964f03 commit ccf5d54

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

stubs/stub.go

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"log"
1313
"os"
1414
"os/exec"
15+
"os/signal"
1516
"path"
1617
"path/filepath"
1718
"regexp"
@@ -126,6 +127,18 @@ func main() {
126127
command.Stdin = os.Stdin
127128
command.Stdout = os.Stdout
128129
command.Stderr = os.Stderr
130+
131+
// Pass signals through to the child process.
132+
sigChan := make(chan os.Signal, 1)
133+
signal.Notify(sigChan)
134+
go func() {
135+
for sig := range sigChan {
136+
if command.Process != nil {
137+
command.Process.Signal(sig)
138+
}
139+
}
140+
}()
141+
129142
err = command.Run()
130143
var exitError *exec.ExitError
131144
if errors.As(err, &exitError) {

0 commit comments

Comments
 (0)