From 3b04e2e3d4d0b50e5e109b3e6019a725ff22b793 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 12 Oct 2018 14:09:30 +0000 Subject: [PATCH] daemon: do not run complex code in a signal handler instead, delegate the work to a one off thread and notify it from the signal handler --- src/daemon/daemon.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index ea24e32eb..f53649518 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -136,7 +136,14 @@ bool t_daemon::run(bool interactive) { throw std::runtime_error{"Can't run stopped daemon"}; } - tools::signal_handler::install(std::bind(&daemonize::t_daemon::stop_p2p, this)); + + std::atomic stop(false); + boost::thread([&stop, this] { + while (!stop) + epee::misc_utils::sleep_no_w(100); + this->stop_p2p(); + }).detach(); + tools::signal_handler::install([&stop](int){ stop = true; }); try {