summaryrefslogtreecommitdiffstats
path: root/golib/eows/eows-signal.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-08-07 18:08:27 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-08-07 19:30:25 +0200
commit7496dbabaf710a9e0f3b599c83163adddfcb8870 (patch)
treed2ab9f9f89edc0f381a71a967d920cef3e150be5 /golib/eows/eows-signal.go
parent62e2996fcbcd704653d3043046c451fbc044918b (diff)
Added eows (Exec Over WebSocket) package.
Diffstat (limited to 'golib/eows/eows-signal.go')
-rw-r--r--golib/eows/eows-signal.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/golib/eows/eows-signal.go b/golib/eows/eows-signal.go
new file mode 100644
index 0000000..5db5366
--- /dev/null
+++ b/golib/eows/eows-signal.go
@@ -0,0 +1,48 @@
+// +build !windows
+
+// Package eows is used to Execute commands Over WebSocket
+package eows
+
+import (
+ "fmt"
+ "os"
+ "syscall"
+)
+
+// Signal sends a signal to the running command / process
+func (e *ExecOverWS) Signal(signal string) error {
+ var sig os.Signal
+ switch signal {
+ case "quit", "SIGQUIT":
+ sig = syscall.SIGQUIT
+ case "terminated", "SIGTERM":
+ sig = syscall.SIGTERM
+ case "interrupt", "SIGINT":
+ sig = syscall.SIGINT
+ case "aborted", "SIGABRT":
+ sig = syscall.SIGABRT
+ case "continued", "SIGCONT":
+ sig = syscall.SIGCONT
+ case "hangup", "SIGHUP":
+ sig = syscall.SIGHUP
+ case "killed", "SIGKILL":
+ sig = syscall.SIGKILL
+ case "stopped (signal)", "SIGSTOP":
+ sig = syscall.SIGSTOP
+ case "stopped", "SIGTSTP":
+ sig = syscall.SIGTSTP
+ case "user defined signal 1", "SIGUSR1":
+ sig = syscall.SIGUSR1
+ case "user defined signal 2", "SIGUSR2":
+ sig = syscall.SIGUSR2
+ default:
+ return fmt.Errorf("Unsupported signal")
+ }
+
+ if e.proc == nil {
+ return fmt.Errorf("Cannot retrieve process")
+ }
+
+ fmt.Printf("SEND signal %v to proc %v\n", sig, e.proc.Pid)
+ return e.proc.Signal(sig)
+}