[hipl-commit] [trunk] Rev 4620: hipd: overhaul of the exiting infrastructure.

  • From: Mircea Gherzan <mircea.gherzan@xxxxxxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Sun, 30 May 2010 18:55:27 +0300

Committer: Mircea Gherzan <mircea.gherzan@xxxxxxxxxxxxxx>
Date: 30/05/2010 at 18:55:27
Revision: 4620
Revision-id: mircea.gherzan@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: trunk

Log:
  hipd: overhaul of the exiting infrastructure.
  * the signal handler should be static
  * the signal handler must not be called directly
  * passing a signal value to exit(3) is simply wrong
  * hip_exit did not use the signal number

Modified:
  M  hipd/hipd.c
  M  hipd/init.c
  M  hipd/init.h
  M  hipd/maintenance.c
  M  hipd/user.c

=== modified file 'hipd/hipd.c'
--- hipd/hipd.c 2010-05-26 10:28:47 +0000
+++ hipd/hipd.c 2010-05-30 15:53:09 +0000
@@ -389,7 +389,7 @@
 
 out_err:
     /* free allocated resources */
-    hip_exit(err);
+    hip_exit();
 
     if (ctx.input_msg) {
         free(ctx.input_msg);

=== modified file 'hipd/init.c'
--- hipd/init.c 2010-05-30 15:31:26 +0000
+++ hipd/init.c 2010-05-30 15:53:09 +0000
@@ -818,6 +818,142 @@
 }
 
 /**
+ * Cleanup and signal handler to free userspace and kernel space
+ * resource allocations.
+ *
+ * @param signal the signal hipd received
+ */
+void hip_exit(void)
+{
+    hip_delete_default_prefix_sp_pair();
+    /* Close SAs with all peers */
+    // hip_send_close(NULL);
+
+    hip_delete_all_sp();
+
+    hip_delete_all_addresses();
+
+    set_up_device(HIP_HIT_DEV, 0);
+
+    /* Next line is needed only if RVS or hiprelay is in use. */
+    hip_uninit_services();
+
+    hip_uninit_handle_functions();
+
+    hip_user_uninit_handles();
+
+    hip_uninit_maint_functions();
+
+    lmod_uninit_packet_types();
+
+#ifdef CONFIG_HIP_OPPORTUNISTIC
+    hip_oppdb_uninit();
+#endif
+
+#ifdef CONFIG_HIP_RVS
+    HIP_INFO("Uninitializing RVS / HIP relay database and whitelist.\n");
+    hip_relay_uninit();
+#endif
+
+    if (hip_raw_sock_input_v6) {
+        HIP_INFO("hip_raw_sock_input_v6\n");
+        close(hip_raw_sock_input_v6);
+    }
+
+    if (hip_raw_sock_output_v6) {
+        HIP_INFO("hip_raw_sock_output_v6\n");
+        close(hip_raw_sock_output_v6);
+    }
+
+    if (hip_raw_sock_input_v4) {
+        HIP_INFO("hip_raw_sock_input_v4\n");
+        close(hip_raw_sock_input_v4);
+    }
+
+    if (hip_raw_sock_output_v4) {
+        HIP_INFO("hip_raw_sock_output_v4\n");
+        close(hip_raw_sock_output_v4);
+    }
+
+    if (hip_nat_sock_input_udp) {
+        HIP_INFO("hip_nat_sock_input_udp\n");
+        close(hip_nat_sock_input_udp);
+    }
+
+    if (hip_nat_sock_output_udp) {
+        HIP_INFO("hip_nat_sock_output_udp\n");
+        close(hip_nat_sock_output_udp);
+    }
+
+    if (hip_nat_sock_input_udp_v6) {
+        HIP_INFO("hip_nat_sock_input_udp_v6\n");
+        close(hip_nat_sock_input_udp_v6);
+    }
+
+    if (hip_nat_sock_output_udp_v6) {
+        HIP_INFO("hip_nat_sock_output_udp_v6\n");
+        close(hip_nat_sock_output_udp_v6);
+    }
+
+    hip_uninit_hadb();
+    hip_uninit_host_id_dbs();
+
+    if (hip_user_sock) {
+        HIP_INFO("hip_user_sock\n");
+        close(hip_user_sock);
+    }
+    if (hip_nl_ipsec.fd) {
+        HIP_INFO("hip_nl_ipsec.fd\n");
+        rtnl_close(&hip_nl_ipsec);
+    }
+    if (hip_nl_route.fd) {
+        HIP_INFO("hip_nl_route.fd\n");
+        rtnl_close(&hip_nl_route);
+    }
+
+    hip_remove_lock_file(HIP_DAEMON_LOCK_FILE);
+
+#ifdef CONFIG_HIP_PERFORMANCE
+    /* Deallocate memory of perf_set after finishing all of tests */
+    hip_perf_destroy(perf_set);
+#endif
+
+    hip_dh_uninit();
+
+    lmod_uninit_disabled_modules();
+
+    hip_remove_kernel_modules();
+
+    return;
+}
+
+/**
+ * Signal handler: exit gracefully by sending CLOSE to all peers
+ *
+ * @param signal the signal hipd received from OS
+ */
+static void hip_close(int signum)
+{
+    static int terminate = 0;
+
+    HIP_ERROR("Caught signal: %d\n", signum);
+    terminate++;
+
+    /* Close SAs with all peers */
+    if (terminate == 1) {
+        hip_send_close(NULL, FLUSH_HA_INFO_DB);
+        hipd_set_state(HIPD_STATE_CLOSING);
+        HIP_DEBUG("Starting to close HIP daemon...\n");
+    } else if (terminate == 2) {
+        HIP_DEBUG("Send still once this signal to force daemon exit...\n");
+    } else if (terminate > 2) {
+        HIP_DEBUG("Terminating daemon.\n");
+        hip_exit();
+        exit(EXIT_SUCCESS);
+    }
+}
+
+/**
  * Main initialization function for HIP daemon.
  * @param flags startup flags
  * @return      zero on success or negative on failure
@@ -1114,140 +1250,4 @@
     return err;
 }
 
-/**
- * exit gracefully by sending CLOSE to all peers
- *
- * @param signal the signal hipd received from OS
- */
-void hip_close(int signal)
-{
-    static int terminate = 0;
-
-    HIP_ERROR("Signal: %d\n", signal);
-    terminate++;
-
-    /* Close SAs with all peers */
-    if (terminate == 1) {
-        hip_send_close(NULL, FLUSH_HA_INFO_DB);
-        hipd_set_state(HIPD_STATE_CLOSING);
-        HIP_DEBUG("Starting to close HIP daemon...\n");
-    } else if (terminate == 2) {
-        HIP_DEBUG("Send still once this signal to force daemon exit...\n");
-    } else if (terminate > 2) {
-        HIP_DEBUG("Terminating daemon.\n");
-        hip_exit(signal);
-        exit(signal);
-    }
-}
-
-/**
- * Cleanup and signal handler to free userspace and kernel space
- * resource allocations.
- *
- * @param signal the signal hipd received
- */
-void hip_exit(int signal)
-{
-    HIP_ERROR("Signal: %d\n", signal);
-
-    hip_delete_default_prefix_sp_pair();
-    /* Close SAs with all peers */
-    // hip_send_close(NULL);
-
-    hip_delete_all_sp();
-
-    hip_delete_all_addresses();
-
-    set_up_device(HIP_HIT_DEV, 0);
-
-    /* Next line is needed only if RVS or hiprelay is in use. */
-    hip_uninit_services();
-
-    hip_uninit_handle_functions();
-
-    hip_user_uninit_handles();
-
-    hip_uninit_maint_functions();
-
-    lmod_uninit_packet_types();
-
-#ifdef CONFIG_HIP_OPPORTUNISTIC
-    hip_oppdb_uninit();
-#endif
-
-#ifdef CONFIG_HIP_RVS
-    HIP_INFO("Uninitializing RVS / HIP relay database and whitelist.\n");
-    hip_relay_uninit();
-#endif
-
-    if (hip_raw_sock_input_v6) {
-        HIP_INFO("hip_raw_sock_input_v6\n");
-        close(hip_raw_sock_input_v6);
-    }
-
-    if (hip_raw_sock_output_v6) {
-        HIP_INFO("hip_raw_sock_output_v6\n");
-        close(hip_raw_sock_output_v6);
-    }
-
-    if (hip_raw_sock_input_v4) {
-        HIP_INFO("hip_raw_sock_input_v4\n");
-        close(hip_raw_sock_input_v4);
-    }
-
-    if (hip_raw_sock_output_v4) {
-        HIP_INFO("hip_raw_sock_output_v4\n");
-        close(hip_raw_sock_output_v4);
-    }
-
-    if (hip_nat_sock_input_udp) {
-        HIP_INFO("hip_nat_sock_input_udp\n");
-        close(hip_nat_sock_input_udp);
-    }
-
-    if (hip_nat_sock_output_udp) {
-        HIP_INFO("hip_nat_sock_output_udp\n");
-        close(hip_nat_sock_output_udp);
-    }
-
-    if (hip_nat_sock_input_udp_v6) {
-        HIP_INFO("hip_nat_sock_input_udp_v6\n");
-        close(hip_nat_sock_input_udp_v6);
-    }
-
-    if (hip_nat_sock_output_udp_v6) {
-        HIP_INFO("hip_nat_sock_output_udp_v6\n");
-        close(hip_nat_sock_output_udp_v6);
-    }
-
-    hip_uninit_hadb();
-    hip_uninit_host_id_dbs();
-
-    if (hip_user_sock) {
-        HIP_INFO("hip_user_sock\n");
-        close(hip_user_sock);
-    }
-    if (hip_nl_ipsec.fd) {
-        HIP_INFO("hip_nl_ipsec.fd\n");
-        rtnl_close(&hip_nl_ipsec);
-    }
-    if (hip_nl_route.fd) {
-        HIP_INFO("hip_nl_route.fd\n");
-        rtnl_close(&hip_nl_route);
-    }
-
-    hip_remove_lock_file(HIP_DAEMON_LOCK_FILE);
-
-#ifdef CONFIG_HIP_PERFORMANCE
-    /* Deallocate memory of perf_set after finishing all of tests */
-    hip_perf_destroy(perf_set);
-#endif
-
-    hip_dh_uninit();
-
-    lmod_uninit_disabled_modules();
-
-    hip_remove_kernel_modules();
-
-    return;
-}
+

