Index: /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/load_catalogs.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/load_catalogs.c	(revision 33299)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/relphot/src/load_catalogs.c	(revision 33300)
@@ -1,3 +1,5 @@
 # include "relphot.h"
+# include <sys/types.h>
+# include <sys/wait.h>
 
 // this function loops over the catalogs, loads the data, and extracts a bright subset
@@ -106,6 +108,24 @@
   }    
 
+  char *cwd;
+  if ((cwd = getcwd(NULL, 1024)) == NULL) {
+    fprintf (stderr, "error getting cwd (longer than 1024 chars?)\n");
+    exit (1);
+  }
+
   int i;
   for (i = 0; i < table->Nhosts; i++) {
+
+    // if table->hosts[i].pathname is a relative path (pathname[0] is not '/'), then 
+    // we need to prepend our current path
+
+    if (table->hosts[i].pathname[0] != '/') {
+      int Nbytes = strlen(cwd) + strlen(table->hosts[i].pathname) + 2;
+      char *newpath = NULL;
+      ALLOCATE (newpath, char, Nbytes);
+      snprintf (newpath, Nbytes, "%s/%s", cwd, table->hosts[i].pathname);
+      free (table->hosts[i].pathname);
+      table->hosts[i].pathname = newpath;
+    }
 
     char catalogFile[512];
@@ -162,5 +182,4 @@
       }
       table->hosts[i].pid = pid; // save for future reference
-      // check that all hosts started OK?
     }
   }
@@ -169,7 +188,39 @@
     fprintf (stderr, "run the relphot_client commands above.  when these are done, hit return\n");
     getchar();
-  } else {
-    // watch for stdout / stderr from those jobs...
-    // wait for all of them to complete...
+  }
+  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
+    // we have launched table->Nhosts jobs; wait for all of them to complete...
+    for (i = 0; i < table->Nhosts; i++) {
+      int status = 0;
+      int pid = waitpid (-1, &status, 0);
+
+      // XXX we'll need to pass in WNOHANG and keep retrying if we want to have a timeout...
+      // find the host which has finished
+      int j;
+      for (j = 0; j < table->Nhosts; j++) {
+	if (table->hosts[j].pid != pid) continue;
+	// check on the status of this and report any output?
+	fprintf (stderr, "job finished for %s (%d)\n", table->hosts[j].hostname, pid);
+	if (WIFEXITED(status)) {
+	  fprintf (stderr, "normal completion, exit status is %d\n", WEXITSTATUS(status));
+	  if (WEXITSTATUS(status)) {
+	    fprintf (stderr, "job failed on %s\n", table->hosts[j].hostname);
+	  }
+	}
+	// 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");
+      }
+    }
   }
 
