Index: trunk/Ohana/src/opihi/pcontrol/StartJob.c
===================================================================
--- trunk/Ohana/src/opihi/pcontrol/StartJob.c	(revision 3187)
+++ trunk/Ohana/src/opihi/pcontrol/StartJob.c	(revision 3203)
@@ -3,9 +3,10 @@
 int StartJob (Job *job) {
 
-  int  Nline;
-  char *line;
+  int  i, Nline, status;
+  char *line, *p;
+  Host *host;
   IOBuffer buffer;
 
-  InitIOBuffer (&buffer);
+  InitIOBuffer (&buffer, 0x100);
 
   /* job must have assigned host */
@@ -17,6 +18,6 @@
 
   /* construct command line : job arg0 arg1 ... argN\n */
-  Nline = 10 + argc;
-  for (i = 0; i < argc; i++) {
+  Nline = 10 + job[0].argc;
+  for (i = 0; i < job[0].argc; i++) {
     Nline += strlen (job[0].argv[i]);
   }
@@ -24,9 +25,8 @@
   bzero (line, Nline);
   strcpy (line, "job");
-  for (i = 0; i < argc; i++) {
+  for (i = 0; i < job[0].argc; i++) {
     strcat (line, " ");
     strcat (line, job[0].argv[i]);
   }
-  strcat (line, "\n");
 
   status = PclientCommand (host, line, &buffer);
@@ -35,15 +35,13 @@
   /* check on success of pclient command */
   switch (status) {
-    case DOWN:
+    case PCLIENT_DOWN:
       fprintf (stderr, "host %s is down\n", host[0].hostname);
-      goto escape;
-      /*** different behavior for ANYHOST, WANTHOST, NEEDHOST ***/
+      goto failure;
 
-    case HUNG:
+    case PCLIENT_HUNG:
       fprintf (stderr, "host %s is not responding\n", host[0].hostname);
-      goto escape;
-      /*** should we consider a HUNG host DOWN? ***/
+      goto failure;
 
-    case TRUE:
+    case PCLIENT_GOOD:
       fprintf (stderr, "message received\n");  
       break;
@@ -60,10 +58,9 @@
     exit (1);
   }
-  fscan (p, "%*s %d", &status);
+  sscanf (p, "%*s %d", &status);
   switch (status) {
     case -1:
       fprintf (stderr, "error in pclient child\n");
-      goto escape;
-      /*** should we consider this host DOWN? ***/
+      goto failure;
 
     case -2:
@@ -77,6 +74,8 @@
     default:
       job[0].pid = status;
-      PutHost (host, PCONTROL_HOST_BUSY, QUEUE_BOTTOM);
-      PutJob (job, PCONTROL_JOB_BUSY, QUEUE_BOTTOM);
+      PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM);
+      PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM);
+      FreeIOBuffer (&buffer);
+      /** need to start timers here **/
       return (TRUE);
   }
@@ -85,21 +84,13 @@
   exit (1);
 
-escape:
-  job[0].host = NULL; /* unlink host & job */
+failure:
+  /* unlink host & job */
+  job[0].host = NULL;
   host[0].job = NULL;
-  /*** need to pop host from corresponding queue (BUSY) ***/
-  PutHost (host, PCONTROL_HOST_DOWN, QUEUE_BOTTOM);
-  PutJob (job, PCONTROL_JOB_PENDING, QUEUE_BOTTOM);
-  FreeBuffer (&buffer);
+  PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
+  PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM);
+  FreeIOBuffer (&buffer);
   return (FALSE);
 }
 
-/* 
-   this function sends a new command to the pclient.
-   before calling this function:
-     - grab the job from its queue (remove it from that queue with GetQueue)
-     - identify the target host (MUST already be IDLE)
-     - grab the host from its queue (remove it from that queue with GetQueue)
-     - link job and host (job[0].host = host, host[0].job = job)
-     - job must also have a valid command (argc, argv)
-*/
+/** note : host and job popped off stacks : can't use UnlinkJobAndHost **/
