diff options
author | Riccardo Spagni <ric@spagni.net> | 2018-10-16 18:23:44 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2018-10-16 18:23:44 +0200 |
commit | d4e4fac2095b98d6888b9ba198c8628a7613f25b (patch) | |
tree | b23dc09bc194a25d45e5f7dbbe880a9ac15bd7c1 /src/daemon | |
parent | Merge pull request #4623 (diff) | |
parent | daemon: fix reading past stack on exit (diff) | |
download | monero-d4e4fac2095b98d6888b9ba198c8628a7613f25b.tar.xz |
Merge pull request #4602
6f28667a daemon: fix reading past stack on exit (moneromooo-monero)
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/daemon.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index f53649518..49d6d49cf 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -137,13 +137,18 @@ bool t_daemon::run(bool interactive) throw std::runtime_error{"Can't run stopped daemon"}; } - std::atomic<bool> stop(false); - boost::thread([&stop, this] { + std::atomic<bool> stop(false), shutdown(false); + boost::thread stop_thread = boost::thread([&stop, &shutdown, this] { while (!stop) epee::misc_utils::sleep_no_w(100); - this->stop_p2p(); - }).detach(); - tools::signal_handler::install([&stop](int){ stop = true; }); + if (shutdown) + this->stop_p2p(); + }); + epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ + stop = true; + stop_thread.join(); + }); + tools::signal_handler::install([&stop, &shutdown](int){ stop = shutdown = true; }); try { |