aboutsummaryrefslogtreecommitdiffstats
path: root/util/interrupt/cleaner.go
diff options
context:
space:
mode:
Diffstat (limited to 'util/interrupt/cleaner.go')
-rw-r--r--util/interrupt/cleaner.go28
1 files changed, 15 insertions, 13 deletions
diff --git a/util/interrupt/cleaner.go b/util/interrupt/cleaner.go
index 58dd6b07..3f6c3afb 100644
--- a/util/interrupt/cleaner.go
+++ b/util/interrupt/cleaner.go
@@ -14,19 +14,21 @@ var cleaners []Cleaner
var active = false
// RegisterCleaner is responsible for regisreting a cleaner function. When a function is registered, the Signal watcher is started in a goroutine.
-func RegisterCleaner(f Cleaner) {
- cleaners = append(cleaners, f)
- if !active {
- active = true
- go func() {
- ch := make(chan os.Signal, 1)
- signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
- <-ch
- // Prevent un-terminated ^C character in terminal
- fmt.Println()
- clean()
- os.Exit(1)
- }()
+func RegisterCleaner(f ...Cleaner) {
+ for _, fn := range f {
+ cleaners = append(cleaners, fn)
+ if !active {
+ active = true
+ go func() {
+ ch := make(chan os.Signal, 1)
+ signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
+ <-ch
+ // Prevent un-terminated ^C character in terminal
+ fmt.Println()
+ clean()
+ os.Exit(1)
+ }()
+ }
}
}