vspd: Run deferred tasks on os.Exit.
Any tasks deferred in the main func will not execute if os.Exit is called. Moving application logic down into a new func which is called by main works around this limitation.
This commit is contained in:
parent
3967d9e24e
commit
e38032ba2f
@ -10,19 +10,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
os.Exit(run())
|
||||||
|
}
|
||||||
|
|
||||||
|
// run is the real main function for vspd. It is necessary to work around the
|
||||||
|
// fact that deferred functions do not run when os.Exit() is called.
|
||||||
|
func run() int {
|
||||||
// Load config file and parse CLI args.
|
// Load config file and parse CLI args.
|
||||||
cfg, err := loadConfig()
|
cfg, err := loadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "loadConfig error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "loadConfig error: %v\n", err)
|
||||||
os.Exit(1)
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
vspd, err := newVspd(cfg)
|
vspd, err := newVspd(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "newVspd error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "newVspd error: %v\n", err)
|
||||||
os.Exit(1)
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run until an exit code is returned.
|
return vspd.run()
|
||||||
os.Exit(vspd.run())
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user