gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r30871 - msh/src


From: gnunet
Subject: [GNUnet-SVN] r30871 - msh/src
Date: Tue, 26 Nov 2013 14:11:13 +0100

Author: harsha
Date: 2013-11-26 14:11:13 +0100 (Tue, 26 Nov 2013)
New Revision: 30871

Modified:
   msh/src/mshd.c
Log:
- use pipe to send termination signal to the local address lookup server


Modified: msh/src/mshd.c
===================================================================
--- msh/src/mshd.c      2013-11-26 12:51:44 UTC (rev 30870)
+++ msh/src/mshd.c      2013-11-26 13:11:13 UTC (rev 30871)
@@ -162,6 +162,11 @@
   struct ChildProc *prev;
 
   /**
+   * Singalling pipe's write end
+   */
+  struct GNUNET_DISK_FileHandle *sig_write;
+
+  /**
    * The process id of the child process
    */
   pid_t pid;
@@ -315,8 +320,16 @@
  */
 uint16_t listen_port;
 
+/******************************************************************/
+/* Static variables to be used only in the local worker processes */
+/******************************************************************/
 
 /**
+ * The signalling pipe's read end
+ */
+struct GNUNET_DISK_FileHandle *worker_sigfd;
+
+/**
  * Function to copy NULL terminated list of arguments
  *
  * @param argv the NULL terminated list of arguments. Cannot be NULL.
@@ -363,6 +376,8 @@
 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct ChildProc *chld;
+  int sig;
+
   shutdown_task = GNUNET_SCHEDULER_NO_TASK;
   switch (mode)
   {
@@ -374,9 +389,12 @@
       LOG_DEBUG ("Delaying shutdown\n");
       shutdown_task = GNUNET_SCHEDULER_add_delayed
            (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown, NULL);
+      sig = GNUNET_TERM_SIG;
       while (NULL != chld)
       {
-        GNUNET_break (0 == kill (chld->pid, GNUNET_TERM_SIG));
+        GNUNET_break (0 == kill (chld->pid, sig));
+        if (NULL != chld->sig_write)
+          GNUNET_break (0 < GNUNET_DISK_file_write (chld->sig_write, &sig, 
sizeof (int)));
         chld = chld->next;
       }
       return;
@@ -536,6 +554,8 @@
   while (NULL != (chld = chld_head))
   {
     GNUNET_CONTAINER_DLL_remove (chld_head, chld_tail, chld);
+    if (NULL != chld->sig_write)
+      GNUNET_DISK_file_close (chld->sig_write);
     GNUNET_free (chld);
   }
   GNUNET_assert (MODE_SERV == mode);
@@ -723,6 +743,9 @@
   struct ChildProc *chld = cls;
 
   GNUNET_CONTAINER_DLL_remove (chld_head, chld_tail, chld);
+  if (NULL != chld->sig_write)
+    GNUNET_DISK_file_close (chld->sig_write);
+  GNUNET_free (chld);
   LOG (GNUNET_ERROR_TYPE_INFO, "Local server died.  Exiting. \n");
   GNUNET_SCHEDULER_shutdown ();
   if (0 == rank)
@@ -745,6 +768,23 @@
 
 
 /**
+ * Task which is run after receiving a signal thru the signal pipe.  This task
+ * terminates is run only in the local worker process and terminates it.
+ *
+ * @param cls NULL
+ * @param tc scheduler task context.
+ */
+static void
+terminate_worker (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
+    GNUNET_SCHEDULER_shutdown ();
+  GNUNET_DISK_file_close (worker_sigfd);
+  worker_sigfd = NULL;
+}
+
+
+/**
  * Task which will initiate the local address lookup server
  */
 static void
@@ -772,6 +812,9 @@
     MSH_monitor_process (proc, &proc_exit_cb, NULL);
   }
   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == shutdown_task);
+  (void) GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+                                         worker_sigfd,
+                                         &terminate_worker, NULL);
   shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                                 &do_shutdown, NULL);
 }
@@ -794,6 +837,9 @@
 schedule_next_round ()
 {
   struct ChildProc *chld;
+  struct GNUNET_DISK_PipeHandle *pipe;
+  struct GNUNET_DISK_FileHandle *read_end;
+  struct GNUNET_DISK_FileHandle *write_end;
   intmax_t pid;
   int total_rounds;
 
@@ -827,14 +873,26 @@
   bitmap = NULL;
   setenv (MSHD_HOSTSFILE, hostsfile, 1);
   setenv (MSHD_SOCK_NAME, unixpath, 1);
+  pipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, 0, 0);
+  GNUNET_assert (NULL != pipe);
+  read_end = GNUNET_DISK_pipe_detach_end (pipe, GNUNET_DISK_PIPE_END_READ);
+  write_end = GNUNET_DISK_pipe_detach_end (pipe, GNUNET_DISK_PIPE_END_WRITE);
+  GNUNET_DISK_pipe_close (pipe);
+  pipe = NULL;
   pid = fork ();
   if (-1 == pid)
   {
+    GNUNET_DISK_file_close (read_end);
+    GNUNET_DISK_file_close (write_end);
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
   if (0 == pid)
   {
+    GNUNET_DISK_file_close (write_end);
+    write_end = NULL;
+    worker_sigfd = read_end;
+    read_end = NULL;
     GNUNET_log_setup ("mshd-local-serv", NULL, NULL);
     mode = MODE_LOCAL_SERV;
     GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != shutdown_task);
@@ -863,6 +921,10 @@
   }
   chld = GNUNET_new (struct ChildProc);
   chld->pid = pid;
+  chld->sig_write = write_end;
+  write_end = NULL;
+  GNUNET_DISK_file_close (read_end);
+  read_end = NULL;
   GNUNET_CONTAINER_DLL_insert (chld_head, chld_tail, chld);
   MSH_pmonitor_init ();
   MSH_monitor_process_pid (pid, &local_serv_exit_cb, chld);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]