Index: trunk/Ohana/src/opihi/pantasks/ControllerOps.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/ControllerOps.c	(revision 4762)
+++ trunk/Ohana/src/opihi/pantasks/ControllerOps.c	(revision 4763)
@@ -25,5 +25,5 @@
   gettimeofday (&stop, (void *) NULL);
   dtime = DTIME (stop, start);
-  if (VerboseMode()) fprintf (stderr, "check job status %f\n", dtime);
+  /* if (VerboseMode()) fprintf (stderr, "check job status %f\n", dtime); */
 
   if ((job[0].state == JOB_EXIT) || (job[0].state == JOB_CRASH)) {
@@ -32,8 +32,17 @@
     gettimeofday (&stop, (void *) NULL);
     dtime = DTIME (stop, start);
-    if (VerboseMode()) fprintf (stderr, "get stdout %f\n", dtime);
-
+    /* if (VerboseMode()) fprintf (stderr, "get stdout %f\n", dtime); */
+
+    gettimeofday (&start, (void *) NULL);
     GetJobOutput ("stderr", job[0].pid, &job[0].stderr, job[0].stderr_size);
+    gettimeofday (&stop, (void *) NULL);
+    dtime = DTIME (stop, start);
+    /* if (VerboseMode()) fprintf (stderr, "get stderr %f\n", dtime); */
+
+    gettimeofday (&start, (void *) NULL);
     DeleteControllerJob (job);
+    gettimeofday (&stop, (void *) NULL);
+    dtime = DTIME (stop, start);
+    /* if (VerboseMode()) fprintf (stderr, "delete job %f\n", dtime); */
   }  
   return (TRUE);
@@ -138,5 +147,5 @@
   if (status == -1) return (CONTROLLER_HUNG);
 
-  if (VerboseMode()) fprintf (stderr, "message received (GetJobOutput : %s)\n", cmd);  
+  /* if (VerboseMode()) fprintf (stderr, "message received (GetJobOutput : %s)\n", cmd);   */
   /* drop extra bytes from pcontrol (not pclient:job) */
   buffer[0].Nbuffer = Nstart + Nbytes;
@@ -328,10 +337,8 @@
   FlushIOBuffer (buffer);
 
-  if (VerboseMode()) fprintf (stderr, "send: %s\n", cmd);
-
   /* send command, is pipe still open? */
   status = write_fmt (stdin_cntl, "%s\n", cmd);
   if ((status == -1) && (errno == EPIPE)) {
-    ControllerStatus = FALSE;
+    StopController ();
     if (VerboseMode()) fprintf (stderr, "controller is down\n");
     return (FALSE);
@@ -347,9 +354,10 @@
   }
   if (status ==  0) {
-    ControllerStatus = FALSE;
+    StopController ();
     if (VerboseMode()) fprintf (stderr, "controller is down\n");
     return (FALSE);
   }
   if (status == -1) {
+    StopController ();
     if (VerboseMode()) fprintf (stderr, "controller is not responding\n");
     return (FALSE);
@@ -362,5 +370,5 @@
     bzero (buffer[0].buffer + buffer[0].Nbuffer, buffer[0].Nalloc - buffer[0].Nbuffer);
   }
-  if (VerboseMode()) fprintf (stderr, "message received, %d cycles\n", i);
+  /* if (VerboseMode()) fprintf (stderr, "message received, %d cycles\n", i); */
   return (TRUE);
 }
@@ -428,5 +436,5 @@
 int QuitController () {
 
-  int i, status, waitstatus, result;
+  int status;
   char cmd[128];
   IOBuffer buffer;
@@ -436,6 +444,18 @@
   sprintf (cmd, "quit");
   InitIOBuffer (&buffer, 0x100);
-  status = ControllerCommand (cmd, CONTROLLER_PROMPT, &buffer);
-  FreeIOBuffer (&buffer);
+  status = ControllerCommand (cmd, "", &buffer);
+  FreeIOBuffer (&buffer);
+
+  /* the quit command does not return a prompt, so we always 
+     get an error on the controller here */
+  StopController ();
+  return (TRUE);
+}
+
+int StopController () {
+
+  int i, waitstatus, result;
+
+  if (!ControllerStatus) return (TRUE);
 
   ControllerStatus = FALSE;
@@ -451,5 +471,4 @@
   FreeIOBuffer (&stdout_buffer);
   FreeIOBuffer (&stderr_buffer);
-
-  return (TRUE);
-}
+  return (TRUE);
+}
