signal

package
v20.10.14+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

This package provides helper functions for dealing with signals across various operating systems

Documentation

Overview

Package signal provides helper functions for dealing with signals across various operating systems.

Index

Constants

View Source
const (
	// SIGCHLD is a signal sent to a process when a child process terminates, is interrupted, or resumes after being interrupted.
	SIGCHLD = syscall.SIGCHLD
	// SIGWINCH is a signal sent to a process when its controlling terminal changes its size
	SIGWINCH = syscall.SIGWINCH
	// SIGPIPE is a signal sent to a process when a pipe is written to before the other end is open for reading
	SIGPIPE = syscall.SIGPIPE
	// DefaultStopSignal is the syscall signal used to stop a container in unix systems.
	DefaultStopSignal = "SIGTERM"
)

Variables

View Source
var SignalMap = map[string]syscall.Signal{
	"ABRT":     unix.SIGABRT,
	"ALRM":     unix.SIGALRM,
	"BUS":      unix.SIGBUS,
	"CHLD":     unix.SIGCHLD,
	"CLD":      unix.SIGCLD,
	"CONT":     unix.SIGCONT,
	"FPE":      unix.SIGFPE,
	"HUP":      unix.SIGHUP,
	"ILL":      unix.SIGILL,
	"INT":      unix.SIGINT,
	"IO":       unix.SIGIO,
	"IOT":      unix.SIGIOT,
	"KILL":     unix.SIGKILL,
	"PIPE":     unix.SIGPIPE,
	"POLL":     unix.SIGPOLL,
	"PROF":     unix.SIGPROF,
	"PWR":      unix.SIGPWR,
	"QUIT":     unix.SIGQUIT,
	"SEGV":     unix.SIGSEGV,
	"STKFLT":   unix.SIGSTKFLT,
	"STOP":     unix.SIGSTOP,
	"SYS":      unix.SIGSYS,
	"TERM":     unix.SIGTERM,
	"TRAP":     unix.SIGTRAP,
	"TSTP":     unix.SIGTSTP,
	"TTIN":     unix.SIGTTIN,
	"TTOU":     unix.SIGTTOU,
	"URG":      unix.SIGURG,
	"USR1":     unix.SIGUSR1,
	"USR2":     unix.SIGUSR2,
	"VTALRM":   unix.SIGVTALRM,
	"WINCH":    unix.SIGWINCH,
	"XCPU":     unix.SIGXCPU,
	"XFSZ":     unix.SIGXFSZ,
	"RTMIN":    sigrtmin,
	"RTMIN+1":  sigrtmin + 1,
	"RTMIN+2":  sigrtmin + 2,
	"RTMIN+3":  sigrtmin + 3,
	"RTMIN+4":  sigrtmin + 4,
	"RTMIN+5":  sigrtmin + 5,
	"RTMIN+6":  sigrtmin + 6,
	"RTMIN+7":  sigrtmin + 7,
	"RTMIN+8":  sigrtmin + 8,
	"RTMIN+9":  sigrtmin + 9,
	"RTMIN+10": sigrtmin + 10,
	"RTMIN+11": sigrtmin + 11,
	"RTMIN+12": sigrtmin + 12,
	"RTMIN+13": sigrtmin + 13,
	"RTMIN+14": sigrtmin + 14,
	"RTMIN+15": sigrtmin + 15,
	"RTMAX-14": sigrtmax - 14,
	"RTMAX-13": sigrtmax - 13,
	"RTMAX-12": sigrtmax - 12,
	"RTMAX-11": sigrtmax - 11,
	"RTMAX-10": sigrtmax - 10,
	"RTMAX-9":  sigrtmax - 9,
	"RTMAX-8":  sigrtmax - 8,
	"RTMAX-7":  sigrtmax - 7,
	"RTMAX-6":  sigrtmax - 6,
	"RTMAX-5":  sigrtmax - 5,
	"RTMAX-4":  sigrtmax - 4,
	"RTMAX-3":  sigrtmax - 3,
	"RTMAX-2":  sigrtmax - 2,
	"RTMAX-1":  sigrtmax - 1,
	"RTMAX":    sigrtmax,
}

SignalMap is a map of Linux signals.

Functions

func CatchAll

func CatchAll(sigc chan os.Signal)

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.

func DumpStacks

func DumpStacks(dir string) (string, error)

DumpStacks appends the runtime stack into file in dir and returns full path to that file.

func ParseSignal

func ParseSignal(rawSignal string) (syscall.Signal, error)

ParseSignal translates a string to a valid syscall signal. It returns an error if the signal map doesn't include the given signal.

func StopCatch

func StopCatch(sigc chan os.Signal)

StopCatch stops catching the signals and closes the specified channel.

func Trap

func Trap(cleanup func(), logger interface {
	Info(args ...interface{})
})

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 ValidSignalForPlatform

func ValidSignalForPlatform(sig syscall.Signal) bool

ValidSignalForPlatform returns true if a signal is valid on the platform

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL