- raise a signal after receiving it from the control pipe by calling the respective...
authorSree Harsha Totakura <totakura@in.tum.de>
Thu, 28 Nov 2013 13:00:55 +0000 (13:00 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Thu, 28 Nov 2013 13:00:55 +0000 (13:00 +0000)
src/include/gnunet_signal_lib.h
src/util/os_priority.c
src/util/signal.c

index 04037b4ca3a5a50a48acd6e7a785d0cb832dd18f..32f8963e062fe67b5bd3f398c610e4010e43c25a 100644 (file)
@@ -72,6 +72,17 @@ void
 GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx);
 
 
+/**
+ * Raise the given signal by calling the installed signal handlers.  This will
+ * not use the @em raise() system call but only calls the handlers registered
+ * through GNUNET_SIGNAL_handler_install().
+ *
+ * @param sig the signal to raise
+ */
+void
+GNUNET_SIGNAL_raise (const int sig);
+
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif
index 1466ce0599805728b6d1d9fcc288bcb89dfa07b7..d772e3c87d100120da9fc52c25f6977f377f1d3b 100644 (file)
@@ -107,7 +107,7 @@ parent_control_handler (void *cls,
   GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
                                  control_pipe, &parent_control_handler,
                                  control_pipe);
-  raise ((int) sig);
+  GNUNET_SIGNAL_raise ((int) sig);
 }
 
 
index edce5f653565547720153038131cf0d4e3c15a43..92042018f4abefae972715c603f27253ecadf7b0 100644 (file)
 
 struct GNUNET_SIGNAL_Context
 {
+
+  struct GNUNET_SIGNAL_Context *next;
+
+  struct GNUNET_SIGNAL_Context *prev;
+
   int sig;
 
   GNUNET_SIGNAL_Handler method;
@@ -41,6 +46,11 @@ struct GNUNET_SIGNAL_Context
 #endif
 };
 
+static struct GNUNET_SIGNAL_Context *sc_head;
+
+static struct GNUNET_SIGNAL_Context *sc_tail;
+
+
 #ifdef WINDOWS
 GNUNET_SIGNAL_Handler w32_sigchld_handler = NULL;
 #endif
@@ -81,6 +91,7 @@ GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler)
     }
   }
 #endif
+  GNUNET_CONTAINER_DLL_insert_tail (sc_head, sc_tail, ret);
   return ret;
 }
 
@@ -93,5 +104,29 @@ GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx)
   sigemptyset (&sig.sa_mask);
   sigaction (ctx->sig, &ctx->oldsig, &sig);
 #endif
+  GNUNET_CONTAINER_DLL_remove (sc_head, sc_tail, ctx);
   GNUNET_free (ctx);
 }
+
+
+/**
+ * Raise the given signal by calling the installed signal handlers.  This will
+ * not use the @em raise() system call but only calls the handlers registered
+ * through GNUNET_SIGNAL_handler_install().
+ *
+ * @param sig the signal to raise
+ */
+void
+GNUNET_SIGNAL_raise (const int sig)
+{
+  struct GNUNET_SIGNAL_Context *ctx;
+  
+  for (ctx = sc_head; NULL != sc_head; ctx = ctx->next)
+  {
+    if (sig != ctx->sig)
+      continue;
+    if (NULL == ctx->method)
+      continue;
+    ctx->method ();
+  }
+}