diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index 28feca4f53..77085d9b7a 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -415,9 +415,11 @@ void application::wait4interrupt_request() } } -void application::wait() +void application::wait( bool log ) { + if( log ) ilog("Wait for interrupt request"); wait4interrupt_request(); + if( log ) ilog("Interrupt request has been generated"); if( finish_request ) { @@ -426,9 +428,11 @@ void application::wait() ilog("Request for application shutdown processed."); } + if( log ) ilog("Wait for finishing plugins"); finish(); + if( log ) ilog("Plugins have been finished"); - handler_wrapper.wait4stop(); + handler_wrapper.wait4stop( log ); } bool application::is_thread_closed() @@ -646,13 +650,17 @@ void application::kill( bool direct_stop ) ::kill(getpid(), SIGINT); } -bool application::quit() +bool application::quit( bool log ) { auto _is_thread_closed = is_thread_closed(); if( !_is_thread_closed ) + { + if( log ) ilog("Kill application"); kill(); + if( log ) ilog("Application has been killed"); + } - wait(); + wait( log ); return is_thread_closed(); } diff --git a/libraries/appbase/include/appbase/application.hpp b/libraries/appbase/include/appbase/application.hpp index 1eca6d1c6d..190fb7173a 100644 --- a/libraries/appbase/include/appbase/application.hpp +++ b/libraries/appbase/include/appbase/application.hpp @@ -102,7 +102,7 @@ namespace appbase { * Wait until quit(), SIGINT or SIGTERM and then shutdown */ void wait4interrupt_request(); - void wait(); + void wait( bool log = false ); bool is_thread_closed(); template< typename Plugin > @@ -167,7 +167,7 @@ namespace appbase { std::set< std::string > get_plugins_names() const; void kill( bool direct_stop = false ); // direct_stop is only viable for unit tests where signals don't work - bool quit(); + bool quit( bool log = false ); using finish_request_type = std::function; diff --git a/libraries/appbase/include/appbase/signals_handler.hpp b/libraries/appbase/include/appbase/signals_handler.hpp index 5667df3392..efcadf532f 100644 --- a/libraries/appbase/include/appbase/signals_handler.hpp +++ b/libraries/appbase/include/appbase/signals_handler.hpp @@ -64,7 +64,7 @@ namespace appbase { signals_handler_wrapper( signals_handler::interrupt_request_generation_type&& _interrupt_request_generation ); void init(); - void wait4stop(); + void wait4stop( bool log = false ); void force_stop(); bool is_thread_closed(); diff --git a/libraries/appbase/signals_handler.cpp b/libraries/appbase/signals_handler.cpp index 38d30ba4a2..96eaf6ac0f 100644 --- a/libraries/appbase/signals_handler.cpp +++ b/libraries/appbase/signals_handler.cpp @@ -112,16 +112,23 @@ void signals_handler_wrapper::init() initialized = true; } -void signals_handler_wrapper::wait4stop() +void signals_handler_wrapper::wait4stop( bool log ) { if( initialized ) { if( handler_thread->joinable() ) { + if( log ) ilog("Clearing signals"); handler.clear_signals(); + if( log ) ilog("Signals have been cleared"); + + if( log ) ilog("Stopping IO service"); get_io_service().stop(); + if( log ) ilog("IO service has been stopped"); + if( log ) ilog("Joining handler's thread"); handler_thread->join(); + if( log ) ilog("Handler's thread has been joined"); } } thread_closed = true; diff --git a/programs/beekeeper/beekeeper/beekeeper_app.cpp b/programs/beekeeper/beekeeper/beekeeper_app.cpp index b90196b0a5..04c1ae0c3f 100644 --- a/programs/beekeeper/beekeeper/beekeeper_app.cpp +++ b/programs/beekeeper/beekeeper/beekeeper_app.cpp @@ -18,8 +18,14 @@ beekeeper_app::beekeeper_app() beekeeper_app::~beekeeper_app() { - if( app.quit() && start_loop ) + if( start_loop ) + { + ilog("beekeeper is exiting"); + app.quit( true/*log*/ ); ilog("exited cleanly"); + } + else + app.quit(); } void beekeeper_app::set_program_options() @@ -188,7 +194,9 @@ void beekeeper_app::start() app.notify_status( "beekeeper is ready" ); - app.wait(); + ilog("beekeeper is waiting"); + app.wait( true/*log*/ ); + ilog("waiting is finished"); } const boost::program_options::variables_map& beekeeper_app::get_args() const