From a6aac24601bafbb17918a0241f0fd53f6b49d004 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Wed, 6 Oct 2010 16:02:56 +0200 Subject: [PATCH] Move signal processing completly out of the signal handler (including logging) --- src/main.cpp | 48 ++++++++++++++++++++++++++++++++++++------------ 1 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4decd4a..5eb040d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,11 +26,13 @@ using namespace std; Updater::Ptr updater; -volatile bool is_online = false; -volatile bool webcheck_enabled = false; volatile bool need_config_reload = false; volatile bool exit_now = false; +volatile bool caught_sig_usr1 = false; +volatile bool caught_sig_usr2 = false; +volatile bool caught_sig_rtmin1 = false; + /** * Checks if a bpdyndnsd process is already running. * @param updater Shared Pointer to updater, needed for logging. @@ -150,8 +152,7 @@ void terminate(int param) */ void switch_to_offline(int param) { - updater->get_logger()->print_caught_siguser1(); - is_online = false; + caught_sig_usr1 = true; } /*lint !e715 */ @@ -171,9 +172,7 @@ void reload_config(int param) */ void switch_to_online(int param) { - updater->get_logger()->print_caught_siguser2(); - is_online = true; - webcheck_enabled = false; + caught_sig_usr2 = true; } /*lint !e715 */ @@ -183,9 +182,7 @@ void switch_to_online(int param) */ void switch_to_online_webcheck(int param) { - updater->get_logger()->print_caught_sigrtmin(); - is_online = true; - webcheck_enabled = true; + caught_sig_rtmin1 = true; } /*lint !e715 */ @@ -308,8 +305,8 @@ int main(int argc, char *argv[]) return -1; // Should we start in offline mode? - is_online = !updater->get_config()->get_start_offline(); - webcheck_enabled = updater->get_config()->get_webcheck_enabled(); + bool is_online = !updater->get_config()->get_start_offline(); + bool webcheck_enabled = updater->get_config()->get_webcheck_enabled(); // One shot run if daemon mode is disabled if (updater->get_config()->get_daemon_mode() != 1) @@ -318,6 +315,33 @@ int main(int argc, char *argv[]) // service processing starts here do { + // Signal processing + if (caught_sig_usr1) + { + caught_sig_usr1 = false; + updater->get_logger()->print_caught_siguser1(); + + // Go offline + is_online = false; + } else if (caught_sig_usr2) + { + caught_sig_usr2 = false; + updater->get_logger()->print_caught_siguser2(); + + // Go online + is_online = true; + webcheck_enabled = false; + } else if (caught_sig_rtmin1) + { + caught_sig_rtmin1 = false; + updater->get_logger()->print_caught_sigrtmin(); + + // Go online - with webcheck + is_online = true; + webcheck_enabled = true; + } + + // State handling if ( is_online == true ) { // Check if webcheck_enabled differs due to caught singnal then set it in config correspondingly -- 1.7.1