| 122 | } |
| 123 | |
| 124 | void application::startup() { |
| 125 | //during startup, run a second thread to catch SIGINT/SIGTERM/SIGPIPE/SIGHUP |
| 126 | boost::asio::io_service startup_thread_ios; |
| 127 | setup_signal_handling_on_ios(startup_thread_ios, true); |
| 128 | std::thread startup_thread([&startup_thread_ios]() { |
| 129 | startup_thread_ios.run(); |
| 130 | }); |
| 131 | auto clean_up_signal_thread = [&startup_thread_ios, &startup_thread]() { |
| 132 | startup_thread_ios.stop(); |
| 133 | startup_thread.join(); |
| 134 | }; |
| 135 | |
| 136 | try { |
| 137 | for( auto plugin : initialized_plugins ) { |
| 138 | if( is_quiting() ) break; |
| 139 | plugin->startup(); |
| 140 | } |
| 141 | |
| 142 | } catch( ... ) { |
| 143 | clean_up_signal_thread(); |
| 144 | shutdown(); |
| 145 | throw; |
| 146 | } |
| 147 | |
| 148 | //after startup, shut down the signal handling thread and catch the signals back on main io_service |
| 149 | clean_up_signal_thread(); |
| 150 | setup_signal_handling_on_ios(get_io_service(), false); |
| 151 | |
| 152 | #ifdef SIGHUP |
| 153 | std::shared_ptr<boost::asio::signal_set> sighup_set(new boost::asio::signal_set(get_io_service(), SIGHUP)); |
| 154 | start_sighup_handler( sighup_set ); |
| 155 | #endif |
| 156 | } |
| 157 | |
| 158 | void application::start_sighup_handler( std::shared_ptr<boost::asio::signal_set> sighup_set ) { |
| 159 | #ifdef SIGHUP |