diff --git a/nano/load_test/entry.cpp b/nano/load_test/entry.cpp index c47989fd63..a70ccab4d1 100644 --- a/nano/load_test/entry.cpp +++ b/nano/load_test/entry.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -595,13 +596,14 @@ int main (int argc, char * const * argv) std::shared_ptr ioc_shared = std::make_shared (); boost::asio::io_context & ioc{ *ioc_shared }; - debug_assert (!nano::signal_handler_impl); - nano::signal_handler_impl = [&ioc] () { + nano::signal_manager sigman; + + auto signal_handler = [&ioc] (int signum) { ioc.stop (); }; - std::signal (SIGINT, &nano::signal_handler); - std::signal (SIGTERM, &nano::signal_handler); + sigman.register_signal_handler (SIGINT, signal_handler, true); + sigman.register_signal_handler (SIGTERM, signal_handler, false); tcp::resolver resolver{ ioc }; auto const primary_node_results = resolver.resolve ("::1", std::to_string (rpc_port_start)); diff --git a/nano/nano_node/daemon.cpp b/nano/nano_node/daemon.cpp index 0ed9ee7053..9d260e4369 100644 --- a/nano/nano_node/daemon.cpp +++ b/nano/nano_node/daemon.cpp @@ -193,8 +193,7 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag } } - debug_assert (!nano::signal_handler_impl); - nano::signal_handler_impl = [this, io_ctx_w = std::weak_ptr{ io_ctx }] () { + auto signal_handler = [this, io_ctx_w = std::weak_ptr{ io_ctx }] (int signum) { logger.warn (nano::log::type::daemon, "Interrupt signal received, stopping..."); if (auto io_ctx_l = io_ctx_w.lock ()) @@ -207,10 +206,10 @@ void nano::daemon::run (std::filesystem::path const & data_path, nano::node_flag nano::signal_manager sigman; // keep trapping Ctrl-C to avoid a second Ctrl-C interrupting tasks started by the first - sigman.register_signal_handler (SIGINT, &nano::signal_handler, true); + sigman.register_signal_handler (SIGINT, signal_handler, true); // sigterm is less likely to come in bunches so only trap it once - sigman.register_signal_handler (SIGTERM, &nano::signal_handler, false); + sigman.register_signal_handler (SIGTERM, signal_handler, false); runner = std::make_unique (io_ctx, node->config.io_threads); runner->join (); diff --git a/nano/nano_rpc/entry.cpp b/nano/nano_rpc/entry.cpp index b198d20820..30dedb3492 100644 --- a/nano/nano_rpc/entry.cpp +++ b/nano/nano_rpc/entry.cpp @@ -58,8 +58,7 @@ void run (std::filesystem::path const & data_path, std::vector cons auto rpc = nano::get_rpc (io_ctx, rpc_config, ipc_rpc_processor); rpc->start (); - debug_assert (!nano::signal_handler_impl); - nano::signal_handler_impl = [io_ctx_w = std::weak_ptr{ io_ctx }] () { + auto signal_handler = [io_ctx_w = std::weak_ptr{ io_ctx }] (int signum) { logger.warn (nano::log::type::daemon, "Interrupt signal received, stopping..."); if (auto io_ctx_l = io_ctx_w.lock ()) @@ -69,8 +68,8 @@ void run (std::filesystem::path const & data_path, std::vector cons sig_int_or_term = 1; }; - sigman.register_signal_handler (SIGINT, &nano::signal_handler, true); - sigman.register_signal_handler (SIGTERM, &nano::signal_handler, false); + sigman.register_signal_handler (SIGINT, signal_handler, true); + sigman.register_signal_handler (SIGTERM, signal_handler, false); runner = std::make_unique (io_ctx, rpc_config.rpc_process.io_threads); runner->join (); diff --git a/nano/secure/utility.cpp b/nano/secure/utility.cpp index 07d6472462..bec147eae1 100644 --- a/nano/secure/utility.cpp +++ b/nano/secure/utility.cpp @@ -74,16 +74,3 @@ void nano::remove_temporary_directories () } } } - -namespace nano -{ -/** A wrapper for handling signals */ -std::function signal_handler_impl; -void signal_handler (int sig) -{ - if (signal_handler_impl != nullptr) - { - signal_handler_impl (); - } -} -} diff --git a/nano/secure/utility.hpp b/nano/secure/utility.hpp index 96f93d6edd..8cd446c90a 100644 --- a/nano/secure/utility.hpp +++ b/nano/secure/utility.hpp @@ -13,7 +13,4 @@ std::filesystem::path working_path (nano::networks network = nano::network_const std::filesystem::path unique_path (nano::networks network = nano::network_constants::active_network); // Remove all unique tmp directories created by the process void remove_temporary_directories (); -// Generic signal handler declarations -extern std::function signal_handler_impl; -void signal_handler (int sig); }