summaryrefslogtreecommitdiff
path: root/pkg/signal/signal_linux.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-03-21 13:47:07 -0500
committerBrent Baude <bbaude@redhat.com>2020-03-22 13:24:45 -0500
commit9536560b4f3a38fbba4ac61c357dd3627fb6cf4e (patch)
tree8d8cf1471d590752357f06088044d1dcf752ee70 /pkg/signal/signal_linux.go
parent2ffff3c6abacad855ce7ddf8290514ebe1424d7f (diff)
downloadpodman-9536560b4f3a38fbba4ac61c357dd3627fb6cf4e.tar.gz
podman-9536560b4f3a38fbba4ac61c357dd3627fb6cf4e.tar.bz2
podman-9536560b4f3a38fbba4ac61c357dd3627fb6cf4e.zip
podmanv2 add core container commands
add core container commands for podmanv2: kill, pause, restart, rm, stop, unpause Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/signal/signal_linux.go')
-rw-r--r--pkg/signal/signal_linux.go19
1 files changed, 17 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)
+}