summaryrefslogtreecommitdiff
path: root/pkg/signal
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/signal')
-rw-r--r--pkg/signal/signal_linux.go19
-rw-r--r--pkg/signal/signal_unsupported.go6
2 files changed, 23 insertions, 2 deletions
diff --git a/pkg/signal/signal_linux.go b/pkg/signal/signal_linux.go
index 3d549898f..76ab16ec7 100644
--- a/pkg/signal/signal_linux.go
+++ b/pkg/signal/signal_linux.go
@@ -104,11 +104,11 @@ func ParseSignal(rawSignal string) (syscall.Signal, error) {
}
return syscall.Signal(s), nil
}
- signal, ok := signalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")]
+ sig, ok := signalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")]
if !ok {
return -1, fmt.Errorf("invalid signal: %s", rawSignal)
}
- return signal, nil
+ return sig, nil
}
// CatchAll catches all signals and relays them to the specified channel.
@@ -125,3 +125,18 @@ func StopCatch(sigc chan os.Signal) {
signal.Stop(sigc)
close(sigc)
}
+
+// ParseSignalNameOrNumber translates a string to a valid syscall signal. Input
+// can be a name or number representation i.e. "KILL" "9"
+func ParseSignalNameOrNumber(rawSignal string) (syscall.Signal, error) {
+ s, err := ParseSignal(rawSignal)
+ if err == nil {
+ return s, nil
+ }
+ for k, v := range signalMap {
+ if k == strings.ToUpper(rawSignal) {
+ return v, nil
+ }
+ }
+ return -1, fmt.Errorf("invalid signal: %s", rawSignal)
+}
diff --git a/pkg/signal/signal_unsupported.go b/pkg/signal/signal_unsupported.go
index 0a92a5b3a..f946d802d 100644
--- a/pkg/signal/signal_unsupported.go
+++ b/pkg/signal/signal_unsupported.go
@@ -26,3 +26,9 @@ func CatchAll(sigc chan os.Signal) {
func StopCatch(sigc chan os.Signal) {
panic("Unsupported on non-linux platforms")
}
+
+// ParseSignalNameOrNumber translates a string to a valid syscall signal. Input
+// can be a name or number representation i.e. "KILL" "9"
+func ParseSignalNameOrNumber(rawSignal string) (syscall.Signal, error) {
+ return 0, fmt.Errorf("unsupported on non-linux platforms")
+}