From 31a968834f685963432b71f189eaafd086be2eb6 Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Tue, 12 Jul 2016 13:54:23 +0100 Subject: [PATCH] ciao-launcher: Ensure cpu profile and logs are flushed Launcher was mistakenly using defer to flush logs and to stop the CPU profiling when shutting down. However, as launcher is quit by calling os.Exit, deferred functions do not get called. This was leading to incomplete CPU profiles being generated. Fixes: #163 Signed-off-by: Mark Ryan --- ciao-launcher/main.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/ciao-launcher/main.go b/ciao-launcher/main.go index 894660a9f..1ec59a950 100644 --- a/ciao-launcher/main.go +++ b/ciao-launcher/main.go @@ -528,32 +528,34 @@ func main() { log.Fatalf("Unable to initialise logs: %v", err) } + glog.Info("Starting Launcher") + + exitCode := 0 + var stopProfile func() if profileFN != nil { - stopProfile := profileFN() - if stopProfile != nil { - defer stopProfile() - } + stopProfile = profileFN() } - defer func() { - glog.Flush() - glog.Info("Exit") - }() - - glog.Info("Starting Launcher") - if hardReset { purgeLauncherState() - os.Exit(0) - } + } else { + setLimits() + + glog.Infof("Launcher will allow a maximum of %d instances", maxInstances) - setLimits() + if err := createMandatoryDirs(); err != nil { + glog.Fatalf("Unable to create mandatory dirs: %v", err) + } - glog.Infof("Launcher will allow a maximum of %d instances", maxInstances) + exitCode = startLauncher() + } - if err := createMandatoryDirs(); err != nil { - glog.Fatalf("Unable to create mandatory dirs: %v", err) + if stopProfile != nil { + stopProfile() } - os.Exit(startLauncher()) + glog.Flush() + glog.Info("Exit") + + os.Exit(exitCode) }