Handle SIGINT (CTL+C) by gracefully shutting down

This commit is contained in:
2025-08-10 14:07:27 -04:00
parent 7579446388
commit d26b791dd2
4 changed files with 47 additions and 7 deletions
+23 -7
View File
@@ -5,6 +5,7 @@
#include <boost/asio.hpp>
#include <mind.h>
#include <componentThread.h>
#include <marionette/marionette.h>
namespace smo {
@@ -381,13 +382,28 @@ void ComponentThread::exceptionInd(ComponentThread& thread)
std::cerr << "Mrntt: Exception occurred: in thread "
<< thread.name << ". Killing Salmanoff." << "\n";
smo::mind.finalizeReq(
[]()
{
mrntt::mrntt->keepLooping = false;
mrntt::mrntt->getIoService().stop();
std::cout << "Mrntt: Signaled main loop to exit." << "\n";
});
// Delegate to common shutdown request
mind.finalizeReq(smo::mrntt::exitMarionetteLoop);
});
}
void ComponentThread::userShutdownInd()
{
if (this->id != ComponentThread::MRNTT)
{
throw std::runtime_error(std::string(__func__)
+ ": invoked on non-mrntt thread " + this->name);
}
// Post the user shutdown to the mrntt thread.
this->getIoService().post(
[]()
{
std::cerr << "Mrntt: User requested shutdown (SIGINT)."
<< " Killing Salmanoff." << "\n";
// Delegate to common shutdown request
mind.finalizeReq(smo::mrntt::exitMarionetteLoop);
});
}