Signal handling changed to be able to go offline, online or online with webcheck ip.
authorBjoern Sikora <bjoern.sikora@intra2net.com>
Thu, 20 May 2010 16:34:09 +0000 (18:34 +0200)
committerBjoern Sikora <bjoern.sikora@intra2net.com>
Thu, 20 May 2010 16:34:09 +0000 (18:34 +0200)
scripts/bpdyndnsd
src/logger.cpp
src/logger.h
src/main.cpp

index c1d6712..203d719 100755 (executable)
@@ -79,6 +79,29 @@ restart() {
     start
 }
 
+online() {
+    echo -n "Switching $progname to online mode: "
+    killproc bpdyndnsd -USR2
+    RETVAL=$?
+    [ $RETVAL -eq 0 ] && success || failure
+    echo
+}
+
+online_webcheck() {
+    echo -n "Switching $progname to online mode with webcheck enabled: "
+    killproc bpdyndnsd -RTMIN
+    RETVAL=$?
+    [ $RETVAL -eq 0 ] && success || failure
+    echo
+}
+
+offline() {
+    echo -n "Switching $progname to offline mode: "
+    killproc bpdyndnsd -USR1
+    RETVAL=$?
+    [ $RETVAL -eq 0 ] && success || failure
+    echo
+}
 
 ##
 ## determine what we should do:
@@ -103,8 +126,17 @@ case "$1" in
     condrestart)
         [ -f /var/lock/subsys/bpdyndnsd ] && restart || : 
         ;;
+    online)
+        online
+        ;;
+    online_webcheck)
+        online_webcheck
+        ;;
+    offline)
+        offline
+        ;;
     *)
-        echo "Usage: bpdyndnsd {start|stop|status|restart|reload|condrestart}"
+        echo "Usage: bpdyndnsd {start|stop|status|restart|reload|condrestart|online|online_webcheck|offline}"
         RETVAL=1
 esac
 
index a42c7d7..cb0fb30 100644 (file)
@@ -575,7 +575,33 @@ void Logger::print_caught_sighup() const
     int level = 1;
     if ( level <= Loglevel )
     {
-        log_notice("Caught SIGHUP. Reloading config and switching to online mode...");
+        log_notice("Caught SIGHUP. Reloading config...");
+    }
+}
+
+
+/**
+ * SIGUSR2 caught.
+ */
+void Logger::print_caught_siguser2() const
+{
+    int level = 1;
+    if ( level <= Loglevel )
+    {
+        log_notice("Caught SIGUSR2. Switching to online mode...");
+    }
+}
+
+
+/**
+ * SIGRTMIN caught.
+ */
+void Logger::print_caught_sigrtmin() const
+{
+    int level = 1;
+    if ( level <= Loglevel )
+    {
+        log_notice("Caught SIGRTMIN. Switching to online mode with webcheck enabled...");
     }
 }
 
index b33d924..06f4534 100644 (file)
@@ -108,6 +108,10 @@ public:
 
     void print_caught_sighup() const;
 
+    void print_caught_siguser2() const;
+
+    void print_caught_sigrtmin() const;
+
     void print_error_setting_signal(const std::string& signal) const;
 
     void print_init_log_facility() const;
index eb0dac9..ae8135c 100644 (file)
@@ -27,6 +27,7 @@ using namespace std;
 
 Updater::Ptr updater;
 bool is_online = false;
+bool webcheck_enabled = false;
 
 /**
  * Checks if a bpdyndnsd process is already running.
@@ -154,7 +155,7 @@ void switch_to_offline(int param)
 
 
 /**
- * Signal SIGHUP caught, reloading config and switching to online mode.
+ * Signal SIGHUP caught, reloading config.
  * @param param Parameter from the signal interface.
  */
 void reload_config(int param)
@@ -162,7 +163,30 @@ void reload_config(int param)
     updater->get_logger()->print_caught_sighup();
     if ( updater->reload_config() != 0 )
         exit(-1);
+} /*lint !e715 */
+
+
+/**
+ * Signal SIGUSR2 caught, switching to online mode.
+ * @param param Parameter from the signal interface.
+ */
+void switch_to_online(int param)
+{
+    updater->get_logger()->print_caught_siguser2();
     is_online = true;
+    webcheck_enabled = false;
+} /*lint !e715 */
+
+
+/**
+ * Signal SIGRTMIN caught, switching to online mode with webcheck enabled.
+ * @param param Parameter from the signal interface.
+ */
+void switch_to_online_webcheck(int param)
+{
+    updater->get_logger()->print_caught_sigrtmin();
+    is_online = true;
+    webcheck_enabled = true;
 } /*lint !e715 */
 
 
@@ -191,6 +215,18 @@ int init_signals()
         updater->get_logger()->print_error_setting_signal("SIGHUP");
         return -1;
     }
+    ret_val = signal(SIGUSR2,switch_to_online);
+    if ( ret_val == SIG_ERR )
+    {
+        updater->get_logger()->print_error_setting_signal("SIGUSR2");
+        return -1;
+    }
+    ret_val = signal(SIGRTMIN,switch_to_online_webcheck);
+    if ( ret_val == SIG_ERR )
+    {
+        updater->get_logger()->print_error_setting_signal("SIGRTMIN");
+        return -1;
+    }
 
     return 0;
 }
@@ -272,12 +308,12 @@ int main(int argc, char *argv[])
     if ( init_daemon_mode(updater->get_config()->get_daemon_mode()) != 0 )
         return -1;
 
-    // Should we start in offline mode?
-    is_online = !updater->get_config()->get_start_offline();
-
     // service processing starts here
     do
     {
+        // Should we start in offline mode?
+        is_online = !updater->get_config()->get_start_offline();
+
         if ( is_online == true )
         {
             // update all configured services