From bed035fe72cbf6d2d64bdb2bb77e789085b8c707 Mon Sep 17 00:00:00 2001 From: Valera Cogut Date: Fri, 28 Sep 2018 12:06:34 +0300 Subject: [PATCH] Capture Ctrl+C in cli_wallet when not in daemon mode #1193 --- libraries/fc | 2 +- programs/cli_wallet/main.cpp | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libraries/fc b/libraries/fc index 2405081a18..cfb86d9e8f 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 2405081a18a3fa23e06e1e751cd020de835b182e +Subproject commit cfb86d9e8fcd6540de1572b8930db67bdded9819 diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index bf07b29441..269ddfdf8f 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -61,12 +61,6 @@ # include #endif -#ifdef WIN32 - #define QUIT_CURR_THREAD TerminateThread(pthread_self(), 0) -#else - #define QUIT_CURR_THREAD pthread_cancel(pthread_self()) -#endif - using namespace graphene::app; using namespace graphene::chain; using namespace graphene::utilities; @@ -286,16 +280,16 @@ int main( int argc, char** argv ) wallet_cli->register_api( wapi ); wallet_cli->start(); - fc::set_signal_handler([&wapi, &wallet_file](int signal) { + fc::set_signal_handler([&wallet_cli, &wapi, &wallet_file](int signal) { ilog( "Captured SIGINT not in daemon mode" ); wapi->save_wallet_file(wallet_file.generic_string()); - QUIT_CURR_THREAD; + wallet_cli->quit_blocked_thread(); }, SIGINT); - fc::set_signal_handler([&wapi, &wallet_file](int signal) { + fc::set_signal_handler([&wallet_cli, &wapi, &wallet_file](int signal) { ilog( "Captured SIGTERM not in daemon mode" ); wapi->save_wallet_file(wallet_file.generic_string()); - QUIT_CURR_THREAD; + wallet_cli->quit_blocked_thread(); }, SIGTERM); wallet_cli->wait(); @@ -307,6 +301,10 @@ int main( int argc, char** argv ) exit_promise->set_value(signal); }, SIGINT); + fc::set_signal_handler([&exit_promise](int signal) { + exit_promise->set_value(signal); + }, SIGTERM); + ilog( "Entering Daemon Mode, ^C to exit" ); exit_promise->wait(); }