Increase log level on SIGRTMAX. Reset it on SIGHUP
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 8 Oct 2010 14:44:58 +0000 (16:44 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 8 Oct 2010 14:44:58 +0000 (16:44 +0200)
src/logger.cpp
src/logger.hpp
src/main.cpp

index d0498cb..8f42a3e 100644 (file)
@@ -678,6 +678,21 @@ void Logger::print_caught_sigrtmin() const
 
 
 /**
+ * SIGRTMAX caught.
+ */
+void Logger::print_caught_sigrtmax(int new_loglevel) const
+{
+    int level = 0;
+    if ( level <= Loglevel )
+    {
+        ostringstream msg;
+        msg << "Caught SIGRTMAX. Increasing log level to " << new_loglevel << endl;
+        log_error(msg.str());
+    }
+}
+
+
+/**
  * Error while setting signal handler.
  */
 void Logger::print_error_setting_signal(const string& signal) const
index 6fd05cc..c2f6609 100644 (file)
@@ -128,6 +128,8 @@ public:
 
     void print_caught_sigrtmin() const;
 
+    void print_caught_sigrtmax(int new_loglevel) const;
+
     void print_error_setting_signal(const std::string& signal) const;
 
     void print_init_log_facility() const;
index 39f3549..e7f1666 100644 (file)
@@ -31,6 +31,7 @@ volatile bool caught_sig_hup = false;
 volatile bool caught_sig_usr1 = false;
 volatile bool caught_sig_usr2 = false;
 volatile bool caught_sig_rtmin = false;
+volatile bool caught_sig_rtmax = false;
 volatile bool caught_sig_term = false;
 
 /**
@@ -156,7 +157,7 @@ void sigusr1_func(int param)
 
 
 /**
- * Signal SIGHUP caught (reload config)
+ * Signal SIGHUP caught (reload config and reset log level)
  * @param param Parameter from the signal interface.
  */
 void sighup_func(int param)
@@ -186,6 +187,16 @@ void sigrtmin_func(int param)
 
 
 /**
+ * Signal SIGRTMAX caught (increase log level)
+ * @param param Parameter from the signal interface.
+ */
+void sigrtmax_func(int param)
+{
+    caught_sig_rtmax = true;
+} /*lint !e715 */
+
+
+/**
  * Initialize the signals we handle.
  * @return 0 if all is fine, -1 on error.
  */
@@ -222,6 +233,12 @@ int init_signals()
         updater->get_logger()->print_error_setting_signal("SIGRTMIN");
         return -1;
     }
+    ret_val = signal(SIGRTMAX, sigrtmax_func);
+    if ( ret_val == SIG_ERR )
+    {
+        updater->get_logger()->print_error_setting_signal("SIGRTMAX");
+        return -1;
+    }
 
     return 0;
 }
@@ -315,6 +332,8 @@ int main(int argc, char *argv[])
     // Tell the world we are running
     updater->get_logger()->print_started();
 
+    int original_log_level = updater->get_logger()->get_loglevel();
+
     // service processing starts here
     do
     {
@@ -342,6 +361,14 @@ int main(int argc, char *argv[])
             // Go online - with webcheck
             is_online = true;
             webcheck_enabled = true;
+        } else if (caught_sig_rtmax)
+        {
+            caught_sig_rtmax = false;
+
+            // Increase log level
+            int new_loglevel = updater->get_logger()->get_loglevel() + 1;
+            updater->get_logger()->print_caught_sigrtmax(new_loglevel);
+            updater->get_logger()->set_loglevel(new_loglevel);
         } else if (caught_sig_term)
         {
             caught_sig_term = false;
@@ -358,6 +385,9 @@ int main(int argc, char *argv[])
                 updater->get_logger()->print_conf_reload_failed_exit();
                 exit(-1);
             }
+
+            // Reset log level to startup log level in case it got elevated by SIGRTMAX
+            updater->get_logger()->set_loglevel(original_log_level);
         }
 
         // State handling