Index: trunk/Ohana/src/opihi/pcontrol/CheckDoneJob.c
===================================================================
--- trunk/Ohana/src/opihi/pcontrol/CheckDoneJob.c	(revision 12840)
+++ trunk/Ohana/src/opihi/pcontrol/CheckDoneJob.c	(revision 20047)
@@ -1,7 +1,8 @@
 # include "pcontrol.h"
+# define DEBUG 0
 
 int CheckDoneJob (Job *job, Host *host) {
   
-  int success;
+  int status1, status2;
 
   ASSERT (job, "job not set");
@@ -11,11 +12,27 @@
   ASSERT (job == (Job *) host[0].job, "invalid job");
 
-  success = TRUE;
-  success &= GetJobOutput ("stdout", host, &job[0].stdout_buff, job[0].stdout_size);
-  success &= GetJobOutput ("stderr", host, &job[0].stderr_buff, job[0].stderr_size);
+  status1 = GetJobOutput ("stdout", host, &job[0].stdout);
+  status2 = GetJobOutput ("stderr", host, &job[0].stderr);
 
-  if (!success) {
-    // XXX some kind of error?
-    // XXX try again later?
+  if ((status1 == PCLIENT_DOWN) || (status2 == PCLIENT_DOWN)) {
+    // unlink host & job
+    if (DEBUG || VerboseMode()) gprint (GP_ERR, "host %s is down\n", host[0].hostname);
+    job[0].host = NULL;
+    host[0].job = NULL;
+	
+    PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM);
+
+    // clear the response data
+    host[0].response_state = PCONTROL_RESP_NONE;
+    host[0].response = NULL;
+
+    // host has shutdown; harvest the defunct process
+    HarvestHost (host[0].pid);
+    PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
+    return (FALSE);
+  }
+
+  // try again if we are still waiting
+  if ((status1 == PCLIENT_HUNG) || (status2 == PCLIENT_HUNG)) {
     PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM);
     PutJob (job, PCONTROL_JOB_DONE, STACK_BOTTOM);
@@ -32,4 +49,2 @@
   return (TRUE);
 }
-
-/** need to add timeout check here **/
