Forward all signals to child process

This commit is contained in:
Guillaume Tardif 2020-08-05 13:59:52 +02:00
parent 4dd1918ac2
commit 05a8582126
1 changed files with 12 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"os/signal"
"strings" "strings"
apicontext "github.com/docker/api/context" apicontext "github.com/docker/api/context"
@ -61,6 +62,17 @@ func Exec() {
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
s := make(chan os.Signal)
signal.Notify(s) // catch all signals
go func() {
for sig := range s {
err := cmd.Process.Signal(sig)
if err != nil {
fmt.Printf("WARNING could not forward signal %s to %s : %s\n", sig.String(), ComDockerCli, err.Error())
}
}
}()
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
if exiterr, ok := err.(*exec.ExitError); ok { if exiterr, ok := err.(*exec.ExitError); ok {
os.Exit(exiterr.ExitCode()) os.Exit(exiterr.ExitCode())