From 4a8cb1229490c8d77c7e38e223f241182ceb0008 Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Wed, 13 Aug 2025 10:03:18 -0400 Subject: [PATCH] Mrntt: initializeSalmanoff exceptions handled in outermode catch block We don't post a message to the event loop telling it to execute initializeSalmanoff anymore. We now execute it in the main control flow. Also, we've unified the logic to call finalizeReq() in response to exceptions in the outermost try block. --- smocore/marionette/marionette.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/smocore/marionette/marionette.cpp b/smocore/marionette/marionette.cpp index 277e6ca..699988b 100644 --- a/smocore/marionette/marionette.cpp +++ b/smocore/marionette/marionette.cpp @@ -39,6 +39,7 @@ void ComponentThread::marionetteMain(ComponentThread& self) self.initializeTls(); mrntt::exitCode = EXIT_SUCCESS; static boost::asio::signal_set signals(self.getIoService(), SIGINT); + bool callFinalizeReq = false; try { // Register SIGINT (Ctrl+C) handler to request user shutdown @@ -67,9 +68,9 @@ void ComponentThread::marionetteMain(ComponentThread& self) throw JustPrintUsageNoError(options); } + initializeSalmanoff(); self.getIoService().post([]() { - initializeSalmanoff(); mind.initialize(); }); @@ -110,42 +111,46 @@ void ComponentThread::marionetteMain(ComponentThread& self) } std::cout << __func__ << ": Exited event loop" << "\n"; - shutdownSalmanoff(); } catch (const OptionParser::Exception& e) { - std::ostream &out = std::cout; + std::ostream *out = &std::cout; std::string outUsageMsg; if (typeid(e) == typeid(OptionsParserError)) { mrntt::exitCode = EXIT_FAILURE; + out = &std::cerr; outUsageMsg = std::string(__func__) + ": "; } - out << outUsageMsg << e.what() << std::endl; - mind.finalizeReq([]{ - mrntt::mrntt->getIoService().stop(); - }); - self.getIoService().reset(); - self.getIoService().run(); - return; + *out << outUsageMsg << e.what() << std::endl; + callFinalizeReq = true; } catch (const std::exception& e) { std::cerr << __func__ << ": Exception occurred: " << e.what() << std::endl; mrntt::exitCode = EXIT_FAILURE; - return; + callFinalizeReq = true; } catch (...) { std::cerr << __func__ << ": Unknown exception occurred" << std::endl; mrntt::exitCode = EXIT_FAILURE; - return; + callFinalizeReq = true; } - std::cout << __func__ << ": Exiting normally" << std::endl; + if (callFinalizeReq) + { + mind.finalizeReq([]{ + mrntt::mrntt->getIoService().stop(); + }); + self.getIoService().reset(); + self.getIoService().run(); + } + + shutdownSalmanoff(); } } // namespace smo