From 23ed50c10ffc8c846c5190bceebd98ed79239dc8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 9 Aug 2021 19:15:46 +0200 Subject: [PATCH] replace docker/pkg/signal with github.com/moby/sys/signal The github.com/docker/docker/pkg/signal package was moved to a separate module in moby/sys. Signed-off-by: Sebastiaan van Stijn --- cli/command/container/attach.go | 2 +- cli/command/container/opts.go | 2 +- cli/command/container/run.go | 2 +- cli/command/container/signals.go | 2 +- cli/command/container/signals_test.go | 2 +- cli/command/container/start.go | 2 +- cli/command/container/tty.go | 2 +- vendor.conf | 2 +- .../docker/docker/pkg/signal/README.md | 1 - .../docker/docker/pkg/signal/trap.go | 104 ------------------ vendor/github.com/moby/sys/mount/go.mod | 2 +- vendor/github.com/moby/sys/signal/go.mod | 5 + .../docker/pkg => moby/sys}/signal/signal.go | 2 +- .../pkg => moby/sys}/signal/signal_darwin.go | 2 +- .../pkg => moby/sys}/signal/signal_freebsd.go | 2 +- .../pkg => moby/sys}/signal/signal_linux.go | 2 +- .../sys}/signal/signal_linux_mipsx.go | 2 +- .../pkg => moby/sys}/signal/signal_unix.go | 2 +- .../sys}/signal/signal_unsupported.go | 2 +- .../pkg => moby/sys}/signal/signal_windows.go | 2 +- 20 files changed, 22 insertions(+), 122 deletions(-) delete mode 100644 vendor/github.com/docker/docker/pkg/signal/README.md delete mode 100644 vendor/github.com/docker/docker/pkg/signal/trap.go create mode 100644 vendor/github.com/moby/sys/signal/go.mod rename vendor/github.com/{docker/docker/pkg => moby/sys}/signal/signal.go (96%) rename vendor/github.com/{docker/docker/pkg => moby/sys}/signal/signal_darwin.go (94%) rename vendor/github.com/{docker/docker/pkg => moby/sys}/signal/signal_freebsd.go (94%) rename vendor/github.com/{docker/docker/pkg => moby/sys}/signal/signal_linux.go (96%) rename vendor/github.com/{docker/docker/pkg => moby/sys}/signal/signal_linux_mipsx.go (96%) rename vendor/github.com/{docker/docker/pkg => moby/sys}/signal/signal_unix.go (91%) rename vendor/github.com/{docker/docker/pkg => moby/sys}/signal/signal_unsupported.go (73%) rename vendor/github.com/{docker/docker/pkg => moby/sys}/signal/signal_windows.go (92%) diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index 8470855992..a9e604f31f 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -10,7 +10,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" - "github.com/docker/docker/pkg/signal" + "github.com/moby/sys/signal" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index f53ae5960d..d3853857fd 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -19,8 +19,8 @@ import ( "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/errdefs" - "github.com/docker/docker/pkg/signal" "github.com/docker/go-connections/nat" + "github.com/moby/sys/signal" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/pflag" diff --git a/cli/command/container/run.go b/cli/command/container/run.go index 27c267e551..103ca83ff0 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -13,7 +13,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/signal" + "github.com/moby/sys/signal" "github.com/moby/term" "github.com/pkg/errors" "github.com/sirupsen/logrus" diff --git a/cli/command/container/signals.go b/cli/command/container/signals.go index 1929a9b191..dbfd7f0339 100644 --- a/cli/command/container/signals.go +++ b/cli/command/container/signals.go @@ -6,7 +6,7 @@ import ( gosignal "os/signal" "github.com/docker/cli/cli/command" - "github.com/docker/docker/pkg/signal" + "github.com/moby/sys/signal" "github.com/sirupsen/logrus" ) diff --git a/cli/command/container/signals_test.go b/cli/command/container/signals_test.go index 39eaab1c5d..248d4b1480 100644 --- a/cli/command/container/signals_test.go +++ b/cli/command/container/signals_test.go @@ -7,7 +7,7 @@ import ( "time" "github.com/docker/cli/internal/test" - "github.com/docker/docker/pkg/signal" + "github.com/moby/sys/signal" ) func TestForwardSignals(t *testing.T) { diff --git a/cli/command/container/start.go b/cli/command/container/start.go index bec948225f..f2d6351421 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -9,7 +9,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types" - "github.com/docker/docker/pkg/signal" + "github.com/moby/sys/signal" "github.com/moby/term" "github.com/pkg/errors" "github.com/spf13/cobra" diff --git a/cli/command/container/tty.go b/cli/command/container/tty.go index 4060c0a19f..cc64f999dc 100644 --- a/cli/command/container/tty.go +++ b/cli/command/container/tty.go @@ -11,7 +11,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types" "github.com/docker/docker/client" - "github.com/docker/docker/pkg/signal" + "github.com/moby/sys/signal" "github.com/sirupsen/logrus" ) diff --git a/vendor.conf b/vendor.conf index 35372a1229..8aad29f5d0 100755 --- a/vendor.conf +++ b/vendor.conf @@ -45,7 +45,7 @@ github.com/Microsoft/go-winio 5c2e05d71961716a6c392a06ada4 github.com/miekg/pkcs11 210dc1e16747c5ba98a03bcbcf728c38086ea357 # v1.0.3 github.com/mitchellh/mapstructure d16e9488127408e67948eb43b6d3fbb9f222da10 # v1.3.2 github.com/moby/buildkit 9f254e18360a24c2ae47b26f772c3c89533bcbb7 # master / v0.9.0-dev -github.com/moby/sys b0f1fd7235275d01bd35cc4421e884e522395f45 # mountinfo/v0.4.1 (latest tag, either mount/vXXX, mountinfo/vXXX or symlink/vXXX) +github.com/moby/sys 9b0136d132d8e0d1c116a38d7ec9af70d3a59536 # signal/v0.5.0 (latest tag, either mount/vXXX, mountinfo/vXXX, signal/vXXX, or symlink/vXXX) github.com/moby/term 3f7ff695adc6a35abc925370dd0a4dafb48ec64d github.com/modern-go/concurrent bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94 # 1.0.3 github.com/modern-go/reflect2 94122c33edd36123c84d5368cfb2b69df93a0ec8 # v1.0.1 diff --git a/vendor/github.com/docker/docker/pkg/signal/README.md b/vendor/github.com/docker/docker/pkg/signal/README.md deleted file mode 100644 index 2b237a5942..0000000000 --- a/vendor/github.com/docker/docker/pkg/signal/README.md +++ /dev/null @@ -1 +0,0 @@ -This package provides helper functions for dealing with signals across various operating systems \ No newline at end of file diff --git a/vendor/github.com/docker/docker/pkg/signal/trap.go b/vendor/github.com/docker/docker/pkg/signal/trap.go deleted file mode 100644 index a277b95629..0000000000 --- a/vendor/github.com/docker/docker/pkg/signal/trap.go +++ /dev/null @@ -1,104 +0,0 @@ -package signal // import "github.com/docker/docker/pkg/signal" - -import ( - "fmt" - "os" - gosignal "os/signal" - "path/filepath" - "runtime" - "strings" - "sync/atomic" - "syscall" - "time" - - "github.com/pkg/errors" -) - -// Trap sets up a simplified signal "trap", appropriate for common -// behavior expected from a vanilla unix command-line tool in general -// (and the Docker engine in particular). -// -// * If SIGINT or SIGTERM are received, `cleanup` is called, then the process is terminated. -// * If SIGINT or SIGTERM are received 3 times before cleanup is complete, then cleanup is -// skipped and the process is terminated immediately (allows force quit of stuck daemon) -// * A SIGQUIT always causes an exit without cleanup, with a goroutine dump preceding exit. -// * Ignore SIGPIPE events. These are generated by systemd when journald is restarted while -// the docker daemon is not restarted and also running under systemd. -// Fixes https://github.com/docker/docker/issues/19728 -// -func Trap(cleanup func(), logger interface { - Info(args ...interface{}) -}) { - c := make(chan os.Signal, 1) - // we will handle INT, TERM, QUIT, SIGPIPE here - signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGPIPE} - gosignal.Notify(c, signals...) - go func() { - interruptCount := uint32(0) - for sig := range c { - if sig == syscall.SIGPIPE { - continue - } - - go func(sig os.Signal) { - logger.Info(fmt.Sprintf("Processing signal '%v'", sig)) - switch sig { - case os.Interrupt, syscall.SIGTERM: - if atomic.LoadUint32(&interruptCount) < 3 { - // Initiate the cleanup only once - if atomic.AddUint32(&interruptCount, 1) == 1 { - // Call the provided cleanup handler - cleanup() - os.Exit(0) - } else { - return - } - } else { - // 3 SIGTERM/INT signals received; force exit without cleanup - logger.Info("Forcing docker daemon shutdown without cleanup; 3 interrupts received") - } - case syscall.SIGQUIT: - DumpStacks("") - logger.Info("Forcing docker daemon shutdown without cleanup on SIGQUIT") - } - // for the SIGINT/TERM, and SIGQUIT non-clean shutdown case, exit with 128 + signal # - os.Exit(128 + int(sig.(syscall.Signal))) - }(sig) - } - }() -} - -const stacksLogNameTemplate = "goroutine-stacks-%s.log" - -// DumpStacks appends the runtime stack into file in dir and returns full path -// to that file. -func DumpStacks(dir string) (string, error) { - var ( - buf []byte - stackSize int - ) - bufferLen := 16384 - for stackSize == len(buf) { - buf = make([]byte, bufferLen) - stackSize = runtime.Stack(buf, true) - bufferLen *= 2 - } - buf = buf[:stackSize] - var f *os.File - if dir != "" { - path := filepath.Join(dir, fmt.Sprintf(stacksLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1))) - var err error - f, err = os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666) - if err != nil { - return "", errors.Wrap(err, "failed to open file to write the goroutine stacks") - } - defer f.Close() - defer f.Sync() - } else { - f = os.Stderr - } - if _, err := f.Write(buf); err != nil { - return "", errors.Wrap(err, "failed to write goroutine stacks") - } - return f.Name(), nil -} diff --git a/vendor/github.com/moby/sys/mount/go.mod b/vendor/github.com/moby/sys/mount/go.mod index e1e03a3769..b08f010955 100644 --- a/vendor/github.com/moby/sys/mount/go.mod +++ b/vendor/github.com/moby/sys/mount/go.mod @@ -3,6 +3,6 @@ module github.com/moby/sys/mount go 1.14 require ( - github.com/moby/sys/mountinfo v0.4.0 + github.com/moby/sys/mountinfo v0.4.1 golang.org/x/sys v0.0.0-20200922070232-aee5d888a860 ) diff --git a/vendor/github.com/moby/sys/signal/go.mod b/vendor/github.com/moby/sys/signal/go.mod new file mode 100644 index 0000000000..c48d5aecce --- /dev/null +++ b/vendor/github.com/moby/sys/signal/go.mod @@ -0,0 +1,5 @@ +module github.com/moby/sys/signal + +go 1.13 + +require golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c diff --git a/vendor/github.com/docker/docker/pkg/signal/signal.go b/vendor/github.com/moby/sys/signal/signal.go similarity index 96% rename from vendor/github.com/docker/docker/pkg/signal/signal.go rename to vendor/github.com/moby/sys/signal/signal.go index b274033ef6..c9cd046cfa 100644 --- a/vendor/github.com/docker/docker/pkg/signal/signal.go +++ b/vendor/github.com/moby/sys/signal/signal.go @@ -1,6 +1,6 @@ // Package signal provides helper functions for dealing with signals across // various operating systems. -package signal // import "github.com/docker/docker/pkg/signal" +package signal import ( "fmt" diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_darwin.go b/vendor/github.com/moby/sys/signal/signal_darwin.go similarity index 94% rename from vendor/github.com/docker/docker/pkg/signal/signal_darwin.go rename to vendor/github.com/moby/sys/signal/signal_darwin.go index ee5501e3d9..946de87e94 100644 --- a/vendor/github.com/docker/docker/pkg/signal/signal_darwin.go +++ b/vendor/github.com/moby/sys/signal/signal_darwin.go @@ -1,4 +1,4 @@ -package signal // import "github.com/docker/docker/pkg/signal" +package signal import ( "syscall" diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_freebsd.go b/vendor/github.com/moby/sys/signal/signal_freebsd.go similarity index 94% rename from vendor/github.com/docker/docker/pkg/signal/signal_freebsd.go rename to vendor/github.com/moby/sys/signal/signal_freebsd.go index 764f90e264..6b9569bb75 100644 --- a/vendor/github.com/docker/docker/pkg/signal/signal_freebsd.go +++ b/vendor/github.com/moby/sys/signal/signal_freebsd.go @@ -1,4 +1,4 @@ -package signal // import "github.com/docker/docker/pkg/signal" +package signal import ( "syscall" diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_linux.go b/vendor/github.com/moby/sys/signal/signal_linux.go similarity index 96% rename from vendor/github.com/docker/docker/pkg/signal/signal_linux.go rename to vendor/github.com/moby/sys/signal/signal_linux.go index 4013bded13..692b9f9e77 100644 --- a/vendor/github.com/docker/docker/pkg/signal/signal_linux.go +++ b/vendor/github.com/moby/sys/signal/signal_linux.go @@ -1,6 +1,6 @@ // +build !mips,!mipsle,!mips64,!mips64le -package signal // import "github.com/docker/docker/pkg/signal" +package signal import ( "syscall" diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_linux_mipsx.go b/vendor/github.com/moby/sys/signal/signal_linux_mipsx.go similarity index 96% rename from vendor/github.com/docker/docker/pkg/signal/signal_linux_mipsx.go rename to vendor/github.com/moby/sys/signal/signal_linux_mipsx.go index c78c887af5..138a840cc6 100644 --- a/vendor/github.com/docker/docker/pkg/signal/signal_linux_mipsx.go +++ b/vendor/github.com/moby/sys/signal/signal_linux_mipsx.go @@ -1,7 +1,7 @@ // +build linux // +build mips mipsle mips64 mips64le -package signal // import "github.com/docker/docker/pkg/signal" +package signal import ( "syscall" diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_unix.go b/vendor/github.com/moby/sys/signal/signal_unix.go similarity index 91% rename from vendor/github.com/docker/docker/pkg/signal/signal_unix.go rename to vendor/github.com/moby/sys/signal/signal_unix.go index a2aa4248fa..5d058fd56b 100644 --- a/vendor/github.com/docker/docker/pkg/signal/signal_unix.go +++ b/vendor/github.com/moby/sys/signal/signal_unix.go @@ -1,6 +1,6 @@ // +build !windows -package signal // import "github.com/docker/docker/pkg/signal" +package signal import ( "syscall" diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_unsupported.go b/vendor/github.com/moby/sys/signal/signal_unsupported.go similarity index 73% rename from vendor/github.com/docker/docker/pkg/signal/signal_unsupported.go rename to vendor/github.com/moby/sys/signal/signal_unsupported.go index 1fd25a83c6..161ba27397 100644 --- a/vendor/github.com/docker/docker/pkg/signal/signal_unsupported.go +++ b/vendor/github.com/moby/sys/signal/signal_unsupported.go @@ -1,6 +1,6 @@ // +build !linux,!darwin,!freebsd,!windows -package signal // import "github.com/docker/docker/pkg/signal" +package signal import ( "syscall" diff --git a/vendor/github.com/docker/docker/pkg/signal/signal_windows.go b/vendor/github.com/moby/sys/signal/signal_windows.go similarity index 92% rename from vendor/github.com/docker/docker/pkg/signal/signal_windows.go rename to vendor/github.com/moby/sys/signal/signal_windows.go index 65752f24aa..c84a63e821 100644 --- a/vendor/github.com/docker/docker/pkg/signal/signal_windows.go +++ b/vendor/github.com/moby/sys/signal/signal_windows.go @@ -1,4 +1,4 @@ -package signal // import "github.com/docker/docker/pkg/signal" +package signal import ( "syscall"