forked from TrueCloudLab/restic
Run cleanup handlers in main function
This commit is contained in:
parent
dac89bf544
commit
76817da922
2 changed files with 8 additions and 0 deletions
|
@ -13,6 +13,7 @@ import (
|
||||||
var cleanupHandlers struct {
|
var cleanupHandlers struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
list []func() error
|
list []func() error
|
||||||
|
done bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var stderr = os.Stderr
|
var stderr = os.Stderr
|
||||||
|
@ -39,6 +40,11 @@ func RunCleanupHandlers() {
|
||||||
cleanupHandlers.Lock()
|
cleanupHandlers.Lock()
|
||||||
defer cleanupHandlers.Unlock()
|
defer cleanupHandlers.Unlock()
|
||||||
|
|
||||||
|
if cleanupHandlers.done {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cleanupHandlers.done = true
|
||||||
|
|
||||||
for _, f := range cleanupHandlers.list {
|
for _, f := range cleanupHandlers.list {
|
||||||
err := f()
|
err := f()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -32,6 +32,8 @@ func main() {
|
||||||
fmt.Fprintf(os.Stderr, "\nthe `unlock` command can be used to remove stale locks\n")
|
fmt.Fprintf(os.Stderr, "\nthe `unlock` command can be used to remove stale locks\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RunCleanupHandlers()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue