Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 8b76602

Browse files
authored
Merge pull request #1879 from ndeloof/signals
signals
2 parents ba40ef0 + 9215d68 commit 8b76602

File tree

12 files changed

+19
-97
lines changed

12 files changed

+19
-97
lines changed

cli/cmd/context/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func exportCommand() *cobra.Command {
4848
Use: "export",
4949
Short: "Export a context to a tar or kubeconfig file",
5050
Run: func(cmd *cobra.Command, args []string) {
51-
mobycli.Exec(cmd.Root())
51+
mobycli.Exec()
5252
},
5353
}
5454
cmd.Flags().Bool("kubeconfig", false, "Export as a kubeconfig file")
@@ -60,7 +60,7 @@ func importCommand() *cobra.Command {
6060
Use: "import",
6161
Short: "Import a context from a tar or zip file",
6262
Run: func(cmd *cobra.Command, args []string) {
63-
mobycli.Exec(cmd.Root())
63+
mobycli.Exec()
6464
},
6565
}
6666
return cmd

cli/cmd/context/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ $ docker context create my-context --description "some description" --docker "ho
6969
Use: "create CONTEXT",
7070
Short: "Create new context",
7171
RunE: func(cmd *cobra.Command, args []string) error {
72-
mobycli.Exec(cmd.Root())
72+
mobycli.Exec()
7373
return nil
7474
},
7575
Long: longHelp,

cli/cmd/context/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func inspectCommand() *cobra.Command {
2727
Use: "inspect",
2828
Short: "Display detailed information on one or more contexts",
2929
RunE: func(cmd *cobra.Command, args []string) error {
30-
mobycli.Exec(cmd.Root())
30+
mobycli.Exec()
3131
return nil
3232
},
3333
}

cli/cmd/context/ls.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func listCommand() *cobra.Command {
5353
Aliases: []string{"ls"},
5454
Args: cobra.NoArgs,
5555
RunE: func(cmd *cobra.Command, args []string) error {
56-
return runList(cmd, opts)
56+
return runList(opts)
5757
},
5858
}
5959
cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Only show context names")
@@ -62,14 +62,14 @@ func listCommand() *cobra.Command {
6262
return cmd
6363
}
6464

65-
func runList(cmd *cobra.Command, opts lsOpts) error {
65+
func runList(opts lsOpts) error {
6666
err := opts.validate()
6767
if err != nil {
6868
return err
6969
}
7070
format := strings.ToLower(strings.ReplaceAll(opts.format, " ", ""))
7171
if format != "" && format != formatter.JSON && format != formatter.PRETTY && format != formatter.TemplateLegacyJSON {
72-
mobycli.Exec(cmd.Root())
72+
mobycli.Exec()
7373
return nil
7474
}
7575

cli/cmd/context/update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ $ docker context update my-context --description "some description" --docker "ho
5656
Short: "Update a context",
5757
Args: cobra.ExactArgs(1),
5858
RunE: func(cmd *cobra.Command, args []string) error {
59-
return runUpdate(cmd, args[0])
59+
return runUpdate(args[0])
6060
},
6161
Long: longHelp,
6262
}
@@ -71,7 +71,7 @@ $ docker context update my-context --description "some description" --docker "ho
7171
return cmd
7272
}
7373

