Move signal processing completly out of the signal handler (including logging)
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 6 Oct 2010 14:02:56 +0000 (16:02 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 6 Oct 2010 14:02:56 +0000 (16:02 +0200)
src/main.cpp

index 4decd4a..5eb040d 100644 (file)
 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