aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-03-09 17:34:42 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-03-09 17:34:42 +0100
commit92f718ade3789c1ed33be04d03c3214b6ed8f596 (patch)
tree1b75ceda8f1116f88c97d04b0abd4502ca8cf1af /main.go
parent00b5b83dcff4904aeb18760caa193fa3393241e0 (diff)
Added default CTRL+C signal handler.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'main.go')
-rw-r--r--main.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/main.go b/main.go
index 2dfd056..8d1e0eb 100644
--- a/main.go
+++ b/main.go
@@ -26,6 +26,7 @@ import (
"regexp"
"sort"
"strings"
+ "syscall"
"text/tabwriter"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/xaapiv1"
@@ -324,6 +325,20 @@ func main() {
// Start signals monitoring routine
MonitorSignals()
+ // Default callback to handle interrupt signal
+ // Maybe be overwritten by some subcommand (eg. targets commands)
+ err := OnSignals(func(sig os.Signal) {
+ Log.Debugf("Send signal %v (from main)", sig)
+ if IsInterruptSignal(sig) {
+ err := cli.NewExitError("Interrupted\n", int(syscall.EINTR))
+ cli.HandleExitCoder(err)
+ }
+ })
+ if err != nil {
+ cli.NewExitError(err.Error(), 1)
+ return
+ }
+
// Run the cli app
app.Run(os.Args)
}