=== modified file 'hipd/init.h'
--- hipd/init.h 2010-05-20 16:14:34 +0000
+++ hipd/init.h 2010-05-30 15:53:09 +0000
@@ -52,7 +52,6 @@
 int hip_create_nat_sock_udp(int *hip_nat_sock_udp,
                             struct sockaddr_in *addr,
                             int is_output);
-void hip_close(int signal);
-void hip_exit(int signal);
+void hip_exit(void);
 
 #endif /* HIP_HIPD_INIT_H */

=== modified file 'hipd/maintenance.c'
--- hipd/maintenance.c  2010-05-26 10:28:47 +0000
+++ hipd/maintenance.c  2010-05-30 15:53:09 +0000
@@ -256,8 +256,8 @@
                 hipd_set_state(HIPD_STATE_CLOSED);
             }
         } else {
-            hip_exit(SIGINT);
-            exit(SIGINT);
+            hip_exit();
+            exit(EXIT_SUCCESS);
         }
         force_exit_counter--;
     }

=== modified file 'hipd/user.c'
--- hipd/user.c 2010-05-26 10:28:47 +0000
+++ hipd/user.c 2010-05-30 15:53:09 +0000
@@ -26,6 +26,10 @@
 
 #define _BSD_SOURCE
 
+#include <signal.h>
+#include <unistd.h>
+#include <sys/types.h>
+
 #include "config.h"
 #include "accessor.h"
 #include "user.h"
@@ -672,7 +676,8 @@
     case HIP_MSG_RESTART:
         HIP_DEBUG("Restart message received, restarting HIP daemon now!!!\n");
         hipd_set_flag(HIPD_FLAG_RESTART);
-        hip_close(SIGINT);
+        /* invoking the signal handler directly is not a sane thing to do */
+        kill(getpid(), SIGINT);
         break;
     case HIP_MSG_SET_DATAPACKET_MODE_ON:
     {

Other related posts:

  • » [hipl-commit] [trunk] Rev 4620: hipd: overhaul of the exiting infrastructure. - Mircea Gherzan