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.
This commit is contained in:
2025-08-13 10:03:18 -04:00
parent b6b2ce7ada
commit 4a8cb12294
+18 -13
View File
@@ -39,6 +39,7 @@ void ComponentThread::marionetteMain(ComponentThread& self)
self.initializeTls(); self.initializeTls();
mrntt::exitCode = EXIT_SUCCESS; mrntt::exitCode = EXIT_SUCCESS;
static boost::asio::signal_set signals(self.getIoService(), SIGINT); static boost::asio::signal_set signals(self.getIoService(), SIGINT);
bool callFinalizeReq = false;
try { try {
// Register SIGINT (Ctrl+C) handler to request user shutdown // Register SIGINT (Ctrl+C) handler to request user shutdown
@@ -67,9 +68,9 @@ void ComponentThread::marionetteMain(ComponentThread& self)
throw JustPrintUsageNoError(options); throw JustPrintUsageNoError(options);
} }
initializeSalmanoff();
self.getIoService().post([]() self.getIoService().post([]()
{ {
initializeSalmanoff();
mind.initialize(); mind.initialize();
}); });
@@ -110,42 +111,46 @@ void ComponentThread::marionetteMain(ComponentThread& self)
} }
std::cout << __func__ << ": Exited event loop" << "\n"; std::cout << __func__ << ": Exited event loop" << "\n";
shutdownSalmanoff();
} }
catch (const OptionParser::Exception& e) catch (const OptionParser::Exception& e)
{ {
std::ostream &out = std::cout; std::ostream *out = &std::cout;
std::string outUsageMsg; std::string outUsageMsg;
if (typeid(e) == typeid(OptionsParserError)) if (typeid(e) == typeid(OptionsParserError))
{ {
mrntt::exitCode = EXIT_FAILURE; mrntt::exitCode = EXIT_FAILURE;
out = &std::cerr;
outUsageMsg = std::string(__func__) + ": "; outUsageMsg = std::string(__func__) + ": ";
} }
out << outUsageMsg << e.what() << std::endl; *out << outUsageMsg << e.what() << std::endl;
mind.finalizeReq([]{ callFinalizeReq = true;
mrntt::mrntt->getIoService().stop();
});
self.getIoService().reset();
self.getIoService().run();
return;
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
std::cerr << __func__ << ": Exception occurred: " << e.what() std::cerr << __func__ << ": Exception occurred: " << e.what()
<< std::endl; << std::endl;
mrntt::exitCode = EXIT_FAILURE; mrntt::exitCode = EXIT_FAILURE;
return; callFinalizeReq = true;
} }
catch (...) catch (...)
{ {
std::cerr << __func__ << ": Unknown exception occurred" << std::endl; std::cerr << __func__ << ": Unknown exception occurred" << std::endl;
mrntt::exitCode = EXIT_FAILURE; 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 } // namespace smo