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