Skip to content

Commit 47dd7c7

Browse files
author
Mike Morris
committed
Add proper signal handling for Interrupt and Quit signals
1 parent 4853c30 commit 47dd7c7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import (
1919
"github.com/mmmorris1975/simple-logger"
2020
"os"
2121
"os/exec"
22+
"os/signal"
2223
"path/filepath"
2324
"runtime"
2425
"strings"
26+
"syscall"
2527
"time"
2628
)
2729

@@ -50,6 +52,8 @@ var (
5052
ses *session.Session
5153
cfg *config.AwsConfig
5254
usr *credlib.AwsIdentity
55+
56+
sigCh = make(chan os.Signal, 3)
5357
)
5458

5559
func init() {
@@ -103,6 +107,14 @@ func init() {
103107
}
104108

105109
func main() {
110+
signal.Notify(sigCh, os.Interrupt, syscall.SIGQUIT)
111+
go func() {
112+
for {
113+
sig := <-sigCh
114+
log.Debugf("Got signal: %s", sig.String())
115+
}
116+
}()
117+
106118
kingpin.CommandLine.Interspersed(false)
107119
kingpin.Parse()
108120

0 commit comments

Comments
 (0)