Added default CTRL+C signal handler.
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Fri, 9 Mar 2018 16:34:42 +0000 (17:34 +0100)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Fri, 9 Mar 2018 16:34:42 +0000 (17:34 +0100)
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
main.go

diff --git a/main.go b/main.go
index 2dfd056..8d1e0eb 100644 (file)
--- 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)
 }