74-
func runUpdate(cmd *cobra.Command, name string) error {
74+
func runUpdate(name string) error {
7575
s := store.Instance()
7676
dockerContext, err := s.Get(name)
7777
if err == nil && dockerContext != nil {
@@ -80,6 +80,6 @@ func runUpdate(cmd *cobra.Command, name string) error {
8080
}
8181
}
8282

83-
mobycli.Exec(cmd.Root())
83+
mobycli.Exec()
8484
return nil
8585
}

cli/cmd/login/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Command() *cobra.Command {
4949
}
5050

5151
func runLogin(cmd *cobra.Command, args []string) error {
52-
mobycli.Exec(cmd.Root())
52+
mobycli.Exec()
5353
return nil
5454
}
5555

cli/cmd/logout/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ func Command() *cobra.Command {
3737
}
3838

3939
func runLogout(cmd *cobra.Command, args []string) error {
40-
mobycli.Exec(cmd.Root())
40+
mobycli.Exec()
4141
return nil
4242
}

cli/cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func getOutFromMoby(cmd *cobra.Command, args ...string) (string, error) {
8080
// we don't want to fail on error, there is an error if the engine is not available but it displays client version info
8181
// Still, technically the [] byte versionResult could be nil, just let the original command display what it has to display
8282
if versionResult == nil {
83-
mobycli.Exec(cmd.Root())
83+
mobycli.Exec()
8484
return "", nil
8585
}
8686
return string(versionResult), err

cli/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func main() {
191191

192192
// --version should immediately be forwarded to the original cli
193193
if opts.Version {
194-
mobycli.Exec(root)
194+
mobycli.Exec()
195195
}
196196

197197
if opts.Config == "" {
@@ -205,7 +205,7 @@ func main() {
205205

206206
s, err := store.New(configDir)
207207
if err != nil {
208-
mobycli.Exec(root)
208+
mobycli.Exec()
209209
}
210210
store.WithContextStore(s)
211211

cli/mobycli/exec.go

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"os"
2323
"os/exec"
24-
"os/signal"
2524
"path/filepath"
2625
"regexp"
2726

@@ -49,7 +48,7 @@ func ExecIfDefaultCtxType(ctx context.Context, root *cobra.Command) {
4948
currentCtx, err := s.Get(currentContext)
5049
// Only run original docker command if the current context is not ours.
5150
if err != nil || mustDelegateToMoby(currentCtx.Type()) {
52-
Exec(root)
51+
Exec()
5352
}
5453
}
5554

@@ -63,10 +62,8 @@ func mustDelegateToMoby(ctxType string) bool {
6362
}
6463

6564
// Exec delegates to com.docker.cli if on moby context
66-
func Exec(root *cobra.Command) {
67-
childExit := make(chan bool)
68-
err := RunDocker(childExit, os.Args[1:]...)
69-
childExit <- true
65+
func Exec() {
66+
err := RunDocker(os.Args[1:]...)
7067
if err != nil {
7168
if exiterr, ok := err.(*exec.ExitError); ok {
7269
exitCode := exiterr.ExitCode()
@@ -91,7 +88,7 @@ func Exec(root *cobra.Command) {
9188
}
9289

9390
// RunDocker runs a docker command, and forward signals to the shellout command (stops listening to signals when an event is sent to childExit)
94-
func RunDocker(childExit chan bool, args ...string) error {
91+
func RunDocker(args ...string) error {
9592
execBinary, err := resolvepath.LookPath(ComDockerCli)
9693
if err != nil {
9794
execBinary = findBinary(ComDockerCli)
@@ -105,29 +102,6 @@ func RunDocker(childExit chan bool, args ...string) error {
105102
cmd.Stdin = os.Stdin
106103
cmd.Stdout = os.Stdout
107104
cmd.Stderr = os.Stderr
108-
109-
signals := make(chan os.Signal, 1)
110-
signal.Notify(signals) // catch all signals
111-
go func() {
112-
for {
113-
select {
114-
case sig := <-signals:
115-
if cmd.Process == nil {
116-
continue // can happen if receiving signal before the process is actually started
117-
}
118-
// In go1.14+, the go runtime issues SIGURG as an interrupt to
119-
// support preemptable system calls on Linux. Since we can't
120-
// forward that along we'll check that here.
121-
if isRuntimeSig(sig) {
122-
continue
123-
}
124-
_ = cmd.Process.Signal(sig)
125-
case <-childExit:
126-
return
127-
}
128-
}
129-
}()
130-
131105
return cmd.Run()
132106
}
133107

0 commit comments

Comments
 (0)