-fix channel data range to make -1 legal value
[oweals/gnunet.git] / src / testbed / gnunet_testbed_mpi_spawn.c
index 54b1fdf72d0335fd0a04c4626ad0d38ffd63d0c4..41d8054711d460b28f978d725264dcf68eb10277 100644 (file)
@@ -26,15 +26,10 @@ static int ret;
 static struct GNUNET_OS_Process *child;
 
 /**
- * The arguments including the binary to spawn 
+ * The arguments including the binary to spawn
  */
 static char **argv2;
 
-/**
- * All our IP addresses
- */
-static char **our_addrs;
-
 /**
  * Pipe used to communicate shutdown via signal.
  */
@@ -60,11 +55,6 @@ static unsigned long child_exit_code;
  */
 static enum GNUNET_OS_ProcessStatusType child_status;
 
-/**
- * how many IP addresses are currently assigned to us
- */
-static unsigned int num_addrs;
-
 /**
  * The shutdown task
  */
@@ -89,7 +79,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   shutdown_task_id = GNUNET_SCHEDULER_NO_TASK;
   if (0 != child_exit_code)
   {
-    LOG (GNUNET_ERROR_TYPE_WARNING, "Child exited with error code: %lu\n", 
+    LOG (GNUNET_ERROR_TYPE_WARNING, "Child exited with error code: %lu\n",
          child_exit_code);
     ret = 128 + (int) child_exit_code;
   }
@@ -111,7 +101,7 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   static int hard_kill;
 
   GNUNET_assert (NULL != child);
-  terminate_task_id = 
+  terminate_task_id =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                     &terminate_task, NULL);
   if (0 != hard_kill)
@@ -120,7 +110,7 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     {
     case 1:
     case 2:
-      LOG (GNUNET_ERROR_TYPE_WARNING, 
+      LOG (GNUNET_ERROR_TYPE_WARNING,
            "%d more interrupts needed to send SIGKILL to the child\n",
            3 - hard_kill);
       hard_kill++;
@@ -131,7 +121,7 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     }
   }
   hard_kill++;
-  GNUNET_break (0 == GNUNET_OS_process_kill (child, SIGTERM));
+  GNUNET_break (0 == GNUNET_OS_process_kill (child, GNUNET_TERM_SIG));
   LOG (GNUNET_ERROR_TYPE_INFO, _("Waiting for child to exit.\n"));
 }
 
@@ -171,37 +161,6 @@ child_death_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 
-/**
- * Callback function invoked for each interface found.
- *
- * @param cls NULL
- * @param name name of the interface (can be NULL for unknown)
- * @param isDefault is this presumably the default interface
- * @param addr address of this interface (can be NULL for unknown or unassigned)
- * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
- * @param netmask the network mask (can be NULL for unknown or unassigned))
- * @param addrlen length of the address
- * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
- */
-static int 
-addr_proc (void *cls, const char *name, int isDefault,
-           const struct sockaddr *addr,
-           const struct sockaddr *broadcast_addr,
-           const struct sockaddr *netmask, socklen_t addrlen)
-{
-  const struct sockaddr_in *in_addr;
-  char *ipaddr;
-
-  if (sizeof (struct sockaddr_in) != addrlen)
-    return GNUNET_OK;
-  in_addr = (const struct sockaddr_in *) addr;
-  if (NULL == (ipaddr = inet_ntoa (in_addr->sin_addr)))
-    return GNUNET_OK;
-  GNUNET_array_append (our_addrs, num_addrs, GNUNET_strdup (ipaddr));
-  return GNUNET_OK;
-}
-
-
 static void
 destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts)
 {
@@ -227,19 +186,11 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GNUNET_TESTBED_Host **hosts;
   const struct GNUNET_CONFIGURATION_Handle *null_cfg;
-  const char *host_ip;
   char *tmpdir;
+  char *hostname;
+  size_t hostname_len;
   unsigned int nhosts;
-  unsigned int host_cnt;
-  unsigned int addr_cnt;
 
-  GNUNET_OS_network_interfaces_list (&addr_proc, NULL);
-  if (0 == num_addrs)
-  {
-    GNUNET_break (0);
-    ret = GNUNET_SYSERR;
-    return;
-  }
   null_cfg = GNUNET_CONFIGURATION_create ();
   nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler (null_cfg, &hosts);
   if (0 == nhosts)
@@ -248,31 +199,31 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     ret = GNUNET_SYSERR;
     return;
   }
-  for (host_cnt = 0; host_cnt < nhosts; host_cnt++)
+  hostname_len = GNUNET_OS_get_hostname_max_length ();
+  hostname = GNUNET_malloc (hostname_len);
+  if (0 != gethostname (hostname, hostname_len))
   {
-    host_ip = GNUNET_TESTBED_host_get_hostname (hosts[host_cnt]);
-    for (addr_cnt = 0; addr_cnt < num_addrs; addr_cnt++)
-      if (0 == strcmp (host_ip, our_addrs[addr_cnt]))
-        goto proceed;
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname.  Exiting\n");
+    GNUNET_free (hostname);
+    destroy_hosts (hosts, nhosts);
+    ret = GNUNET_SYSERR;
+    return;
   }
-  GNUNET_break (0);
-  ret = GNUNET_SYSERR;
-  destroy_hosts (hosts, nhosts);
-  return;
-
- proceed:
-  destroy_hosts (hosts, nhosts);
-  if (0 != host_cnt)
+  if (NULL == strstr (GNUNET_TESTBED_host_get_hostname (hosts[0]), hostname))
   {
-    LOG_DEBUG ("Exiting as we are not the lowest host\n");
+    LOG_DEBUG ("Exiting as `%s' is not the lowest host\n", hostname);
+    GNUNET_free (hostname);
     ret = GNUNET_OK;
     return;
   }
+  LOG_DEBUG ("Will be executing `%s' on host `%s'\n", argv2[0], hostname);
+  GNUNET_free (hostname);
+  destroy_hosts (hosts, nhosts);
   tmpdir = getenv ("TMPDIR");
   if (NULL == tmpdir)
     tmpdir = getenv ("TMP");
   if (NULL == tmpdir)
-    tmpdir = getenv ("TEMP");  
+    tmpdir = getenv ("TEMP");
   if (NULL == tmpdir)
     tmpdir = "/tmp";
   (void) GNUNET_asprintf (&fn, "%s/gnunet-testbed-spawn.lock", tmpdir);
@@ -295,7 +246,7 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   /* Spawn the new process here */
   LOG (GNUNET_ERROR_TYPE_INFO, _("Spawning process `%s'\n"), argv2[0]);
   child = GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL,
-                                       NULL,
+                                       NULL, NULL,
                                        argv2[0], argv2);
   if (NULL == child)
   {
@@ -353,7 +304,7 @@ main (int argc, char *argv[])
     GNUNET_break (0);
     return 1;
   }
-  if (NULL == (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, 
+  if (NULL == (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO,
                                            GNUNET_NO, GNUNET_NO)))
   {
     GNUNET_break (0);
@@ -370,7 +321,7 @@ main (int argc, char *argv[])
   argv2 = GNUNET_malloc (sizeof (char *) * argc);
   for (cnt = 1; cnt < argc; cnt++)
     argv2[cnt - 1] = argv[cnt];
-  GNUNET_SCHEDULER_run (run, NULL);  
+  GNUNET_SCHEDULER_run (run, NULL);
   GNUNET_free (argv2);
   GNUNET_SIGNAL_handler_uninstall (shc_chld);
   shc_chld = NULL;