Catalli's threaded switch
[sliver-openvswitch.git] / lib / fatal-signal.c
index 80ecfc3..fbc4bbf 100644 (file)
@@ -17,7 +17,6 @@
 #include "fatal-signal.h"
 #include <assert.h>
 #include <errno.h>
-#include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdint.h>
 #include "shash.h"
 #include "socket-util.h"
 #include "util.h"
-
-#define THIS_MODULE VLM_fatal_signal
 #include "vlog.h"
 
+VLOG_DEFINE_THIS_MODULE(fatal_signal)
+
 /* Signals to catch. */
 static const int fatal_signals[] = { SIGTERM, SIGINT, SIGHUP, SIGALRM };
 
@@ -134,11 +133,25 @@ fatal_signal_handler(int sig_nr)
     stored_sig_nr = sig_nr;
 }
 
+/* Check whether a fatal signal has occurred and, if so, call the fatal signal
+ * hooks and exit.
+ *
+ * This function is called automatically by poll_block(), but specialized
+ * programs that may not always call poll_block() on a regular basis should
+ * also call it periodically.  (Therefore, any function with "block" in its
+ * name should call fatal_signal_run() each time it is called, either directly
+ * or through poll_block(), because such functions can only used by specialized
+ * programs that can afford to block outside their main loop around
+ * poll_block().)
+ */
 void
 fatal_signal_run(void)
 {
-    int sig_nr = stored_sig_nr;
+    int sig_nr;
 
+    fatal_signal_init();
+
+    sig_nr = stored_sig_nr;
     if (sig_nr != SIG_ATOMIC_MAX) {
         call_hooks(sig_nr);
 
@@ -152,6 +165,7 @@ fatal_signal_run(void)
 void
 fatal_signal_wait(void)
 {
+    fatal_signal_init();
     poll_fd_wait(signal_fds[0], POLLIN);
 }
 
@@ -200,9 +214,7 @@ fatal_signal_add_file_to_unlink(const char *file)
         fatal_signal_add_hook(unlink_files, cancel_files, NULL, true);
     }
 
-    if (!shash_find(&files, file)) {
-        shash_add(&files, file, NULL);
-    }
+    shash_add_once(&files, file, NULL);
 }
 
 /* Unregisters 'file' from being unlinked when the program terminates via
@@ -236,7 +248,7 @@ fatal_signal_unlink_file_now(const char *file)
 static void
 unlink_files(void *aux OVS_UNUSED)
 {
-    do_unlink_files(); 
+    do_unlink_files();
 }
 
 static void