diff options
Diffstat (limited to 'util/interrupt/cleaner.go')
-rw-r--r-- | util/interrupt/cleaner.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/util/interrupt/cleaner.go b/util/interrupt/cleaner.go index 3f6c3afb..76c9d04d 100644 --- a/util/interrupt/cleaner.go +++ b/util/interrupt/cleaner.go @@ -16,7 +16,7 @@ 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) { for _, fn := range f { - cleaners = append(cleaners, fn) + cleaners = append([]Cleaner{fn}, cleaners...) if !active { active = true go func() { @@ -25,18 +25,25 @@ func RegisterCleaner(f ...Cleaner) { <-ch // Prevent un-terminated ^C character in terminal fmt.Println() - clean() + fmt.Println("Cleaning") + errl := Clean() + for _, err := range errl { + fmt.Println(err) + } os.Exit(1) }() } } } -// Clean invokes all registered cleanup functions -func clean() { - fmt.Println("Cleaning") +// Clean invokes all registered cleanup functions, and returns a list of errors, if they exist. +func Clean() (errorlist []error) { for _, f := range cleaners { - _ = f() + err := f() + if err != nil { + errorlist = append(errorlist, err) + } } cleaners = []Cleaner{} + return } |