From 783c641362cac4f1b3a4129463a19dd9490432d8 Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Wed, 9 Jun 2021 23:40:02 -0400 Subject: [PATCH] cmd/sips, cmd/sipsctl: fix signal handling in Docker (#7) * internal/cli: add $GOOS-specific signal lists * cmd/sips, cmd/sipsctl: use the new signal lists from `internal/cli` --- cmd/sips/sips.go | 2 +- cmd/sipsctl/sipsctl.go | 4 ++-- internal/cli/cli_posix.go | 14 ++++++++++++++ internal/cli/cli_windows.go | 12 ++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 internal/cli/cli_posix.go create mode 100644 internal/cli/cli_windows.go diff --git a/cmd/sips/sips.go b/cmd/sips/sips.go index 5b99d03..45145f9 100644 --- a/cmd/sips/sips.go +++ b/cmd/sips/sips.go @@ -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) diff --git a/cmd/sipsctl/sipsctl.go b/cmd/sipsctl/sipsctl.go index c24f5ef..c3aada4 100644 --- a/cmd/sipsctl/sipsctl.go +++ b/cmd/sipsctl/sipsctl.go @@ -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) diff --git a/internal/cli/cli_posix.go b/internal/cli/cli_posix.go new file mode 100644 index 0000000..92804b7 --- /dev/null +++ b/internal/cli/cli_posix.go @@ -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, +} diff --git a/internal/cli/cli_windows.go b/internal/cli/cli_windows.go new file mode 100644 index 0000000..33ba85e --- /dev/null +++ b/internal/cli/cli_windows.go @@ -0,0 +1,12 @@ +package cli + +import ( + "os" + + "golang.org/x/sys/windows" +) + +var Signals = []os.Signal{ + os.Interrupt, + windows.SIGTERM, +}