From 3ca7c008dbb7825062f99f80de42e9f8b0cf996b Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 17 Oct 2015 12:51:56 +0100 Subject: [PATCH] rpc: misc tweaks - make the execute flag int and volatile (used as signal comms) - do not execute all the RPC shutdown in the signal context - do not busy wait while waiting for the signal --- src/rpc/json_rpc.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/rpc/json_rpc.cpp b/src/rpc/json_rpc.cpp index 816ec25f8..27fb2dafc 100644 --- a/src/rpc/json_rpc.cpp +++ b/src/rpc/json_rpc.cpp @@ -43,25 +43,30 @@ #include #include -static bool execute = true; +static volatile int execute = 1; void trap(int signal) { - RPC::DaemonDeprecated::stop(); - execute = false; + execute = 0; } int main() { + bool initialized = false; int res = RPC::DaemonDeprecated::start(); if (res == RPC::DaemonDeprecated::FAILURE_HTTP_SERVER) { std::cerr << "Couldn't start HTTP server\n"; - execute = false; + execute = 0; } else if (res == RPC::DaemonDeprecated::FAILURE_DAEMON_NOT_RUNNING) { std::cerr << "Couldn't connect to daemon\n"; - execute = false; + execute = 0; + } else { + initialized = true; } signal(SIGINT, &trap); while (execute) { - + epee::misc_utils::sleep_no_w(100); // 100 ms } + signal(SIGINT, SIG_DFL); + if (initialized) + RPC::DaemonDeprecated::stop(); std::cout << "out!\n"; return 0; }