Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c	(revision 33368)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c	(revision 33369)
@@ -92,4 +92,5 @@
     valid:
       // read srcname, write to tgtname, get MD5 sum for srcname as we go:
+      // XXX files that fail here should be skipped (but don't give up)
       if (!get_md5_with_copy (srcname, tgtname, srcDigest)) {
 	fprintf (stderr, "error reading %s, getting md5, or writing %s\n", srcname, tgtname);
@@ -99,4 +100,5 @@
 	
       // need to re-open and re-read tgtname to check md5sum
+      // XXX files that fail here need to be checked
       char *absname = abspath (tgtname, 1024);
       if (!get_md5_from_pclient (host, absname, tgtDigest)) {
@@ -233,19 +235,27 @@
   // fprintf (stderr, "command: %s\n", line);
 
-  // start the md5sum command
   InitIOBuffer (&buffer, 100);
-  PclientCommand (host, line, &buffer);
-  PclientResponse (host, PCLIENT_PROMPT, &buffer);
-  // XXX for the moment, abort if anything goes wrong
-
-  // wait for result
   InitIOBuffer (&stdout_buf, 100);
   InitIOBuffer (&stderr_buf, 100);
+
+  // need to reset pclient for next command...
+  if (!PclientCommand (host, "reset", &buffer)) goto escape;
+  if (!PclientResponse (host, PCLIENT_PROMPT, &buffer)) goto escape;
+  FlushIOBuffer (&buffer);
+
+  // start the md5sum command
+  if (!PclientCommand (host, line, &buffer)) goto escape;
+  if (!PclientResponse (host, PCLIENT_PROMPT, &buffer)) goto escape;
+  // XXX for the moment, abort if anything goes wrong
+
+  // wait for result
   while (!CheckBusyJob (host, &stdout_buf, &stderr_buf)) {
+    FlushIOBuffer (&stdout_buf);
+    FlushIOBuffer (&stdout_buf);
     usleep (10000);
   }
   if (stderr_buf.Nbuffer) {
     fprintf (stderr, "error in md5sum: %s\n", stderr_buf.buffer);
-    exit (1);
+    goto escape;
   }
 
@@ -267,8 +277,14 @@
   
   // need to reset pclient for next command...
-  PclientCommand (host, "reset", &buffer);
-  PclientResponse (host, PCLIENT_PROMPT, &buffer);
+  if (!PclientCommand (host, "reset", &buffer)) goto escape;
+  if (!PclientResponse (host, PCLIENT_PROMPT, &buffer)) goto escape;
 
   return TRUE;
+
+escape:
+  FreeIOBuffer (&buffer);
+  FreeIOBuffer (&stdout_buf);
+  FreeIOBuffer (&stderr_buf);
+  return FALSE;
 }
 
Index: /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/PclientCommands.c
===================================================================
--- /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/PclientCommands.c	(revision 33368)
+++ /branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/PclientCommands.c	(revision 33369)
@@ -20,5 +20,5 @@
   if ((status == -1) && (errno == EPIPE)) {
     fprintf (stderr, "pclient read gives pipe error for %s\n", command);
-    abort();
+    return FALSE;
   }
 
@@ -53,5 +53,5 @@
   if (status ==  0) {
     fprintf (stderr, "pclient read returns 0 for %s\n", response);
-    abort();
+    return FALSE;
   }
   assert (line != NULL); // return (PCLIENT_HUNG);
@@ -65,42 +65,55 @@
 int GetJobOutput (char *command, HostInfo *host, IOBuffer *output, int size) {
   
-  char *line;
-  int i, status;
-  struct timespec request, remain;
+    char *line;
+    int i, status;
+    struct timespec request, remain;
 
-  InitIOBuffer (output, 100);
+    /* avoid blocking on waitpid, test every 100 usec, up to 10 msec */
+    request.tv_sec = 0;
+    request.tv_nsec = 100000;
 
-  /* avoid blocking on waitpid, test every 100 usec, up to 10 msec */
-  request.tv_sec = 0;
-  request.tv_nsec = 100000;
+    status = write_fmt (host->stdio[0], "%s\n", command);
 
-  status = write_fmt (host->stdio[0], "%s\n", command);
+    if ((status == -1) && (errno == EPIPE)) {
+	fprintf (stderr, "host crashed?\n");
+	goto escape;
+    }
 
-  if ((status == -1) && (errno == EPIPE)) {
-    fprintf (stderr, "host crashed\n");
-    exit (2);
-  }
+    // attempt to read the output->size bytes from the host 
+    for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (output->Nbuffer < size); i++) {
+	status = ReadtoIOBuffer (output, host->stdio[1]);
+	if (status == -1) nanosleep (&request, &remain);
+    }
+    if (DEBUG) fprintf (stderr, "Read %d of %d bytes so far\n", output->Nbuffer, size);
+    if (status == 0) {
+	fprintf (stderr, "client down\n");
+	goto escape;
+    }
+    if (output->Nbuffer < size) {
+	fprintf (stderr, "client hung\n");
+	goto escape;
+    }
 
-  // attempt to read the output->size bytes from the host 
-  for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (output->Nbuffer < size); i++) {
-    status = ReadtoIOBuffer (output, host->stdio[1]);
-    if (status == -1) nanosleep (&request, &remain);
-  }
-  if (DEBUG) fprintf (stderr, "Read %d of %d bytes so far\n", output->Nbuffer, size);
-  assert (status != 0);		   // return PCLIENT_DOWN;
-  assert (output->Nbuffer >= size); // return PCLIENT_HUNG;
+    // keep trying to read until we get the prompt
+    line = NULL;
+    status = -1;
+    for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) {
+	status = ReadtoIOBuffer (output, host->stdio[1]);
+	line = memstr (output->buffer, PCLIENT_PROMPT, output->Nbuffer);
+	if (status == -1) nanosleep (&request, &remain);
+    }
+    if (DEBUG) fprintf (stderr, "Read %d of %d bytes so far\n", output->Nbuffer, size);
+    if (!status) {
+	fprintf (stderr, "pclient down?\n");	      // return PCLIENT_DOWN;
+	goto escape;
+    }
+    if (!line) {
+	fprintf (stderr, "pclient hung?\n");		      // return PCLIENT_HUNG;
+	goto escape;
+    }
+    return TRUE;
 
