Ver código fonte

replace pkg/signal with moby/sys/signal v0.5.0

This code was moved to the moby/sys repository

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 4 anos atrás
pai
commit
28409ca6c7

+ 1 - 1
api/server/router/container/container_routes.go

@@ -19,7 +19,7 @@ import (
 	containerpkg "github.com/docker/docker/container"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/pkg/ioutils"
-	"github.com/docker/docker/pkg/signal"
+	"github.com/moby/sys/signal"
 	specs "github.com/opencontainers/image-spec/specs-go/v1"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"

+ 1 - 1
builder/dockerfile/dispatchers.go

@@ -21,12 +21,12 @@ import (
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/image"
 	"github.com/docker/docker/pkg/jsonmessage"
-	"github.com/docker/docker/pkg/signal"
 	"github.com/docker/docker/pkg/system"
 	"github.com/docker/go-connections/nat"
 	"github.com/moby/buildkit/frontend/dockerfile/instructions"
 	"github.com/moby/buildkit/frontend/dockerfile/parser"
 	"github.com/moby/buildkit/frontend/dockerfile/shell"
+	"github.com/moby/sys/signal"
 	specs "github.com/opencontainers/image-spec/specs-go/v1"
 	"github.com/pkg/errors"
 )

+ 1 - 1
container/container.go

@@ -31,13 +31,13 @@ import (
 	"github.com/docker/docker/pkg/containerfs"
 	"github.com/docker/docker/pkg/idtools"
 	"github.com/docker/docker/pkg/ioutils"
-	"github.com/docker/docker/pkg/signal"
 	"github.com/docker/docker/pkg/system"
 	"github.com/docker/docker/restartmanager"
 	"github.com/docker/docker/volume"
 	volumemounts "github.com/docker/docker/volume/mounts"
 	units "github.com/docker/go-units"
 	agentexec "github.com/docker/swarmkit/agent/exec"
+	"github.com/moby/sys/signal"
 	"github.com/moby/sys/symlink"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"

+ 1 - 1
container/container_unit_test.go

@@ -10,7 +10,7 @@ import (
 	"github.com/docker/docker/api/types/container"
 	swarmtypes "github.com/docker/docker/api/types/swarm"
 	"github.com/docker/docker/daemon/logger/jsonfilelog"
-	"github.com/docker/docker/pkg/signal"
+	"github.com/moby/sys/signal"
 	"gotest.tools/v3/assert"
 )
 

+ 1 - 1
daemon/container.go

@@ -17,12 +17,12 @@ import (
 	"github.com/docker/docker/image"
 	"github.com/docker/docker/oci/caps"
 	"github.com/docker/docker/opts"
-	"github.com/docker/docker/pkg/signal"
 	"github.com/docker/docker/pkg/system"
 	"github.com/docker/docker/pkg/truncindex"
 	"github.com/docker/docker/runconfig"
 	volumemounts "github.com/docker/docker/volume/mounts"
 	"github.com/docker/go-connections/nat"
+	"github.com/moby/sys/signal"
 	"github.com/opencontainers/selinux/go-selinux"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"

+ 1 - 1
daemon/exec.go

@@ -15,7 +15,7 @@ import (
 	"github.com/docker/docker/daemon/exec"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/pkg/pools"
-	"github.com/docker/docker/pkg/signal"
+	"github.com/moby/sys/signal"
 	"github.com/moby/term"
 	specs "github.com/opencontainers/runtime-spec/specs-go"
 	"github.com/pkg/errors"

+ 1 - 1
daemon/kill.go

@@ -10,7 +10,7 @@ import (
 	containerpkg "github.com/docker/docker/container"
 	"github.com/docker/docker/errdefs"
 	libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
-	"github.com/docker/docker/pkg/signal"
+	"github.com/moby/sys/signal"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 )

+ 0 - 1
pkg/signal/README.md

@@ -1 +0,0 @@
-This package provides helper functions for dealing with signals across various operating systems

+ 52 - 6
pkg/signal/signal_deprecated.go

@@ -1,8 +1,54 @@
-package signal
+// Package signal provides helper functions for dealing with signals across
+// various operating systems.
+package signal // import "github.com/docker/docker/pkg/signal"
 
-import "github.com/docker/docker/pkg/stack"
+import (
+	"github.com/docker/docker/pkg/stack"
+	msignal "github.com/moby/sys/signal"
+)
 
-// DumpStacks appends the runtime stack into file in dir and returns full path
-// to that file.
-// Deprecated: use github.com/docker/docker/pkg/stack.Dump instead.
-var DumpStacks = stack.DumpToFile
+var (
+	// DumpStacks appends the runtime stack into file in dir and returns full path
+	// to that file.
+	// Deprecated: use github.com/docker/docker/pkg/stack.Dump instead.
+	DumpStacks = stack.DumpToFile
+
+	// CatchAll catches all signals and relays them to the specified channel.
+	// SIGURG is not handled, as it's used by the Go runtime to support
+	// preemptable system calls.
+	// Deprecated: use github.com/moby/sys/signal.CatchAll instead
+	CatchAll = msignal.CatchAll
+
+	// StopCatch stops catching the signals and closes the specified channel.
+	// Deprecated: use github.com/moby/sys/signal.StopCatch instead
+	StopCatch = msignal.StopCatch
+
+	// ParseSignal translates a string to a valid syscall signal.
+	// It returns an error if the signal map doesn't include the given signal.
+	// Deprecated: use github.com/moby/sys/signal.ParseSignal instead
+	ParseSignal = msignal.ParseSignal
+
+	// ValidSignalForPlatform returns true if a signal is valid on the platform
+	// Deprecated: use github.com/moby/sys/signal.ValidSignalForPlatform instead
+	ValidSignalForPlatform = msignal.ValidSignalForPlatform
+
+	// SignalMap is a map of signals for the current platform.
+	// Deprecated: use github.com/moby/sys/signal.SignalMap instead
+	SignalMap = msignal.SignalMap
+)
+
+// Signals used in cli/command
+const (
+	// SIGCHLD is a signal sent to a process when a child process terminates, is interrupted, or resumes after being interrupted.
+	// Deprecated: use github.com/moby/sys/signal.SIGCHLD instead
+	SIGCHLD = msignal.SIGCHLD
+	// SIGWINCH is a signal sent to a process when its controlling terminal changes its size
+	// Deprecated: use github.com/moby/sys/signal.SIGWINCH instead
+	SIGWINCH = msignal.SIGWINCH
+	// SIGPIPE is a signal sent to a process when a pipe is written to before the other end is open for reading
+	// Deprecated: use github.com/moby/sys/signal.SIGPIPE instead
+	SIGPIPE = msignal.SIGPIPE
+	// DefaultStopSignal is the syscall signal used to stop a container in unix systems.
+	// Deprecated: use github.com/moby/sys/signal.DefaultStopSignal instead
+	DefaultStopSignal = msignal.DefaultStopSignal
+)

+ 0 - 70
pkg/signal/signal_linux_test.go

@@ -1,70 +0,0 @@
-// +build darwin linux
-
-package signal // import "github.com/docker/docker/pkg/signal"
-
-import (
-	"os"
-	"syscall"
-	"testing"
-	"time"
-)
-
-func TestCatchAll(t *testing.T) {
-	sigs := make(chan os.Signal, 1)
-	CatchAll(sigs)
-	defer StopCatch(sigs)
-
-	listOfSignals := map[string]string{
-		"CONT": syscall.SIGCONT.String(),
-		"HUP":  syscall.SIGHUP.String(),
-		"CHLD": syscall.SIGCHLD.String(),
-		"ILL":  syscall.SIGILL.String(),
-		"FPE":  syscall.SIGFPE.String(),
-		"CLD":  syscall.SIGCLD.String(),
-	}
-
-	for sigStr := range listOfSignals {
-		if signal, ok := SignalMap[sigStr]; ok {
-			_ = syscall.Kill(syscall.Getpid(), signal)
-			s := <-sigs
-			if s.String() != signal.String() {
-				t.Errorf("expected: %q, got: %q", signal, s)
-			}
-		}
-	}
-}
-
-func TestCatchAllIgnoreSigUrg(t *testing.T) {
-	sigs := make(chan os.Signal, 1)
-	CatchAll(sigs)
-	defer StopCatch(sigs)
-
-	err := syscall.Kill(syscall.Getpid(), syscall.SIGURG)
-	if err != nil {
-		t.Fatal(err)
-	}
-	timer := time.NewTimer(1 * time.Second)
-	defer timer.Stop()
-	select {
-	case <-timer.C:
-	case s := <-sigs:
-		t.Fatalf("expected no signals to be handled, but received %q", s.String())
-	}
-}
-
-func TestStopCatch(t *testing.T) {
-	signal := SignalMap["HUP"]
-	channel := make(chan os.Signal, 1)
-	CatchAll(channel)
-	_ = syscall.Kill(syscall.Getpid(), signal)
-	signalString := <-channel
-	if signalString.String() != signal.String() {
-		t.Errorf("expected: %q, got: %q", signal, signalString)
-	}
-
-	StopCatch(channel)
-	_, ok := <-channel
-	if ok {
-		t.Error("expected: !ok, got: ok")
-	}
-}

+ 0 - 45
pkg/signal/signal_test.go

@@ -1,45 +0,0 @@
-package signal // import "github.com/docker/docker/pkg/signal"
-
-import (
-	"syscall"
-	"testing"
-)
-
-func TestParseSignal(t *testing.T) {
-	_, err := ParseSignal("0")
-	expectedErr := "Invalid signal: 0"
-	if err == nil || err.Error() != expectedErr {
-		t.Errorf("expected  %q, but got %v", expectedErr, err)
-	}
-
-	_, err = ParseSignal("SIG")
-	expectedErr = "Invalid signal: SIG"
-	if err == nil || err.Error() != expectedErr {
-		t.Errorf("expected  %q, but got %v", expectedErr, err)
-	}
-
-	for sigStr := range SignalMap {
-		responseSignal, err := ParseSignal(sigStr)
-		if err != nil {
-			t.Error(err)
-		}
-		signal := SignalMap[sigStr]
-		if responseSignal != signal {
-			t.Errorf("expected: %q, got: %q", signal, responseSignal)
-		}
-	}
-}
-
-func TestValidSignalForPlatform(t *testing.T) {
-	isValidSignal := ValidSignalForPlatform(syscall.Signal(0))
-	if isValidSignal {
-		t.Error("expected !isValidSignal")
-	}
-
-	for _, sigN := range SignalMap {
-		isValidSignal = ValidSignalForPlatform(sigN)
-		if !isValidSignal {
-			t.Error("expected isValidSignal")
-		}
-	}
-}

+ 5 - 5
vendor.conf

@@ -9,11 +9,11 @@ github.com/moby/locker                              281af2d563954745bea9d1487c96
 github.com/moby/term                                3f7ff695adc6a35abc925370dd0a4dafb48ec64d
 
 # Note that this dependency uses submodules, providing the github.com/moby/sys/mount,
-# github.com/moby/sys/mountinfo, and github.com/moby/sys/symlink modules. Our vendoring
-# tool (vndr) currently does not support submodules / vendoring sub-paths, so we vendor
-# the top-level moby/sys repository (which contains both) and pick the most recent tag,
-# which could be either `mountinfo/vX.Y.Z`, `mount/vX.Y.Z`, or `symlink/vX.Y.Z`.
-github.com/moby/sys                                 b0f1fd7235275d01bd35cc4421e884e522395f45 # mountinfo/v0.4.1
+# github.com/moby/sys/mountinfo, github.com/moby/sys/signal, and github.com/moby/sys/symlink
+# modules. Our vendoring tool (vndr) currently does not support submodules / vendoring sub-paths,
+# so we vendor the top-level moby/sys repository (which contains both) and pick the most recent tag,
+# which could be either `mountinfo/vX.Y.Z`, `mount/vX.Y.Z`, `signal/vX.Y.Z`, or `symlink/vX.Y.Z`.
+github.com/moby/sys                                 9b0136d132d8e0d1c116a38d7ec9af70d3a59536 # signal/v0.5.0
 
 github.com/creack/pty                               2a38352e8b4d7ab6c336eef107e42a55e72e7fbc # v1.1.11
 github.com/sirupsen/logrus                          bdc0db8ead3853c56b7cd1ac2ba4e11b47d7da6b # v1.8.1

+ 1 - 1
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
 )

+ 5 - 0
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

+ 1 - 1
pkg/signal/signal.go → 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"

+ 1 - 1
pkg/signal/signal_darwin.go → 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"

+ 1 - 1
pkg/signal/signal_freebsd.go → 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"

+ 1 - 1
pkg/signal/signal_linux.go → 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"

+ 1 - 1
pkg/signal/signal_linux_mipsx.go → 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"

+ 1 - 1
pkg/signal/signal_unix.go → 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"

+ 1 - 1
pkg/signal/signal_unsupported.go → 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"

+ 1 - 1
pkg/signal/signal_windows.go → 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"