Index: /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/HostTable.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/HostTable.c	(revision 33473)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/libdvo/src/HostTable.c	(revision 33474)
@@ -188,2 +188,79 @@
   return TRUE;
 }
+
+// wait for all children to complete, report output to stdout
+int HostTableWaitJobsGetIO (HostTable *table, char *file, int lineno) {
+
+  int i;
+
+  // we have launched table->Nhosts jobs; wait for all of them to complete...
+  // if one (N) failed to launch, we will get an ECHILD error from the last (N) calls
+
+  // we need to read any data waiting on stderr or stdout from these jobs, or the overfull
+  // buffers can cause a problem.  we alternate between 'select' and 'waitpid' calls with
+  // timeouts for both
+
+  while (1) {
+
+    // is anyone done?
+    int status = 0;
+
+    // XXX we'll need to pass in WNOHANG and keep retrying if we want to have a timeout...
+    int pid = waitpid (-1, &status, WNOHANG);
+    if (pid) {
+      if (pid == -1) {
+	switch (errno) {
+	  case ECHILD:
+	    done = TRUE;
+	    // no more children, need to exit ...
+	    break;
+	  default:
+	    fprintf (stderr, "programming error (2)? %s %d", file, lineno);
+	    exit (2);
+	}
+      } else {
+	// handle
+      
+
+
+    // find the host which has finished
+    int j;
+    int found = FALSE;
+    for (j = 0; j < table->Nhosts; j++) {
+      if (table->hosts[j].pid != pid) continue;
+      found = TRUE;
+      // check on the status of this and report any output?
+      fprintf (stderr, "job finished for %s (%d)\n", table->hosts[j].hostname, pid);
+      // read the stderr and stdout
+      IOBuffer buffer;
+      InitIOBuffer (&buffer, 100);
+      EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[1]);
+      fprintf (stderr, "--- stdout from %s ---\n", table->hosts[j].hostname);
+      write (STDOUT_FILENO, buffer.buffer, buffer.Nbuffer);
+      fprintf (stderr, "\n");
+	  
+      InitIOBuffer (&buffer, 100);
+      EmptyIOBuffer (&buffer, 100, table->hosts[j].stdio[2]);
+      fprintf (stderr, "--- stderr from %s ---\n", table->hosts[j].hostname);
+      write (STDOUT_FILENO, buffer.buffer, buffer.Nbuffer);
+      fprintf (stderr, "\n");
+      if (WIFEXITED(status)) {
+	fprintf (stderr, "normal completion, exit status is %d\n", WEXITSTATUS(status));
+	table->hosts[j].status = WEXITSTATUS(status);
+	if (table->hosts[j].status) {
+	  fprintf (stderr, "job failed on %s\n", table->hosts[j].hostname);
+	  continue;
+	}
+      } else {
+	table->hosts[j].status = -1;
+	fprintf (stderr, "job exited abnormally on %s\n", table->hosts[j].hostname);
+	continue;
+      }
+    }
+    if (!found) {
+      fprintf (stderr, "Programming error: failed to matched finished job to known host!\n");
+      exit (2);
+    }
+  }
+  return TRUE;
+}
