Browse Source

Forward all signals to child process

Guillaume Tardif 5 years ago
parent
commit
05a8582126
1 changed files with 12 additions and 0 deletions
  1. 12 0
      cli/mobycli/exec.go

+ 12 - 0
cli/mobycli/exec.go

@@ -21,6 +21,7 @@ import (
 	"fmt"
 	"os"
 	"os/exec"
+	"os/signal"
 	"strings"
 
 	apicontext "github.com/docker/api/context"
@@ -61,6 +62,17 @@ func Exec() {
 	cmd.Stdout = os.Stdout
 	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 exiterr, ok := err.(*exec.ExitError); ok {
 			os.Exit(exiterr.ExitCode())