|
|
@@ -21,10 +21,9 @@ import (
|
|
|
"fmt"
|
|
|
"os"
|
|
|
"os/exec"
|
|
|
+ "os/signal"
|
|
|
"strings"
|
|
|
|
|
|
- "github.com/spf13/cobra"
|
|
|
-
|
|
|
apicontext "github.com/docker/api/context"
|
|
|
"github.com/docker/api/context/store"
|
|
|
)
|
|
|
@@ -43,7 +42,7 @@ func ExecIfDefaultCtxType(ctx context.Context) {
|
|
|
currentCtx, err := s.Get(currentContext)
|
|
|
// Only run original docker command if the current context is not ours.
|
|
|
if err != nil || mustDelegateToMoby(currentCtx.Type()) {
|
|
|
- Exec(ctx)
|
|
|
+ Exec()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -57,12 +56,32 @@ func mustDelegateToMoby(ctxType string) bool {
|
|
|
}
|
|
|
|
|
|
// Exec delegates to com.docker.cli if on moby context
|
|
|
-func Exec(ctx context.Context) {
|
|
|
- cmd := exec.CommandContext(ctx, ComDockerCli, os.Args[1:]...)
|
|
|
+func Exec() {
|
|
|
+ cmd := exec.Command(ComDockerCli, os.Args[1:]...)
|
|
|
cmd.Stdin = os.Stdin
|
|
|
cmd.Stdout = os.Stdout
|
|
|
cmd.Stderr = os.Stderr
|
|
|
- if err := cmd.Run(); err != nil {
|
|
|
+
|
|
|
+ signals := make(chan os.Signal)
|
|
|
+ childExit := make(chan bool)
|
|
|
+ signal.Notify(signals) // catch all signals
|
|
|
+ go func() {
|
|
|
+ for {
|
|
|
+ select {
|
|
|
+ case sig := <-signals:
|
|
|
+ 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())
|
|
|
+ }
|
|
|
+ case <-childExit:
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ err := cmd.Run()
|
|
|
+ childExit <- true
|
|
|
+ if err != nil {
|
|
|
if exiterr, ok := err.(*exec.ExitError); ok {
|
|
|
os.Exit(exiterr.ExitCode())
|
|
|
}
|
|
|
@@ -72,14 +91,6 @@ func Exec(ctx context.Context) {
|
|
|
os.Exit(0)
|
|
|
}
|
|
|
|
|
|
-// ExecCmd delegates the cli command to com.docker.cli. The error is never
|
|
|
-// returned (process will exit with docker classic exit code), the return type
|
|
|
-// is to make it easier to use with cobra commands
|
|
|
-func ExecCmd(command *cobra.Command) error {
|
|
|
- Exec(command.Context())
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
// IsDefaultContextCommand checks if the command exists in the classic cli (issues a shellout --help)
|
|
|
func IsDefaultContextCommand(dockerCommand string) bool {
|
|
|
cmd := exec.Command(ComDockerCli, dockerCommand, "--help")
|