console_handler: catch exception inside the input loop

This prevents an exception from existing the loop without
calling the exit handler, if one is defined.
The daemon defines one, which stops the p2p layer, and will
only exit once the p2p layer is shut down. This would cause
a hang upon an exception, as the input thread would have
exited and the daemon would wait forever with no console
user input.
This commit is contained in:
moneromooo-monero 2015-12-06 22:03:53 +00:00
parent 0252ffc37b
commit 4cede1830e
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3

View file

@ -268,10 +268,11 @@ namespace epee
template<typename t_cmd_handler> template<typename t_cmd_handler>
bool run(const std::string& prompt, const std::string& usage, const t_cmd_handler& cmd_handler, std::function<void(void)> exit_handler) bool run(const std::string& prompt, const std::string& usage, const t_cmd_handler& cmd_handler, std::function<void(void)> exit_handler)
{ {
TRY_ENTRY();
bool continue_handle = true; bool continue_handle = true;
m_prompt = prompt; m_prompt = prompt;
while(continue_handle) while(continue_handle)
{
try
{ {
if (!m_running) if (!m_running)
{ {
@ -310,10 +311,14 @@ namespace epee
std::cout << usage; std::cout << usage;
} }
} }
catch (const std::exception &ex)
{
LOG_ERROR("Exception at [console_handler], what=" << ex.what());
}
}
if (exit_handler) if (exit_handler)
exit_handler(); exit_handler();
return true; return true;
CATCH_ENTRY_L0("console_handler", false);
} }
private: private: