IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4684


Ignore:
Timestamp:
Jul 31, 2005, 8:04:11 AM (21 years ago)
Author:
eugene
Message:

task/job list cleanup, fixing kill/delete

Location:
trunk/Ohana/src/opihi
Files:
1 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/include/dvo1.h

    r4606 r4684  
    1 # include "external.h"
    2 # include "shell.h"
    3 # include "dvomath.h"
    4 # include "convert.h"
    5 # include "display.h"
     1# include "opihi.h"
    62# include "data.h"
    73
  • trunk/Ohana/src/opihi/include/pclient.h

    r3211 r4684  
    1 # include "external.h"
    2 # include "shell.h"
    3 # include "dvomath.h"
    4 # include "convert.h"
    5 # include "display.h"
     1# include "opihi.h"
    62# include <sys/types.h>
    73# include <sys/wait.h>
  • trunk/Ohana/src/opihi/include/pcontrol.h

    r4573 r4684  
    1 # include "external.h"
    2 # include "shell.h"
    3 # include "dvomath.h"
    4 # include "convert.h"
    5 # include "display.h"
     1# include "opihi.h"
    62# include <sys/types.h>
    73# include <sys/wait.h>
  • trunk/Ohana/src/opihi/include/scheduler.h

    r4603 r4684  
    1 # include "external.h"
    2 # include "shell.h"
    3 # include "dvomath.h"
    4 # include "convert.h"
    5 # include "display.h"
     1# include "opihi.h"
    62# include <sys/types.h>
    73# include <sys/wait.h>
     
    117  JOB_BUSY,
    128  JOB_EXIT,
     9  JOB_HUNG,
    1310  JOB_CRASH,
    1411  JOB_PENDING,
     
    113110
    114111/* scheduler prototypes */
    115 void InitTasks ();
    116 void ListTasks ();
    117 Task *FindTask (char *name);
    118 Task *CreateTask (char *name);
    119 void SetCurrentTask (char *name);
    120 char *GetCurrentTask ();
    121 int DeleteTask (Task *task);
    122 Task *NextTask ();
    123 int TaskHash (char *input);
    124 int ShowTask (char *name);
     112
    125113char *memstr (char *m1, char *m2, int n);
    126114
     115void InitTasks ();
     116Task *NextTask ();
     117Task *FindTask (char *name);
     118void ListTasks (int verbose);
     119int ShowTask (char *name);
     120int FreeTask (Task *task);
     121Task *CreateTask (char *name);
     122int ValidateTask (Task *task);
     123int RegisterNewTask ();
     124int DeleteNewTask ();
     125Task *GetNewTask ();
     126void SetTaskTimer (struct timeval *timer);
     127double GetTaskTimer (struct timeval start);
     128void InitTaskTimers ();
     129int TaskHash (char *input);
     130
     131int NextJobID ();
     132int InitJobIDs ();
     133int FreeJobID (int ID);
     134
     135void InitJobs ();
    127136Job *NextJob ();
    128 void InitJobs ();
    129 int NextJobID ();
     137Job *FindJob (int JobID);
    130138void ListJobs ();
    131 Job *FindJob (int JobID);
    132139Job *CreateJob (Task *task);
    133 void SetCurrentJob (char *name);
    134 char *GetCurrentJob ();
    135140int SubmitJob (Job *job);
    136141int CheckJob (Job *job);
    137142int DeleteJob (Job *job);
    138143void FreeJob (Job *job);
    139 void SetTaskTimer (struct timeval *timer);
    140 double GetTaskTimer (struct timeval start);
    141144
    142145int CheckJobs ();
  • trunk/Ohana/src/opihi/pantasks/CheckJobs.c

    r4602 r4684  
    1212  while ((job = NextJob ()) != NULL) {
    1313
    14     /* check for timeout - only local jobs timeout here */
    15     if ((job[0].mode == JOB_LOCAL) && (GetTaskTimer(job[0].start) >= job[0].task[0].timeout_period)) {
    16       if (VerboseMode()) fprintf (stderr, "timeout on %s\n", job[0].task[0].name);
    17       /* run task[0].timeout macro, if it exists */
    18       if (job[0].task[0].timeout != NULL) {
    19         exec_loop (job[0].task[0].timeout);
    20       }
    21       DeleteJob (job);
    22       continue;
    23     }
    24 
    25     /* check poll period (ready to run again?) */
     14    /* check poll period (ready to ask for status?) */
    2615    if (GetTaskTimer(job[0].last) < job[0].task[0].poll_period) continue;
    2716
     
    7463    }
    7564
     65    /* check for timeout - (local jobs only)
     66       we only check timeout after a poll (forces at least one poll)
     67     */
     68    if (job[0].mode == JOB_LOCAL) {
     69      if (GetTaskTimer(job[0].start) < job[0].task[0].timeout_period) continue;
     70      if (VerboseMode()) fprintf (stderr, "timeout on %s\n", job[0].task[0].name);
     71      if (!KillLocalJob (job)) {
     72        job[0].state = JOB_HUNG;
     73        if (VerboseMode()) fprintf (stderr, "child process %d is hung, cannot kill\n", job[0].pid);
     74        continue;
     75      }
     76      /* run task[0].timeout macro, if it exists */
     77      if (job[0].task[0].timeout != NULL) {
     78        exec_loop (job[0].task[0].timeout);
     79      }
     80      DeleteJob (job);
     81      continue;
     82    }
     83
    7684    /* reset polling clock */
    7785    SetTaskTimer (&job[0].last);
     
    7987  return (TRUE);
    8088}
     89
     90/*
     91
     92  job / task timeline:
     93
     94  task:
     95  0           exec     
     96  start       create
     97  task clock  new job
     98
     99  job:
     100  0           1xpoll     2xpoll     3xpoll
     101  start       check      check      check
     102  job clock   status     status     status
     103
     104  .           .          .          timeout
     105                                    run
     106                                    timeout
     107
     108  must be at least one poll before timeout
     109  (timeout >= poll)
     110*/
  • trunk/Ohana/src/opihi/pantasks/CheckTasks.c

    r4603 r4684  
    1919    if (task[0].Nmax && (task[0].Njobs >= task[0].Nmax)) continue;
    2020
    21     SetCurrentTask (task[0].name);
    22 
    2321    /* ready to run? : run task.exec macro */
    2422    if (task[0].exec != NULL) {
     
    2624      if (!status) continue;
    2725    }
    28 
    29     /* is task valid?  check state of task.(argc, argv) */
    30     /*** ADD CODE HERE ***/
    3126
    3227    /* construct job from task */
  • trunk/Ohana/src/opihi/pantasks/ControllerOps.c

    r4602 r4684  
    5858  if (p != NULL) {
    5959    fprintf (stderr, "unknown job %d\n", job[0].pid);
     60    FreeIOBuffer (&buffer);
    6061    return (FALSE);
    6162  }
     
    384385
    385386
     387int KillControllerJob (Job *job) {
     388
     389  int status;
     390  char cmd[128];
     391  IOBuffer buffer;
     392
     393  sprintf (cmd, "kill %d", job[0].pid);
     394  InitIOBuffer (&buffer, 0x100);
     395  status = ControllerCommand (cmd, CONTROLLER_PROMPT, &buffer);
     396
     397  /** need to interpret output message & free things **/
     398  FreeIOBuffer (&buffer);
     399  return (TRUE);
     400}
     401
    386402/* memstr returns a view, not an allocated string : don't free */
  • trunk/Ohana/src/opihi/pantasks/JobOps.c

    r4450 r4684  
    11# include "scheduler.h"
    22
    3 # define MAX_N_JOBS 1000
    4 static char *JobIDList;
    5 static int   JobIDPtr = 0;
     3static Job **jobs;
     4static int   Njobs;
     5static int   NJOBS;
    66
    7 static char dot[] = ".";
     7/* counter marking job being visited by the run loop */
     8static int   ActiveJob;
    89
    9 static Job *jobs;
    10 static int  Njobs;
    11 static int  NJOBS;
    12 
    13 static char *JobName = dot;
    14 static int   CurrentJob = 0;
     10/* set up the jobs list */
     11void InitJobs () {
     12  NJOBS = 20;
     13  Njobs = 0;
     14  ALLOCATE (jobs, Job *, NJOBS);
     15  ActiveJob = -1;
     16}
    1517
    1618/* provide a mechanism to loop over the list of jobs */
     
    1921  Job *job;
    2022
    21   if (CurrentJob >= Njobs) {
    22     CurrentJob = 0;
     23  ActiveJob ++;
     24  if (ActiveJob < 0) ActiveJob = 0;
     25  if (ActiveJob >= Njobs) {
     26    ActiveJob = -1;
    2327    return (NULL);
    2428  }
    25 
    26   job = &jobs[CurrentJob];
    27   CurrentJob ++;
     29  job = jobs[ActiveJob];
    2830  return (job);
    29 }
    30 
    31 void InitJobs () {
    32   NJOBS = 20;
    33   Njobs = 0;
    34   ALLOCATE (jobs, Job, NJOBS);
    35   JobName = dot;
    36 
    37   ALLOCATE (JobIDList, char, MAX_N_JOBS);
    38   bzero (JobIDList, MAX_N_JOBS*sizeof(char));
    39 }
    40 
    41 /* return next unique ID, recycle every MAX_N_JOBS */
    42 int NextJobID () {
    43 
    44   int Ntry;
    45 
    46   JobIDPtr ++;
    47   if (JobIDPtr >= MAX_N_JOBS) JobIDPtr = 0;
    48 
    49   Ntry = 0;
    50   while (JobIDList[JobIDPtr]) {
    51     Ntry ++;
    52     JobIDPtr ++;
    53     if (JobIDPtr >= MAX_N_JOBS) JobIDPtr = 0;
    54     if (Ntry == MAX_N_JOBS) return (-1);
    55   }
    56   JobIDList[JobIDPtr] = TRUE;
    57   return (JobIDPtr);
    58 }
    59 
    60 /* list known jobs */
    61 void ListJobs () {
    62 
    63   int i;
    64 
    65   for (i = 0; i < Njobs; i++) {
    66     fprintf (stderr, "%d: %-15s %5d %20s (%x)\n", Njobs, jobs[i].task[0].name, jobs[i].JobID, jobs[i].argv[0], jobs[i].argv);
    67   }
    68   return;
    6931}
    7032
     
    7638  /* return job with matching JobID */
    7739  for (i = 0; i < Njobs; i++) {
    78     if (jobs[i].JobID == JobID) {
    79       return (&jobs[i]);
     40    if (jobs[i][0].JobID == JobID) {
     41      return (jobs[i]);
    8042    }
    8143  }
     
    8345
    8446
     47/* list known jobs */
     48void ListJobs () {
     49
     50  int i;
     51
     52  if (Njobs == 0) {
     53    fprintf (stderr, "no defined jobs\n");
     54    return;
     55  }
     56
     57  for (i = 0; i < Njobs; i++) {
     58    fprintf (stderr, "%d: %-15s %5d %20s (%x)\n", Njobs, jobs[i][0].task[0].name, jobs[i][0].JobID, jobs[i][0].argv[0], jobs[i][0].argv);
     59  }
     60  return;
     61}
     62
    8563/* make a new job from a task */
    8664Job *CreateJob (Task *task) {
    8765 
    8866  int i;
     67  Job *job;
     68 
     69  ALLOCATE (job, Job, 1);
    8970
    90   jobs[Njobs].JobID = NextJobID ();
    91   jobs[Njobs].pid = 0;
    92   jobs[Njobs].mode = JOB_LOCAL;
     71  job[0].JobID = NextJobID ();
     72  job[0].pid = 0;
     73  job[0].mode = JOB_LOCAL;
    9374  if (task[0].host != NULL) {
    94     jobs[Njobs].mode = JOB_CONTROLLER;
     75    job[0].mode = JOB_CONTROLLER;
    9576  }
    9677
     
    9980   *  we allocate one extra element, with value 0 to be passed to execvp
    10081   */
    101   jobs[Njobs].argc = task[0].argc;
    102   ALLOCATE (jobs[Njobs].argv, char *, MAX (task[0].argc + 1, 1));
     82  job[0].argc = task[0].argc;
     83  ALLOCATE (job[0].argv, char *, MAX (task[0].argc + 1, 1));
    10384  for (i = 0; i < task[0].argc; i++) {
    104     jobs[Njobs].argv[i] = strcreate (task[0].argv[i]);
     85    job[0].argv[i] = strcreate (task[0].argv[i]);
    10586  }
    106   jobs[Njobs].argv[i] = 0;
     87  job[0].argv[i] = 0;
    10788
    10889  /* other data from the task is needed by the job
     
    11192     be applied to the existing jobs */
    11293
    113   jobs[Njobs].task = task;
     94  job[0].task = task;
    11495 
    11596  /* if we decide we need to be able to dynamically set task qualities
     
    11798     entries to these quantites in the job structure */
    11899
     100  jobs[Njobs] = job;
    119101  Njobs ++;
    120102  if (Njobs == NJOBS) {
    121103    NJOBS += 20;
    122     REALLOCATE (jobs, Job, NJOBS);
     104    REALLOCATE (jobs, Job *, NJOBS);
    123105  }
    124   return (&jobs[Njobs-1]);
     106  return (jobs[Njobs-1]);
    125107}
    126108
     
    130112
    131113  if (job == NULL) return;
    132 
    133   if ((job[0].JobID >= 0) || (job[0].JobID < MAX_N_JOBS)) {
    134     JobIDList[job[0].JobID] = FALSE;
    135   }
     114 
     115  FreeJobID (job[0].JobID);
    136116
    137117  for (i = 0; i < job[0].argc; i++) {
     
    142122}
    143123
    144 void SetCurrentJob (char *name) {
    145   JobName = name;
    146 }
    147 
    148 char *GetCurrentJob () {
    149   return (JobName);
    150 }
    151 
     124/** are we deleting the active job?? **/
    152125int DeleteJob (Job *job) {
    153126
     
    156129  Nm = -1;
    157130  for (i = 0; i < Njobs; i++) {
    158     if (job == &jobs[i]) {
     131    if (job == jobs[i]) {
    159132      Nm = i;
    160133      break;
     
    166139  }
    167140
    168   FreeJob (&jobs[Nm]);
     141  FreeJob (jobs[Nm]);
    169142  for (i = Nm + 1; i < Njobs; i++)
    170143    jobs[i - 1] = jobs[i];
    171144  Njobs --;
    172145
    173   CurrentJob --;
    174   CurrentJob = MAX (CurrentJob, 0);
    175 
     146  /* adjust active job number */
     147  if (ActiveJob >= Nm) {
     148    ActiveJob --;
     149  }
    176150  return (TRUE);
    177151}
  • trunk/Ohana/src/opihi/pantasks/LocalJob.c

    r4602 r4684  
    102102  int result, waitstatus;
    103103
     104  fprintf (stderr, "checking on %d\n", job[0].pid);
     105
    104106  /* check local job status */
    105107  result = waitpid (job[0].pid, &waitstatus, WNOHANG);
     
    135137        exit (1);
    136138      }
     139      fprintf (stderr, "waited for %d\n", result);
    137140     
    138141      if (WIFEXITED(waitstatus)) {
     
    151154  return;
    152155}
     156
     157int KillLocalJob (Job *job) {
     158
     159  int i, result, waitstatus;
     160
     161  if (job[0].state != JOB_BUSY) return (TRUE);
     162
     163  /* send SIGTERM signal to job */
     164  kill (job[0].pid, SIGTERM);
     165  result = 0;
     166  for (i = 0; (i < 10) && (result == 0); i++) {
     167    usleep (10000);  /* 10 ms is min */
     168    result = waitpid (job[0].pid, &waitstatus, WNOHANG);
     169  }
     170  if (result) return (TRUE);
     171
     172  /* send SIGKILL signal to job */
     173  kill (job[0].pid, SIGKILL);
     174  result = 0;
     175  for (i = 0; (i < 10) && (result == 0); i++) {
     176    usleep (10000);  /* 10 ms is min */
     177    result = waitpid (job[0].pid, &waitstatus, WNOHANG);
     178  }
     179  if (result) return (TRUE);
     180
     181  /* total failure, don't reset */
     182  return (FALSE);
     183}
     184
  • trunk/Ohana/src/opihi/pantasks/Makefile

    r4603 r4684  
    3535$(SDIR)/LocalJob.$(ARCH).o \
    3636$(SDIR)/JobOps.$(ARCH).o \
     37$(SDIR)/JobIDOps.$(ARCH).o \
    3738$(SDIR)/TaskOps.$(ARCH).o \
    3839$(SDIR)/IOBufferOps.$(ARCH).o \
  • trunk/Ohana/src/opihi/pantasks/TaskOps.c

    r4603 r4684  
    1 # include "opihi.h"
    21# include "scheduler.h"
    32
    4 static char dot[] = ".";
    5 
    6 static Task *tasks;
    7 static int   Ntasks;
    8 static int   NTASKS;
    9 
    10 static char *TaskName = dot;
    11 
    12 static int   CurrentTask = 0;
    13 
    14 /* provide a mechanism to loop over the list of tasks */
    15 Task *NextTask () {
    16  
    17   Task *task;
    18 
    19   if (CurrentTask >= Ntasks) {
    20     CurrentTask = 0;
    21     return (NULL);
    22   }
    23 
    24   task = &tasks[CurrentTask];
    25   CurrentTask ++;
    26   return (task);
    27 }
    28 
     3static Task **tasks;
     4static int    Ntasks;
     5static int    NTASKS;
     6
     7/* counter marking task being visited by the run loop */
     8static int   ActiveTask;
     9
     10/* temporary holder for a new task */
     11static Task *NewTask = NULL;
     12
     13/* set up the task list system */
    2914void InitTasks () {
    3015  NTASKS = 20;
    3116  Ntasks = 0;
    32   ALLOCATE (tasks, Task, NTASKS);
    33   TaskName = dot;
    34 }
     17  ALLOCATE (tasks, Task *, NTASKS);
     18  ActiveTask = -1;
     19}
     20
     21/* provide a mechanism to loop over the list of tasks */
     22Task *NextTask () {
     23 
     24  Task *task;
     25
     26  /* move to the next task and return it */
     27  ActiveTask ++;
     28  if (ActiveTask < 0) ActiveTask = 0;
     29  if (ActiveTask >= Ntasks) {
     30    ActiveTask = -1;
     31    return (NULL);
     32  }
     33  task = tasks[ActiveTask];
     34  return (task);
     35}
     36
     37/* return task with given name */
     38Task *FindTask (char *name) {
     39
     40  int i;
     41
     42  /* try for an exact match first */
     43  for (i = 0; i < Ntasks; i++) {
     44    if (!strcmp (tasks[i][0].name, name)) {
     45      return (tasks[i]);
     46    }
     47  }
     48  return (NULL);
     49
    3550
    3651/* list known tasks */
    37 void ListTasks () {
     52void ListTasks (int verbose) {
    3853
    3954  int i, valid;
    4055
     56  if (Ntasks == 0) {
     57    fprintf (stderr, "no defined tasks\n");
     58    return;
     59  }
     60
     61  fprintf (stderr, "Task Status\n");
     62  fprintf (stderr, "  name            Njobs  command\n");
    4163  for (i = 0; i < Ntasks; i++) {
    42     valid = CheckTimeRanges (tasks[i].ranges, tasks[i].Nranges);
     64    valid = CheckTimeRanges (tasks[i][0].ranges, tasks[i][0].Nranges);
    4365    if (valid) {
    4466      fprintf (stderr, "+ ");
     
    4668      fprintf (stderr, "- ");
    4769    }
    48     fprintf (stderr, "%-15s %4d %20s\n", tasks[i].name, tasks[i].Njobs, tasks[i].argv[0]);
     70    fprintf (stderr, "%-15s %4d   %-20s\n", tasks[i][0].name, tasks[i][0].Njobs, tasks[i][0].argv[0]);
     71    if (verbose) {
     72      fprintf (stderr, "    spawn period: %f, polling period: %f, timeout period: %f\n",
     73               tasks[i][0].poll_period, tasks[i][0].poll_period, tasks[i][0].poll_period);
     74      if (tasks[i][0].host != NULL) {
     75        if (tasks[i][0].host_required) {
     76          fprintf (stderr, "    host %s (required)\n", tasks[i][0].host);
     77        } else {
     78          fprintf (stderr, "    host %s (desired)\n", tasks[i][0].host);
     79        }
     80      } else {
     81        fprintf (stderr, "    task runs locally\n");
     82      }     
     83    }
    4984  }
    5085  return;
     
    94129}
    95130
    96 /* return task with given name */
    97 Task *FindTask (char *name) {
    98 
     131/* make a new named task */
     132int FreeTask (Task *task) {
     133 
    99134  int i;
    100135
    101   /* try for an exact match first */
    102   for (i = 0; i < Ntasks; i++) {
    103     if (!strcmp (tasks[i].name, name)) {
    104       return (&tasks[i]);
    105     }
    106   }
    107   return (NULL);
    108 
     136  if (task == NULL) return (FALSE);
     137 
     138  if (task[0].name != NULL) free (task[0].name);
     139  if (task[0].host != NULL) free (task[0].host);
     140  if (task[0].argv != NULL) {
     141    for (i = 0; i < task[0].argc; i++) {
     142      free (task[0].argv[i]);
     143    }
     144    free (task[0].argv);
     145  }
     146  if (task[0].exec != NULL) {
     147    FreeMacro (task[0].exec);
     148    free (task[0].exec);
     149  }
     150  if (task[0].crash != NULL) {
     151    FreeMacro (task[0].crash);
     152    free (task[0].crash);
     153  }
     154  if (task[0].timeout != NULL) {
     155    FreeMacro (task[0].timeout);
     156    free (task[0].timeout);
     157  }
     158  for (i = 0; i < task[0].Nexit; i++) {
     159    if (task[0].exit[i] != NULL) {
     160      FreeMacro (task[0].exit[i]);
     161    }
     162    free (task[0].exit[i]);
     163  }
     164  free (task[0].exit);
     165
     166  if (task[0].ranges != NULL) {
     167    free (task[0].ranges);
     168  }
     169  return (TRUE);
     170}
     171
     172/**** new task functions ***/
    109173
    110174/* make a new named task */
    111175Task *CreateTask (char *name) {
    112176 
    113   tasks[Ntasks].name = strcreate (name);;
    114 
    115   tasks[Ntasks].host = NULL;
    116   tasks[Ntasks].host_required = FALSE;
    117 
    118   tasks[Ntasks].argc = 0;
    119   tasks[Ntasks].argv = NULL;
    120 
    121   tasks[Ntasks].exec = NULL;
    122   tasks[Ntasks].crash = NULL;
    123   tasks[Ntasks].timeout = NULL;
    124 
    125   tasks[Ntasks].Nexit = 0;
    126   tasks[Ntasks].NEXIT = 10;
    127   ALLOCATE (tasks[Ntasks].exit, Macro *, tasks[Ntasks].NEXIT);
     177  ALLOCATE (NewTask, Task, 1);
     178
     179  NewTask[0].name = strcreate (name);;
     180
     181  NewTask[0].host = NULL;
     182  NewTask[0].host_required = FALSE;
     183
     184  NewTask[0].argc = 0;
     185  NewTask[0].argv = NULL;
     186
     187  NewTask[0].exec = NULL;
     188  NewTask[0].crash = NULL;
     189  NewTask[0].timeout = NULL;
     190
     191  NewTask[0].Nexit = 0;
     192  NewTask[0].NEXIT = 10;
     193  ALLOCATE (NewTask[0].exit, Macro *, NewTask[0].NEXIT);
    128194  /* don't free tasks[0].exit, keep at least 1 allocated */
    129195
    130   tasks[Ntasks].exec_period = 1.0;
    131   tasks[Ntasks].poll_period = 1.0;
    132   tasks[Ntasks].timeout_period = 1.0;
    133 
    134   tasks[Ntasks].Nranges = 0;
    135   ALLOCATE (tasks[Ntasks].ranges, TimeRange, 1);
     196  NewTask[0].exec_period = 1.0;
     197  NewTask[0].poll_period = 1.0;
     198  NewTask[0].timeout_period = 1.0;
     199
     200  NewTask[0].Nranges = 0;
     201  ALLOCATE (NewTask[0].ranges, TimeRange, 1);
    136202
    137203  /* init task timer (is reset by 'run') */ 
    138   gettimeofday (&tasks[Ntasks].last, (void *) NULL);
    139   tasks[Ntasks].Njobs = 0;
    140   tasks[Ntasks].Nmax = 0;  /* default value means 'no limit' */
    141 
     204  gettimeofday (&NewTask[0].last, (void *) NULL);
     205  NewTask[0].Njobs = 0;
     206  NewTask[0].Nmax = 0;  /* default value means 'no limit' */
     207
     208  return (NewTask);
     209}
     210
     211int ValidateTask (Task *task) {
     212
     213  if (task[0].argc == 0) {
     214    fprintf (stderr, "task command not defined\n");
     215    return (FALSE);
     216  }
     217  if (task[0].argv == NULL) {
     218    fprintf (stderr, "task command arguments not defined (programming error)\n");
     219    return (FALSE);
     220  }
     221  return (TRUE);
     222}
     223
     224int RegisterNewTask () {
     225 
     226  int N;
     227
     228  N = Ntasks;
    142229  Ntasks ++;
    143230  if (Ntasks == NTASKS) {
    144231    NTASKS += 20;
    145     REALLOCATE (tasks, Task, NTASKS);
    146   }
    147   return (&tasks[Ntasks-1]);
    148 }
    149 
    150 void SetCurrentTask (char *name) {
    151   TaskName = name;
    152 }
    153 
    154 char *GetCurrentTask () {
    155   return (TaskName);
    156 }
     232    REALLOCATE (tasks, Task *, NTASKS);
     233  }
     234  tasks[N] = NewTask;
     235  NewTask = NULL;
     236  return (TRUE);
     237}
     238
     239int DeleteNewTask () {
     240  if (NewTask != NULL) {
     241    FreeTask (NewTask);
     242    free (NewTask);
     243    NewTask = NULL;
     244  }
     245  return (TRUE);
     246}
     247
     248Task *GetNewTask () {
     249  return (NewTask);
     250}
     251
     252/*** task timer functions ***/
    157253
    158254double GetTaskTimer (struct timeval start) {
  • trunk/Ohana/src/opihi/pantasks/kill.c

    r4552 r4684  
    1212  JobID = atoi (argv[1]);
    1313
    14   /* not yet implemented */
     14  job = FindJob (JobID);
    1515
     16  if (job[0].mode == JOB_LOCAL) {
     17    if (!KillLocalJob (job)) {
     18      job[0].state = JOB_HUNG;
     19      if (VerboseMode()) fprintf (stderr, "child process %d is hung, cannot kill\n", job[0].pid);
     20      return (FALSE);
     21    }
     22  } else {
     23    if (!KillControllerJob (job)) {
     24      job[0].state = JOB_HUNG;
     25      if (VerboseMode()) fprintf (stderr, "child process %d is hung, cannot kill\n", job[0].pid);
     26      return (FALSE);
     27    }
     28  }   
     29   
    1630  fprintf (stderr, "this function is not yet implemented\n");
    1731  return (TRUE);
  • trunk/Ohana/src/opihi/pantasks/scheduler.c

    r4450 r4684  
    1 # include "opihi.h"
    21# include "scheduler.h"
    32
     
    4645  InitTasks ();
    4746  InitJobs ();
     47  InitJobIDs ();
    4848
    4949  rl_readline_name = opihi_name;
  • trunk/Ohana/src/opihi/pantasks/status.c

    r4602 r4684  
    88    fprintf (stderr, "scheduler is running\n");
    99  }
    10   ListTasks ();
     10  ListTasks (FALSE);
    1111  ListJobs ();
    1212
  • trunk/Ohana/src/opihi/pantasks/task.c

    r4602 r4684  
    1414  if (N = get_argument (argc, argv, "-list")) {
    1515    remove_argument (N, &argc, argv);
    16     ListTasks ();
     16    ListTasks (FALSE);
     17    return (TRUE);
     18  }
     19
     20  if (N = get_argument (argc, argv, "-longlist")) {
     21    remove_argument (N, &argc, argv);
     22    ListTasks (TRUE);
    1723    return (TRUE);
    1824  }
     
    3440    task = CreateTask (argv[1]);
    3541  }
    36   SetCurrentTask (argv[1]);
     42  /* temporary task is saved statically
     43     add to list after definition is complete */
    3744
    3845  /* read in task from appropriate source (keyboard or list) until end */
     
    7178           have been defined.  delete the task if not */
    7279        free (input);
     80        /* validate the new task: all mandatory elements defined? */
     81        if (!ValidateTask (task)) {
     82          DeleteNewTask ();
     83          return (FALSE);
     84        }
     85        RegisterNewTask ();
    7386        return (TRUE);
    7487        break;
     
    92105    }
    93106  }
    94   return (TRUE);
     107  /* cannot ever reach here */
     108  return (FALSE);
    95109}
    96110
  • trunk/Ohana/src/opihi/pantasks/task_command.c

    r4451 r4684  
    44
    55  int i;
    6   char *taskname;
    76  Task *task;
    87
     
    1312  }
    1413
    15   taskname = GetCurrentTask ();
    16   if (taskname == NULL) {
     14  task = GetNewTask ();
     15  if (task == NULL) {
    1716    fprintf (stderr, "ERROR: not defining or running a task\n");
    18     return (FALSE);
    19   }
    20   task = FindTask (taskname);
    21   if (task == NULL) {
    22     fprintf (stderr, "ERROR: current task not found??\n");
    2317    return (FALSE);
    2418  }
  • trunk/Ohana/src/opihi/pantasks/task_host.c

    r4451 r4684  
    2222  }
    2323
    24   taskname = GetCurrentTask ();
    25   if (taskname == NULL) {
     24  task = GetNewTask ();
     25  if (task == NULL) {
    2626    fprintf (stderr, "ERROR: not defining or running a task\n");
    27     return (FALSE);
    28   }
    29   task = FindTask (taskname);
    30   if (task == NULL) {
    31     fprintf (stderr, "ERROR: current task not found??\n");
    3227    return (FALSE);
    3328  }
  • trunk/Ohana/src/opihi/pantasks/task_macros.c

    r4451 r4684  
    66
    77  int i, N, NLINES, done, depth, ThisList;
    8   char *taskname, *input;
     8  char *input;
    99  Macro *macro;
    1010  Task *task;
     
    2222  }
    2323
    24   taskname = GetCurrentTask ();
    25   if (taskname == NULL) {
     24  task = GetNewTask ();
     25  if (task == NULL) {
    2626    fprintf (stderr, "ERROR: not defining or running a task\n");
    27     return (FALSE);
    28   }
    29   task = FindTask (taskname);
    30   if (task == NULL) {
    31     fprintf (stderr, "ERROR: current task not found??\n");
    3227    return (FALSE);
    3328  }
  • trunk/Ohana/src/opihi/pantasks/task_nmax.c

    r4603 r4684  
    44
    55  Task *task;
    6   char *taskname;
    76
    87  if (argc != 2) goto usage;
    98
    10   taskname = GetCurrentTask ();
    11   if (taskname == NULL) {
     9  task = GetNewTask ();
     10  if (task == NULL) {
    1211    fprintf (stderr, "ERROR: not defining or running a task\n");
    13     return (FALSE);
    14   }
    15   task = FindTask (taskname);
    16   if (task == NULL) {
    17     fprintf (stderr, "ERROR: current task not found??\n");
    1812    return (FALSE);
    1913  }
  • trunk/Ohana/src/opihi/pantasks/task_periods.c

    r4451 r4684  
    55  int N, Poll, Exec, Timeout;
    66  float PollValue, ExecValue, TimeoutValue;
    7   char *taskname;
    87  Task *task;
    98
     
    3837  }
    3938
    40   taskname = GetCurrentTask ();
    41   if (taskname == NULL) {
     39  task = GetNewTask ();
     40  if (task == NULL) {
    4241    fprintf (stderr, "ERROR: not defining or running a task\n");
    43     return (FALSE);
    44   }
    45   task = FindTask (taskname);
    46   if (task == NULL) {
    47     fprintf (stderr, "ERROR: current task not found??\n");
    4842    return (FALSE);
    4943  }
  • trunk/Ohana/src/opihi/pantasks/task_trange.c

    r4602 r4684  
    66  Task *task;
    77  TimeRange range;
    8   char *taskname;
    98
    109  /* add a -reset option?
     
    2423  if (argc != 3) goto usage;
    2524
    26   taskname = GetCurrentTask ();
    27   if (taskname == NULL) {
     25  task = GetNewTask ();
     26  if (task == NULL) {
    2827    fprintf (stderr, "ERROR: not defining or running a task\n");
    29     return (FALSE);
    30   }
    31   task = FindTask (taskname);
    32   if (task == NULL) {
    33     fprintf (stderr, "ERROR: current task not found??\n");
    3428    return (FALSE);
    3529  }
  • trunk/Ohana/src/opihi/pcontrol/delete.c

    r4450 r4684  
    3939  return (TRUE);
    4040}
     41
     42/**** at the moment, this function requires the job to be in the correct state
     43      to be deleted.  This should be changed to kill, then delete job if it is
     44      not in the correct state
     45****/
  • trunk/Ohana/src/opihi/pcontrol/kill.c

    r4450 r4684  
    1212  JobID = atoi (argv[1]);
    1313
     14  /* XXX this function should only fail if a process is hung */
    1415  job = PullJob (JobID, PCONTROL_JOB_BUSY);
    1516  if (job == NULL) {
    1617    fprintf (stderr, "job %s not BUSY\n", argv[1]);
     18    /* make output message more readable by scheduler */
    1719    return (FALSE);
    1820  }
     21
     22  /* XXX - check on success / failure of kill */
    1923  KillJob (job);
     24
    2025  return (TRUE);
    2126}
Note: See TracChangeset for help on using the changeset viewer.