diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-03-09 17:34:42 +0100 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-03-09 17:34:42 +0100 |
commit | 92f718ade3789c1ed33be04d03c3214b6ed8f596 (patch) | |
tree | 1b75ceda8f1116f88c97d04b0abd4502ca8cf1af | |
parent | 00b5b83dcff4904aeb18760caa193fa3393241e0 (diff) |
Added default CTRL+C signal handler.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
-rw-r--r-- | main.go | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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) } |