Handle SIGINT (CTL+C) by gracefully shutting down
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user