Index: trunk/Ohana/src/opihi/pantasks/JobOps.c
===================================================================
--- trunk/Ohana/src/opihi/pantasks/JobOps.c	(revision 3140)
+++ trunk/Ohana/src/opihi/pantasks/JobOps.c	(revision 4450)
@@ -1,3 +1,2 @@
-# include "opihi.h"
 # include "scheduler.h"
 
@@ -9,6 +8,6 @@
 
 static Job *jobs;
-static int   Njobs;
-static int   NJOBS;
+static int  Njobs;
+static int  NJOBS;
 
 static char *JobName = dot;
@@ -65,5 +64,5 @@
 
   for (i = 0; i < Njobs; i++) {
-    fprintf (stderr, "%d: %-15s %5d %20s (%x)\n", Njobs, jobs[i].task.name, jobs[i].JobID, jobs[i].task.argv[0], jobs[i].task.argv);
+    fprintf (stderr, "%d: %-15s %5d %20s (%x)\n", Njobs, jobs[i].task[0].name, jobs[i].JobID, jobs[i].argv[0], jobs[i].argv);
   }
   return;
@@ -75,5 +74,5 @@
   int i;
 
-  /* try for an exact match first */
+  /* return job with matching JobID */
   for (i = 0; i < Njobs; i++) {
     if (jobs[i].JobID == JobID) {
@@ -90,13 +89,31 @@
 
   jobs[Njobs].JobID = NextJobID ();
-  jobs[Njobs].PID = 0;
-  jobs[Njobs].task = task[0];
-
-  /* we need our own copy of task[0].argv */
-  ALLOCATE (jobs[Njobs].task.argv, char *, MAX (jobs[Njobs].task.argc, 1));
-  for (i = 0; i < jobs[Njobs].task.argc; i++) {
-    jobs[Njobs].task.argv[i] = strcreate (task[0].argv[i]);
-  }
-  jobs[Njobs].task.host = strcreate (task[0].host);
+  jobs[Njobs].pid = 0;
+  jobs[Njobs].mode = JOB_LOCAL;
+  if (task[0].host != NULL) {
+    jobs[Njobs].mode = JOB_CONTROLLER;
+  }
+
+  /* we need our own copy of task[0].argv 
+   *  argc is the number of valid args, like the usual command line.
+   *  we allocate one extra element, with value 0 to be passed to execvp
+   */
+  jobs[Njobs].argc = task[0].argc;
+  ALLOCATE (jobs[Njobs].argv, char *, MAX (task[0].argc + 1, 1));
+  for (i = 0; i < task[0].argc; i++) {
+    jobs[Njobs].argv[i] = strcreate (task[0].argv[i]);
+  }
+  jobs[Njobs].argv[i] = 0;
+
+  /* other data from the task is needed by the job 
+     we carry a pointer back to the task.  this means we 
+     cannot modify the task once a job is created, or the changes will 
+     be applied to the existing jobs */
+
+  jobs[Njobs].task = task;
+  
+  /* if we decide we need to be able to dynamically set task qualities
+     (like host, timeouts, etc), the we will need to have matched 
+     entries to these quantites in the job structure */
 
   Njobs ++;
@@ -108,4 +125,21 @@
 }
 
+void FreeJob (Job *job) {
+  
+  int i;
+
+  if (job == NULL) return;
+
+  if ((job[0].JobID >= 0) || (job[0].JobID < MAX_N_JOBS)) {
+    JobIDList[job[0].JobID] = FALSE;
+  }
+
+  for (i = 0; i < job[0].argc; i++) {
+    free (job[0].argv[i]);
+  }
+  free (job[0].argv);
+  return;
+}
+
 void SetCurrentJob (char *name) {
   JobName = name;
@@ -114,22 +148,4 @@
 char *GetCurrentJob () {
   return (JobName);
-}
-
-void FreeJob (Job *job) {
-  
-  int i;
-
-  if (job == NULL) return;
-
-  if ((job[0].JobID >= 0) || (job[0].JobID < MAX_N_JOBS)) {
-    JobIDList[job[0].JobID] = FALSE;
-  }
-
-  for (i = 0; i < job[0].task.argc; i++) {
-    free (job[0].task.argv[i]);
-  }
-  free (job[0].task.argv);
-  free (job[0].task.host);
-  return;
 }
 
@@ -161,29 +177,11 @@
 }
 
-/* this needs to: 
-   1) distinguish local from controller jobs
-   2) fork the local jobs in the background
-   3) send the controller jobs to the controller */
-
 int SubmitJob (Job *job) {
 
-  int i, Nchar;
-  char *string;
-
-  Nchar = 0;
-  for (i = 0; i < job[0].task.argc; i++) {
-    Nchar += strlen (job[0].task.argv[i]) + 1;
-  }
-  ALLOCATE (string, char, Nchar);
-  bzero (string, Nchar);
-
-  strcat (string, job[0].task.argv[0]);
-  for (i = 1; i < job[0].task.argc; i++) {
-    strcat (string, " ");
-    strcat (string, job[0].task.argv[i]);
-  }
-  
-  fprintf (stderr, "executing job %d ...%s...\n", job[0].JobID, string);
-  free (string);
+  if (job[0].mode == JOB_LOCAL) {
+    SubmitLocalJob (job);
+  } else {
+    SubmitControllerJob (job);
+  }
 
   /* reset clock for start and poll-test */
@@ -196,26 +194,11 @@
 int CheckJob (Job *job) {
 
-  float f;
-  f = drand48 ();
-
-  if ((0.00 < f) && (f < 0.25)) {
-    job[0].state = JOB_BUSY;
-    job[0].exit_status = -1;
-    return (JOB_BUSY);
-  }
-  if ((0.25 < f) && (f < 0.50)) {
-    job[0].state = JOB_BUSY;
-    job[0].exit_status = -1;
-    return (JOB_CRASH);
-  }
-  if ((0.50 < f) && (f < 0.75)) {
-    job[0].state = JOB_BUSY;
-    job[0].exit_status = 0;
-    return (JOB_EXIT);
-  }
-  if ((0.75 < f) && (f < 1.00)) {
-    job[0].state = JOB_BUSY;
-    job[0].exit_status = 1;
-    return (JOB_EXIT);
-  }
-}
+  /* add checks for timeouts */
+
+  if (job[0].mode == JOB_LOCAL) {
+    CheckLocalJob (job);
+  } else {
+    CheckControllerJob (job);
+  }
+  return (job[0].state);
+}
