Skip to content

Commit

Permalink
cmd/sips, cmd/sipsctl: fix signal handling in Docker (#7)
Browse files Browse the repository at this point in the history
* internal/cli: add $GOOS-specific signal lists

* cmd/sips, cmd/sipsctl: use the new signal lists from `internal/cli`
  • Loading branch information
DeedleFake authored Jun 10, 2021
1 parent 4148bc6 commit 783c641
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/sips/sips.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func run(ctx context.Context) error {
}

func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
ctx, cancel := signal.NotifyContext(context.Background(), cli.Signals...)
defer cancel()

err := run(ctx)
Expand Down
4 changes: 2 additions & 2 deletions cmd/sipsctl/sipsctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package main

import (
"context"
"os"
"os/signal"

"github.com/DeedleFake/sips/cmd/sipsctl/cmd"
"github.com/DeedleFake/sips/internal/cli"
"github.com/DeedleFake/sips/internal/log"
)

func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
ctx, cancel := signal.NotifyContext(context.Background(), cli.Signals...)
defer cancel()

err := cmd.ExecuteContext(ctx)
Expand Down
14 changes: 14 additions & 0 deletions internal/cli/cli_posix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// +build linux unix darwin netbsd openbsd freebsd

package cli

import (
"os"

"golang.org/x/sys/unix"
)

var Signals = []os.Signal{
os.Interrupt,
unix.SIGTERM,
}
12 changes: 12 additions & 0 deletions internal/cli/cli_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cli

import (
"os"

"golang.org/x/sys/windows"
)

var Signals = []os.Signal{
os.Interrupt,
windows.SIGTERM,
}

0 comments on commit 783c641

Please sign in to comment.