mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
![Sebastiaan van Stijn](/assets/img/avatar_default.png)
Do not handle SIGURG on Linux, as in go1.14+, the go runtime issues SIGURG as an interrupt to support preemptable system calls on Linux. This issue was caught in TestCatchAll, which could fail when updating to Go 1.14 or above; === Failed === FAIL: pkg/signal TestCatchAll (0.01s) signal_linux_test.go:32: assertion failed: urgent I/O condition (string) != continued (string) signal_linux_test.go:32: assertion failed: continued (string) != hangup (string) signal_linux_test.go:32: assertion failed: hangup (string) != child exited (string) signal_linux_test.go:32: assertion failed: child exited (string) != illegal instruction (string) signal_linux_test.go:32: assertion failed: illegal instruction (string) != floating point exception (string) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
// Package signal provides helper functions for dealing with signals across
|
|
// various operating systems.
|
|
package signal // import "github.com/docker/docker/pkg/signal"
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"strconv"
|
|
"strings"
|
|
"syscall"
|
|
)
|
|
|
|
// CatchAll catches all signals and relays them to the specified channel.
|
|
// On Linux, SIGURG is not handled, as it's used by the Go runtime to support
|
|
// preemptable system calls.
|
|
func CatchAll(sigc chan os.Signal) {
|
|
var handledSigs []os.Signal
|
|
for _, s := range SignalMap {
|
|
if isRuntimeSig(s) {
|
|
// Do not handle SIGURG on Linux, as in go1.14+, the go runtime issues
|
|
// SIGURG as an interrupt to support preemptable system calls on Linux.
|
|
continue
|
|
}
|
|
handledSigs = append(handledSigs, s)
|
|
}
|
|
signal.Notify(sigc, handledSigs...)
|
|
}
|
|
|
|
// StopCatch stops catching the signals and closes the specified channel.
|
|
func StopCatch(sigc chan os.Signal) {
|
|
signal.Stop(sigc)
|
|
close(sigc)
|
|
}
|
|
|
|
// ParseSignal translates a string to a valid syscall signal.
|
|
// It returns an error if the signal map doesn't include the given signal.
|
|
func ParseSignal(rawSignal string) (syscall.Signal, error) {
|
|
s, err := strconv.Atoi(rawSignal)
|
|
if err == nil {
|
|
if s == 0 {
|
|
return -1, fmt.Errorf("Invalid signal: %s", rawSignal)
|
|
}
|
|
return syscall.Signal(s), nil
|
|
}
|
|
signal, ok := SignalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")]
|
|
if !ok {
|
|
return -1, fmt.Errorf("Invalid signal: %s", rawSignal)
|
|
}
|
|
return signal, nil
|
|
}
|
|
|
|
// ValidSignalForPlatform returns true if a signal is valid on the platform
|
|
func ValidSignalForPlatform(sig syscall.Signal) bool {
|
|
for _, v := range SignalMap {
|
|
if v == sig {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|