Create portable signalMap
Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)
This commit is contained in:
parent
c563262239
commit
10dc16dcd3
5 changed files with 121 additions and 150 deletions
|
@ -5,6 +5,14 @@ import (
|
|||
"os/signal"
|
||||
)
|
||||
|
||||
func CatchAll(sigc chan os.Signal) {
|
||||
handledSigs := []os.Signal{}
|
||||
for _, s := range signalMap {
|
||||
handledSigs = append(handledSigs, s)
|
||||
}
|
||||
signal.Notify(sigc, handledSigs...)
|
||||
}
|
||||
|
||||
func StopCatch(sigc chan os.Signal) {
|
||||
signal.Stop(sigc)
|
||||
close(sigc)
|
||||
|
|
|
@ -1,44 +1,40 @@
|
|||
package signal
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func CatchAll(sigc chan os.Signal) {
|
||||
signal.Notify(sigc,
|
||||
syscall.SIGABRT,
|
||||
syscall.SIGALRM,
|
||||
syscall.SIGBUS,
|
||||
syscall.SIGCHLD,
|
||||
syscall.SIGCONT,
|
||||
syscall.SIGEMT,
|
||||
syscall.SIGFPE,
|
||||
syscall.SIGHUP,
|
||||
syscall.SIGILL,
|
||||
syscall.SIGINFO,
|
||||
syscall.SIGINT,
|
||||
syscall.SIGIO,
|
||||
syscall.SIGIOT,
|
||||
syscall.SIGKILL,
|
||||
syscall.SIGPIPE,
|
||||
syscall.SIGPROF,
|
||||
syscall.SIGQUIT,
|
||||
syscall.SIGSEGV,
|
||||
syscall.SIGSTOP,
|
||||
syscall.SIGSYS,
|
||||
syscall.SIGTERM,
|
||||
syscall.SIGTRAP,
|
||||
syscall.SIGTSTP,
|
||||
syscall.SIGTTIN,
|
||||
syscall.SIGTTOU,
|
||||
syscall.SIGURG,
|
||||
syscall.SIGUSR1,
|
||||
syscall.SIGUSR2,
|
||||
syscall.SIGVTALRM,
|
||||
syscall.SIGWINCH,
|
||||
syscall.SIGXCPU,
|
||||
syscall.SIGXFSZ,
|
||||
)
|
||||
var signalMap = map[string]syscall.Signal{
|
||||
"ABRT": syscall.SIGABRT,
|
||||
"ALRM": syscall.SIGALRM,
|
||||
"BUG": syscall.SIGBUS,
|
||||
"CHLD": syscall.SIGCHLD,
|
||||
"CONT": syscall.SIGCONT,
|
||||
"EMT": syscall.SIGEMT,
|
||||
"FPE": syscall.SIGFPE,
|
||||
"HUP": syscall.SIGHUP,
|
||||
"ILL": syscall.SIGILL,
|
||||
"INFO": syscall.SIGINFO,
|
||||
"INT": syscall.SIGINT,
|
||||
"IO": syscall.SIGIO,
|
||||
"IOT": syscall.SIGIOT,
|
||||
"KILL": syscall.SIGKILL,
|
||||
"PIPE": syscall.SIGPIPE,
|
||||
"PROF": syscall.SIGPROF,
|
||||
"QUIT": syscall.SIGQUIT,
|
||||
"SEGV": syscall.SIGSEGV,
|
||||
"STOP": syscall.SIGSTOP,
|
||||
"SYS": syscall.SIGSYS,
|
||||
"TERM": syscall.SIGTERM,
|
||||
"TRAP": syscall.SIGTRAP,
|
||||
"TSTP": syscall.SIGTSTP,
|
||||
"TTIN": syscall.SIGTTIN,
|
||||
"TTOU": syscall.SIGTTOU,
|
||||
"URG": syscall.SIGURG,
|
||||
"USR1": syscall.SIGUSR1,
|
||||
"USR2": syscall.SIGUSR2,
|
||||
"VTALRM": syscall.SIGVTALRM,
|
||||
"WINCH": syscall.SIGWINCH,
|
||||
"XCPU": syscall.SIGXCPU,
|
||||
"XFSZ": syscall.SIGXFSZ,
|
||||
}
|
||||
|
|
|
@ -6,37 +6,39 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
func CatchAll(sigc chan os.Signal) {
|
||||
signal.Notify(sigc,
|
||||
syscall.SIGABRT,
|
||||
syscall.SIGALRM,
|
||||
syscall.SIGBUS,
|
||||
syscall.SIGCHLD,
|
||||
syscall.SIGCONT,
|
||||
syscall.SIGFPE,
|
||||
syscall.SIGHUP,
|
||||
syscall.SIGILL,
|
||||
syscall.SIGINT,
|
||||
syscall.SIGIO,
|
||||
syscall.SIGIOT,
|
||||
syscall.SIGKILL,
|
||||
syscall.SIGPIPE,
|
||||
syscall.SIGPROF,
|
||||
syscall.SIGQUIT,
|
||||
syscall.SIGSEGV,
|
||||
syscall.SIGSTOP,
|
||||
syscall.SIGSYS,
|
||||
syscall.SIGTERM,
|
||||
syscall.SIGTRAP,
|
||||
syscall.SIGTSTP,
|
||||
syscall.SIGTTIN,
|
||||
syscall.SIGTTOU,
|
||||
syscall.SIGURG,
|
||||
syscall.SIGUSR1,
|
||||
syscall.SIGUSR2,
|
||||
syscall.SIGVTALRM,
|
||||
syscall.SIGWINCH,
|
||||
syscall.SIGXCPU,
|
||||
syscall.SIGXFSZ,
|
||||
)
|
||||
var signalMap = map[string]syscall.Signal{
|
||||
"ABRT": syscall.SIGABRT,
|
||||
"ALRM": syscall.SIGALRM,
|
||||
"BUF": syscall.SIGBUS,
|
||||
"CHLD": syscall.SIGCHLD,
|
||||
"CONT": syscall.SIGCONT,
|
||||
"EMT": syscall.SIGEMT,
|
||||
"FPE": syscall.SIGFPE,
|
||||
"HUP": syscall.SIGHUP,
|
||||
"ILL": syscall.SIGILL,
|
||||
"INFO": syscall.SIGINFO,
|
||||
"INT": syscall.SIGINT,
|
||||
"IO": syscall.SIGIO,
|
||||
"IOT": syscall.SIGIOT,
|
||||
"KILL": syscall.SIGKILL,
|
||||
"LWP": syscall.SIGLWP,
|
||||
"PIPE": syscall.SIGPIPE,
|
||||
"PROF": syscall.SIGPROF,
|
||||
"QUIT": syscall.SIGQUIT,
|
||||
"SEGV": syscall.SIGSEGV,
|
||||
"STOP": syscall.SIGSTOP,
|
||||
"SYS": syscall.SIGSYS,
|
||||
"TERM": syscall.SIGTERM,
|
||||
"THR": syscall.SIGTHR,
|
||||
"TRAP": syscall.SIGTRAP,
|
||||
"TSTP": syscall.SIGTSTP,
|
||||
"TTIN": syscall.SIGTTIN,
|
||||
"TTOU": syscall.SIGTTOU,
|
||||
"URG": syscall.SIGURG,
|
||||
"USR1": syscall.SIGUSR1,
|
||||
"USR2": syscall.SIGUSR2,
|
||||
"VTALRM": syscall.SIGVTALRM,
|
||||
"WINCH": syscall.SIGWINCH,
|
||||
"XCPU": syscall.SIGXCPU,
|
||||
"XFSZ": syscall.SIGXFSZ,
|
||||
}
|
||||
|
|
|
@ -1,87 +1,43 @@
|
|||
package signal
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var signalMap = map[string]syscall.Signal{}
|
||||
|
||||
/*
|
||||
syscall.SIGABRT,
|
||||
syscall.SIGALRM,
|
||||
syscall.SIGBUS,
|
||||
syscall.SIGCHLD,
|
||||
syscall.SIGCLD,
|
||||
syscall.SIGCONT,
|
||||
syscall.SIGFPE,
|
||||
syscall.SIGHUP,
|
||||
syscall.SIGILL,
|
||||
syscall.SIGINT,
|
||||
syscall.SIGIO,
|
||||
syscall.SIGIOT,
|
||||
syscall.SIGKILL,
|
||||
syscall.SIGPIPE,
|
||||
syscall.SIGPOLL,
|
||||
syscall.SIGPROF,
|
||||
syscall.SIGPWR,
|
||||
syscall.SIGQUIT,
|
||||
syscall.SIGSEGV,
|
||||
syscall.SIGSTKFLT,
|
||||
syscall.SIGSTOP,
|
||||
syscall.SIGSYS,
|
||||
syscall.SIGTERM,
|
||||
syscall.SIGTRAP,
|
||||
syscall.SIGTSTP,
|
||||
syscall.SIGTTIN,
|
||||
syscall.SIGTTOU,
|
||||
syscall.SIGUNUSED,
|
||||
syscall.SIGURG,
|
||||
syscall.SIGUSR1,
|
||||
syscall.SIGUSR2,
|
||||
syscall.SIGVTALRM,
|
||||
syscall.SIGWINCH,
|
||||
syscall.SIGXCPU,
|
||||
syscall.SIGXFSZ,
|
||||
*/
|
||||
|
||||
func CatchAll(sigc chan os.Signal) {
|
||||
signal.Notify(sigc,
|
||||
syscall.SIGABRT,
|
||||
syscall.SIGALRM,
|
||||
syscall.SIGBUS,
|
||||
syscall.SIGCHLD,
|
||||
syscall.SIGCLD,
|
||||
syscall.SIGCONT,
|
||||
syscall.SIGFPE,
|
||||
syscall.SIGHUP,
|
||||
syscall.SIGILL,
|
||||
syscall.SIGINT,
|
||||
syscall.SIGIO,
|
||||
syscall.SIGIOT,
|
||||
syscall.SIGKILL,
|
||||
syscall.SIGPIPE,
|
||||
syscall.SIGPOLL,
|
||||
syscall.SIGPROF,
|
||||
syscall.SIGPWR,
|
||||
syscall.SIGQUIT,
|
||||
syscall.SIGSEGV,
|
||||
syscall.SIGSTKFLT,
|
||||
syscall.SIGSTOP,
|
||||
syscall.SIGSYS,
|
||||
syscall.SIGTERM,
|
||||
syscall.SIGTRAP,
|
||||
syscall.SIGTSTP,
|
||||
syscall.SIGTTIN,
|
||||
syscall.SIGTTOU,
|
||||
syscall.SIGUNUSED,
|
||||
syscall.SIGURG,
|
||||
syscall.SIGUSR1,
|
||||
syscall.SIGUSR2,
|
||||
syscall.SIGVTALRM,
|
||||
syscall.SIGWINCH,
|
||||
syscall.SIGXCPU,
|
||||
syscall.SIGXFSZ,
|
||||
)
|
||||
var signalMap = map[string]syscall.Signal{
|
||||
"ABRT": syscall.SIGABRT,
|
||||
"ALRM": syscall.SIGALRM,
|
||||
"BUS": syscall.SIGBUS,
|
||||
"CHLD": syscall.SIGCHLD,
|
||||
"CLD": syscall.SIGCLD,
|
||||
"CONT": syscall.SIGCONT,
|
||||
"FPE": syscall.SIGFPE,
|
||||
"HUP": syscall.SIGHUP,
|
||||
"ILL": syscall.SIGILL,
|
||||
"INT": syscall.SIGINT,
|
||||
"IO": syscall.SIGIO,
|
||||
"IOT": syscall.SIGIOT,
|
||||
"KILL": syscall.SIGKILL,
|
||||
"PIPE": syscall.SIGPIPE,
|
||||
"POLL": syscall.SIGPOLL,
|
||||
"PROF": syscall.SIGPROF,
|
||||
"PWR": syscall.SIGPWR,
|
||||
"QUIT": syscall.SIGQUIT,
|
||||
"SEGV": syscall.SIGSEGV,
|
||||
"STKFLT": syscall.SIGSTKFLT,
|
||||
"STOP": syscall.SIGSTOP,
|
||||
"SYS": syscall.SIGSYS,
|
||||
"TERM": syscall.SIGTERM,
|
||||
"TRAP": syscall.SIGTRAP,
|
||||
"TSTP": syscall.SIGTSTP,
|
||||
"TTIN": syscall.SIGTTIN,
|
||||
"TTOU": syscall.SIGTTOU,
|
||||
"UNUSED": syscall.SIGUNUSED,
|
||||
"URG": syscall.SIGURG,
|
||||
"USR1": syscall.SIGUSR1,
|
||||
"USR2": syscall.SIGUSR2,
|
||||
"VTALRM": syscall.SIGVTALRM,
|
||||
"WINCH": syscall.SIGWINCH,
|
||||
"XCPU": syscall.SIGXCPU,
|
||||
"XFSZ": syscall.SIGXFSZ,
|
||||
}
|
||||
|
|
9
pkg/signal/signal_unsupported.go
Normal file
9
pkg/signal/signal_unsupported.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
// +build !linux,!darwin,!freebsd
|
||||
|
||||
package signal
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var signalMap = map[string]syscall.Signal{}
|
Loading…
Reference in a new issue