-  // keep trying to read until we get the prompt
-  line = NULL;
-  status = -1;
-  for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) {
-    status = ReadtoIOBuffer (output, host->stdio[1]);
-    line = memstr (output->buffer, PCLIENT_PROMPT, output->Nbuffer);
-    if (status == -1) nanosleep (&request, &remain);
-  }
-  if (DEBUG) fprintf (stderr, "Read %d of %d bytes so far\n", output->Nbuffer, size);
-  assert (status != 0);	      // return PCLIENT_DOWN;
-  assert (line);		      // return PCLIENT_HUNG;
-  return TRUE;
+escape:
+    return FALSE;
 }
 
@@ -120,4 +133,5 @@
   if (p == NULL) {
     if (DEBUG) fprintf (stderr, "missing STATUS in response; try again?\n");
+    FreeIOBuffer (&buffer);
     return FALSE;
   }
@@ -129,4 +143,5 @@
   if (!strcmp(string, "BUSY")) {
     if (DEBUG) fprintf (stderr, "not yet done...\n");
+    FreeIOBuffer (&buffer);
     return FALSE;
   }
@@ -135,5 +150,6 @@
   if (!strcmp(string, "CRASH")) {
     fprintf (stderr, "crash on host...\n");
-    exit (1);
+    FreeIOBuffer (&buffer);
+    return FALSE;
   }
 
@@ -158,5 +174,4 @@
   } else {
     ReadtoIOBuffer (&buffer, host->stdio[1]);
-    FlushIOBuffer (&buffer);
   }
   if (stderr_buf_size) {
@@ -164,7 +179,7 @@
   } else {
     ReadtoIOBuffer (&buffer, host->stdio[2]);
-    FlushIOBuffer (&buffer);
   } 
 
+  FreeIOBuffer (&buffer);
   return TRUE;
 }
