diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-03-24 13:12:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-24 13:12:06 +0100 |
commit | 3dbf2cb5aff67f82e486cd95aca170e44b8fc75a (patch) | |
tree | 0e67d02bcdb5caed701c22b332a4ad6f2bbe6fe6 /pkg/signal/signal_linux.go | |
parent | a2ffd5c230ea6f53ed40ccc60e869164fee41899 (diff) | |
parent | 9536560b4f3a38fbba4ac61c357dd3627fb6cf4e (diff) | |
download | podman-3dbf2cb5aff67f82e486cd95aca170e44b8fc75a.tar.gz podman-3dbf2cb5aff67f82e486cd95aca170e44b8fc75a.tar.bz2 podman-3dbf2cb5aff67f82e486cd95aca170e44b8fc75a.zip |
Merge pull request #5581 from baude/v2containers
podmanv2 add core container commands
Diffstat (limited to 'pkg/signal/signal_linux.go')
-rw-r--r-- | pkg/signal/signal_linux.go | 19 |
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) +} |