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

Commit 9215d68

Browse files
committed
signals
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 7a4e111 commit 9215d68

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
@@ -48,7 +48,7 @@ func Command() *cobra.Command {
4848
}
4949

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

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
@@ -188,7 +188,7 @@ func main() {
188188

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

194194
if opts.Config == "" {
@@ -202,7 +202,7 @@ func main() {
202202

203203
s, err := store.New(configDir)
204204
if err != nil {
205-
mobycli.Exec(root)
205+
mobycli.Exec()
206206
}
207207
store.WithContextStore(s)
208208

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()
@@ -87,7 +84,7 @@ func Exec(root *cobra.Command) {
8784
}
8885

8986
// RunDocker runs a docker command, and forward signals to the shellout command (stops listening to signals when an event is sent to childExit)
90-
func RunDocker(childExit chan bool, args ...string) error {
87+
func RunDocker(args ...string) error {
9188
execBinary, err := resolvepath.LookPath(ComDockerCli)
9289
if err != nil {
9390
execBinary = findBinary(ComDockerCli)
@@ -101,29 +98,6 @@ func RunDocker(childExit chan bool, args ...string) error {
10198
cmd.Stdin = os.Stdin
10299
cmd.Stdout = os.Stdout
103100
cmd.Stderr = os.Stderr
104-
105-
signals := make(chan os.Signal, 1)
106-
signal.Notify(signals) // catch all signals
107-
go func() {
108-
for {
109-
select {
110-
case sig := <-signals:
111-
if cmd.Process == nil {
112-
continue // can happen if receiving signal before the process is actually started
113-
}
114-
// In go1.14+, the go runtime issues SIGURG as an interrupt to
115-
// support preemptable system calls on Linux. Since we can't
116-
// forward that along we'll check that here.
117-
if isRuntimeSig(sig) {
118-
continue
119-
}
120-
_ = cmd.Process.Signal(sig)
121-
case <-childExit:
122-
return
123-
}
124-
}
125-
}()
126-
127101
return cmd.Run()
128102
}
129103

0 commit comments

Comments
 (0)