IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4697


Ignore:
Timestamp:
Aug 2, 2005, 9:40:50 AM (21 years ago)
Author:
eugene
Message:

psched bugfixes, moved IOBuffers and queues

Location:
trunk/Ohana/src/opihi
Files:
1 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/push.c

    r2598 r4697  
    33int push (int argc, char **argv) {
    44 
     5  int N, Unique, Replace, Key;
    56  Queue *queue;
    67
     8  Unique = FALSE;
     9  if ((N = get_argument (argc, argv, "-uniq"))) {
     10    remove_argument (N, &argc, argv);
     11    Unique = TRUE;
     12  }
     13
     14  Replace = FALSE;
     15  if ((N = get_argument (argc, argv, "-replace"))) {
     16    remove_argument (N, &argc, argv);
     17    Replace = TRUE;
     18  }
     19
     20  Key = -1;
     21  if ((N = get_argument (argc, argv, "-key"))) {
     22    remove_argument (N, &argc, argv);
     23    Key = atoi (argv[N]);
     24    remove_argument (N, &argc, argv);
     25  }
     26
    727  if (argc != 3) {
    8     fprintf (stderr, "USAGE: push (queue) (value)\n");
     28    fprintf (stderr, "USAGE: push (queue) (value) [-key N] [-uniq] [-replace]\n");
    929    return (FALSE);
    1030  }
     
    1232  /* will create a queue if none exists */
    1333  queue = CreateQueue (argv[1]);
    14   PushQueue (queue, argv[2]);
     34
     35  if (Unique) {
     36    PushQueueUnique (queue, argv[2], Key);
     37  }
     38  if (Replace) {
     39    PushQueueReplace (queue, argv[2], Key);
     40  }
     41  if (!Unique && !Replace) {
     42    PushQueue (queue, argv[2]);
     43  }
    1544  return (TRUE);
    1645}
  • trunk/Ohana/src/opihi/include/data.h

    r4693 r4697  
    3131int FlushIOBuffer (IOBuffer *buffer);
    3232int ReadtoIOBuffer (IOBuffer *buffer, int fd);
     33int EmptyIOBuffer (IOBuffer *buffer, int Nmax, int fd);
    3334void FreeIOBuffer (IOBuffer *buffer);
    3435
     
    3940Queue *CreateQueue (char *name);
    4041void PushQueue (Queue *queue, char *line);
     42void PushNamedQueue (char *name, char *line);
    4143char *PopQueue (Queue *queue);
     44void PushQueueUnique (Queue *queue, char *line, int Key);
     45void PushQueueReplace (Queue *queue, char *line, int Key);
    4246
    4347/* in sort.c */
  • trunk/Ohana/src/opihi/include/psched.h

    r4693 r4697  
    2323
    2424enum {RANGE_ABS, RANGE_DAY, RANGE_WEEK};
     25
     26enum {TASK_NONE,
     27      TASK_EMPTY,
     28      TASK_COMMENT,
     29      TASK_NMAX,
     30      TASK_TRANGE,
     31      TASK_END,
     32      TASK_HOST,
     33      TASK_COMMAND,
     34      TASK_PERIODS,
     35      TASK_EXIT,
     36      TASK_EXEC
     37} TaskHashResults;
    2538
    2639typedef struct {
     
    91104  JobMode     mode;                     /* local or controller? */
    92105
    93   int         stdout_size;              /* stdout pipe (local only) */
    94   int         stderr_size;              /* stderr pipe (local only) */
     106  int         stdout_size;              /* size of pending stdout buffer (controller) */
     107  int         stderr_size;              /* size of pending stderr buffer (controller) */
    95108  int         stdout_fd;                /* stdout pipe (local only) */
    96109  int         stderr_fd;                /* stderr pipe (local only) */
     
    110123int FreeTask (Task *task);
    111124Task *CreateTask (char *name);
    112 int ValidateTask (Task *task);
     125int ValidateTask (Task *task, int RequireStatic);
    113126int RegisterNewTask ();
    114127int DeleteNewTask ();
    115128Task *GetNewTask ();
     129Task *GetActiveTask ();
    116130void SetTaskTimer (struct timeval *timer);
    117131double GetTaskTimer (struct timeval start);
  • trunk/Ohana/src/opihi/lib.data/IOBufferOps.c

    r4693 r4697  
    1 # include "pclient.h"
     1# include "data.h"
    22
    33int InitIOBuffer (IOBuffer *buffer, int Nalloc) {
     
    6161}
    6262
     63/* read until buffer is empty (Nmax retries) */
     64int EmptyIOBuffer (IOBuffer *buffer, int Nmax, int fd) {
     65
     66  int i, status;
     67
     68  status = -1;
     69  for (i = 0; (status != 0) && (i < Nmax); i++) {
     70    status = ReadtoIOBuffer (buffer, fd);
     71    if (status == -1) usleep (10000);
     72    if (status > 0) i = 0;
     73  }
     74  if (status == -1) return (FALSE);
     75  return (TRUE);
     76}
     77
    6378void FreeIOBuffer (IOBuffer *buffer) {
    6479
  • trunk/Ohana/src/opihi/lib.data/Makefile

    r4693 r4697  
    3636$(SDIR)/open_graph.$(ARCH).o            \
    3737$(SDIR)/open_image.$(ARCH).o            \
     38$(SDIR)/queues.$(ARCH).o                \
    3839$(SDIR)/IOBufferOps.$(ARCH).o           \
    3940$(SDIR)/PlotVectors.$(ARCH).o
  • trunk/Ohana/src/opihi/lib.data/convert.c

    r4689 r4697  
    11# include "convert.h"
    2 # define _XOPEN_SOURCE /* glibc2 needs this */
     2# define _XOPEN_SOURCE /* glibc2 (strptime) needs this */
    33# include <time.h>
    44
  • trunk/Ohana/src/opihi/lib.data/queues.c

    r4693 r4697  
    1 # include "opihi.h"
     1# include "data.h"
    22
    33/* These functions are somewhat fragile: we cannot do multiple CreateQueue
     
    5656}
    5757
     58void PushNamedQueue (char *name, char *line) {
     59
     60  Queue *queue;
     61 
     62  queue = FindQueue (name);
     63  if (queue == NULL) {
     64    queue = CreateQueue (name);
     65  }
     66  PushQueue (queue, line);
     67  return;
     68}
     69
     70/* push line onto queue.  return chars create new lines */
    5871void PushQueue (Queue *queue, char *line) {
    5972
    6073  int N;
    61 
     74  char *p, *q;
     75
     76  p = line;
     77  q = strchr (line, '\n');
    6278  N = queue[0].Nlines;
    63   queue[0].lines[N] = strcreate (line);
    64   queue[0].Nlines ++;
    65   if (queue[0].Nlines == queue[0].NLINES) {
    66     queue[0].NLINES += 10;
    67     REALLOCATE (queue[0].lines, char *, queue[0].NLINES);
    68   }   
     79  while (q != NULL) {
     80    queue[0].lines[N] = strncreate (p, q - p);
     81    N++;
     82    CHECK_REALLOCATE (queue[0].lines, char *, queue[0].NLINES, N, 16);
     83    p = q + 1;
     84    q = strchr (p, '\n');
     85  }   
     86  if (*p) {
     87    queue[0].lines[N] = strcreate (p);
     88    N++;
     89    CHECK_REALLOCATE (queue[0].lines, char *, queue[0].NLINES, N, 16);
     90  }
     91  queue[0].Nlines = N;
     92  return;
     93}
     94
     95char *ChooseKey (char *line, int Key) {
     96
     97  int i;
     98  char *key, *p;
     99
     100  key = line;
     101  if (Key != -1) {
     102    for (i = 0; (i < Key) && (key != NULL); i++) {
     103      p = nextword (key);
     104      key = p;
     105    }
     106    key = thisword (key);
     107  }
     108  return (key);
     109}
     110
     111/* push line onto queue, skipping existing matches (optionally by key) */
     112void PushQueueUnique (Queue *queue, char *line, int Key) {
     113
     114  int i, j, N, found;
     115  char *p, *q, *key1, *key2;
     116  Queue tmp;
     117
     118  /* init tmp queue */
     119  tmp.Nlines = 0;
     120  tmp.NLINES = 16;
     121  ALLOCATE (tmp.lines, char *, tmp.NLINES);
     122
     123  /* push entries on tmp queue */
     124  p = line;
     125  q = strchr (line, '\n');
     126  N = tmp.Nlines;
     127  while (q != NULL) {
     128    tmp.lines[N] = strncreate (p, q - p);
     129    N++;
     130    CHECK_REALLOCATE (tmp.lines, char *, tmp.NLINES, N, 16);
     131    p = q + 1;
     132    q = strchr (p, '\n');
     133  }   
     134  if (*p) {
     135    tmp.lines[N] = strcreate (p);
     136    N++;
     137    CHECK_REALLOCATE (tmp.lines, char *, tmp.NLINES, N, 16);
     138  }
     139  tmp.Nlines = N;
     140
     141  /* add unique entries in tmp to queue */
     142  for (i = 0; i < tmp.Nlines; i++) {
     143    key1 = ChooseKey (tmp.lines[i], Key);
     144    if (key1 == NULL) continue;
     145    found = FALSE;
     146    for (j = 0; !found && (j < queue[0].Nlines); j++) {
     147      key2 = ChooseKey (queue[0].lines[j], Key);
     148      if (key2 == NULL) continue;
     149      if (strcmp (key1, key2)) {
     150        if (Key != -1) free (key2);
     151        continue;
     152      }
     153      found = TRUE;
     154      if (Key != -1) free (key2);
     155    }     
     156    if (!found) PushQueue (queue, tmp.lines[i]);
     157    if (Key != -1) free (key1);
     158  }
     159  for (i = 0; i < tmp.Nlines; i++) {
     160    free (tmp.lines[i]);
     161  }
     162  free (tmp.lines);
     163  return;
     164}
     165
     166/* push line onto queue, replacing matches (optionally by Key) */
     167void PushQueueReplace (Queue *queue, char *line, int Key) {
     168
     169  int i, j, N, found;
     170  char *p, *q, *key1, *key2;
     171  Queue tmp;
     172
     173  /* init tmp queue */
     174  tmp.Nlines = 0;
     175  tmp.NLINES = 16;
     176  ALLOCATE (tmp.lines, char *, tmp.NLINES);
     177
     178  /* push entries on tmp queue */
     179  p = line;
     180  q = strchr (line, '\n');
     181  N = tmp.Nlines;
     182  while (q != NULL) {
     183    tmp.lines[N] = strncreate (p, q - p);
     184    N++;
     185    CHECK_REALLOCATE (tmp.lines, char *, tmp.NLINES, N, 16);
     186    p = q + 1;
     187    q = strchr (p, '\n');
     188  }   
     189  if (*p) {
     190    tmp.lines[N] = strcreate (p);
     191    N++;
     192    CHECK_REALLOCATE (tmp.lines, char *, tmp.NLINES, N, 16);
     193  }
     194  tmp.Nlines = N;
     195
     196  /* add unique entries in tmp to queue */
     197  for (i = 0; i < tmp.Nlines; i++) {
     198    key1 = ChooseKey (tmp.lines[i], Key);
     199    if (key1 == NULL) continue;
     200    found = FALSE;
     201    for (j = 0; !found && (j < queue[0].Nlines); j++) {
     202      key2 = ChooseKey (queue[0].lines[j], Key);
     203      if (key2 == NULL) continue;
     204      if (strcmp (key1, key2)) {
     205        if (Key != -1) free (key2);
     206        continue;
     207      }
     208      queue[0].lines[j] = strcreate (tmp.lines[i]);
     209      found = TRUE;
     210      if (Key != -1) free (key2);
     211    }     
     212    if (!found) PushQueue (queue, tmp.lines[i]);
     213    if (Key != -1) free (key1);
     214  }
     215  for (i = 0; i < tmp.Nlines; i++) {
     216    free (tmp.lines[i]);
     217  }
     218  free (tmp.lines);
    69219  return;
    70220}
  • trunk/Ohana/src/opihi/lib.shell/Makefile

    r4689 r4697  
    5555$(SDIR)/dvomath.$(ARCH).o               \
    5656$(SDIR)/stack_math.$(ARCH).o            \
    57 $(SDIR)/queues.$(ARCH).o                \
    5857$(SDIR)/variable.$(ARCH).o              \
    5958$(SDIR)/opihi.$(ARCH).o
  • trunk/Ohana/src/opihi/pantasks/CheckJobs.c

    r4693 r4697  
    2929        /* XXX this will break on 0 values in output streams */
    3030        if (VerboseMode()) fprintf (stderr, "job %s (%d) crash\n", job[0].task[0].name, job[0].JobID);
    31         set_str_variable ("stdout", job[0].stdout.buffer);
    32         set_str_variable ("stderr", job[0].stderr.buffer);
     31        PushNamedQueue ("stdout", job[0].stdout.buffer);
     32        PushNamedQueue ("stderr", job[0].stderr.buffer);
    3333        if (job[0].task[0].crash != NULL) {
    3434          exec_loop (job[0].task[0].crash);
     
    4040      case JOB_EXIT:
    4141        if (VerboseMode()) fprintf (stderr, "job %s (%d) exit\n", job[0].task[0].name, job[0].JobID);
    42         set_str_variable ("stdout", job[0].stdout.buffer);
    43         set_str_variable ("stderr", job[0].stderr.buffer);
     42        PushNamedQueue ("stdout", job[0].stdout.buffer);
     43        PushNamedQueue ("stderr", job[0].stderr.buffer);
    4444        /* run corresponding task[0].exit macro, if it exists */
    4545        macro = job[0].task[0].def;
  • trunk/Ohana/src/opihi/pantasks/CheckTasks.c

    r4693 r4697  
    2222      if (!status) continue;
    2323    }
     24    if (!ValidateTask (task, TRUE)) continue;
    2425
    2526    /* construct job from task */
  • trunk/Ohana/src/opihi/pantasks/ControllerOps.c

    r4693 r4697  
    33# define CONNECT_TIMEOUT 300
    44
     5/* local static variables to hold the connection to the controller */
    56static int status = FALSE;
    67static int stdin_cntl, stdout_cntl, stderr_cntl;
     
    89static IOBuffer stderr_buffer;
    910
     11/* test if the controller is running */
    1012int CheckControllerStatus () {
    1113  return (status);
    1214}
    1315
     16/* check job / get output if done */
    1417int CheckControllerJob (Job *job) {
    1518
     
    2326}
    2427
     28/* ask controller about job status */
    2529int CheckControllerJobStatus (Job *job) {
    2630
  • trunk/Ohana/src/opihi/pantasks/LocalJob.c

    r4693 r4697  
    11# include "psched.h"
     2
     3/* local jobs are forked in the background
     4   we might need to limit the maximum number of local jobs.
     5   should we have a queue/stack of pending local jobs, much
     6   like controller? */
     7
     8/* update current state, drain stdout/stderr buffers */
     9int CheckLocalJob (Job *job) {
     10
     11  int Nread;
     12
     13  // XXX do something useful with exit status?
     14  CheckLocalJobStatus (job);
     15
     16  if ((job[0].state == JOB_EXIT) || (job[0].state == JOB_CRASH)) {
     17    EmptyIOBuffer (&job[0].stdout, 10, job[0].stdout_fd);
     18    EmptyIOBuffer (&job[0].stderr, 10, job[0].stderr_fd);
     19    close (job[0].stdout_fd);
     20    close (job[0].stderr_fd);
     21  } else {
     22    /* read stdout buffer */
     23    Nread = ReadtoIOBuffer (&job[0].stdout, job[0].stdout_fd);
     24    switch (Nread) {
     25      case -2:  /* error in read (programming error?  system level error?) */
     26        fprintf (stderr, "serious IO error\n");
     27        exit (2);
     28      case -1:  /* no data in pipe */
     29      case 0:   /* pipe is closed, change child state? **/
     30      default:  /* data in pipe */
     31        break;
     32    }
     33 
     34    /* read stderr buffer */
     35    Nread = ReadtoIOBuffer (&job[0].stderr, job[0].stderr_fd);
     36    switch (Nread) {
     37      case -2:  /* error in read (programming error?  system level error?) */
     38        fprintf (stderr, "serious IO error\n");
     39        exit (2);
     40      case -1:  /* no data in pipe */
     41      case 0:   /* pipe is closed, change child state? **/
     42      default:  /* data in pipe */
     43        break;
     44    }
     45  }
     46  return (TRUE);
     47}
     48
     49int CheckLocalJobStatus (Job *job) {
     50
     51  int result, waitstatus;
     52
     53  /* check local job status */
     54  result = waitpid (job[0].pid, &waitstatus, WNOHANG);
     55  switch (result) {
     56    case -1:  /* error with waitpid */
     57      switch (errno) {
     58        case ECHILD:
     59          fprintf (stderr, "unknown PID, not a child proc\n");
     60          fprintf (stderr, "did process already exit?  programming error?\n");
     61          job[0].state = JOB_NONE;
     62          job[0].exit_status = 0;
     63          return (FALSE);
     64        case EINVAL:
     65          fprintf (stderr, "error EINVAL (waitpid): programming error\n");
     66          exit (1);
     67        case EINTR:
     68          fprintf (stderr, "error EINTR (waitpid): programming error\n");
     69          exit (1);
     70        default:
     71          fprintf (stderr, "unknown error for waitpid (%d): programming error\n", errno);
     72          exit (1);
     73      }
     74      break;
     75     
     76    case 0:  /* process not exited */
     77      job[0].state = JOB_BUSY;
     78      job[0].exit_status = 0;
     79      return (TRUE);
     80
     81    default:
     82      if (result != job[0].pid) {
     83        fprintf (stderr, "waitpid error: mis-matched PID (%d vs %d).  programming error\n", result, job[0].pid);
     84        exit (1);
     85      }
     86      if (WIFEXITED(waitstatus)) {
     87        job[0].state = JOB_EXIT;
     88        job[0].exit_status = WEXITSTATUS(waitstatus);
     89      }
     90      if (WIFSIGNALED(waitstatus)) {
     91        job[0].state = JOB_CRASH;
     92        job[0].exit_status = WTERMSIG(waitstatus);
     93      }
     94      if (WIFSTOPPED(waitstatus)) {
     95        fprintf (stderr, "waitpid returns 'stopped': programming error\n");
     96        exit (1);
     97      }
     98  }
     99  return (FALSE);
     100}
    2101
    3102/* this could be written a just a one-way pipe */
     
    58157}
    59158
    60 /* update current state, drain stdout/stderr buffers */
    61 int CheckLocalJob (Job *job) {
    62 
    63   int Nread;
    64 
    65   // XXX do something useful with exit status?
    66   CheckLocalJobStatus (job);
    67 
    68   if ((job[0].state == JOB_EXIT) || (job[0].state == JOB_CRASH)) {
    69     EmptyIOBuffer (&job[0].stdout, job[0].stdout_fd);
    70     EmptyIOBuffer (&job[0].stderr, job[0].stderr_fd);
    71   } else {
    72     /* read stdout buffer */
    73     Nread = ReadtoIOBuffer (&job[0].stdout, job[0].stdout_fd);
    74     switch (Nread) {
    75       case -2:  /* error in read (programming error?  system level error?) */
    76         fprintf (stderr, "serious IO error\n");
    77         exit (2);
    78       case -1:  /* no data in pipe */
    79       case 0:   /* pipe is closed, change child state? **/
    80       default:  /* data in pipe */
    81         break;
    82     }
    83  
    84     /* read stderr buffer */
    85     Nread = ReadtoIOBuffer (&job[0].stderr, job[0].stderr_fd);
    86     switch (Nread) {
    87       case -2:  /* error in read (programming error?  system level error?) */
    88         fprintf (stderr, "serious IO error\n");
    89         exit (2);
    90       case -1:  /* no data in pipe */
    91       case 0:   /* pipe is closed, change child state? **/
    92       default:  /* data in pipe */
    93         break;
    94     }
    95   }
    96   return (TRUE);
    97 }
    98 
    99 int CheckLocalJobStatus (Job *job) {
    100 
    101   int result, waitstatus;
    102 
    103   /*** if child has exited, does the pipe hang around until it is flushed? ***/
    104   /*** who closes the child stdout/stderr fd? */
    105 
    106   /* check local job status */
    107   result = waitpid (job[0].pid, &waitstatus, WNOHANG);
    108   switch (result) {
    109     case -1:  /* error with waitpid */
    110       switch (errno) {
    111         case ECHILD:
    112           fprintf (stderr, "unknown PID, not a child proc\n");
    113           fprintf (stderr, "did process already exit?  programming error?\n");
    114           job[0].state = JOB_NONE;
    115           job[0].exit_status = 0;
    116           return (FALSE);
    117         case EINVAL:
    118           fprintf (stderr, "error EINVAL (waitpid): programming error\n");
    119           exit (1);
    120         case EINTR:
    121           fprintf (stderr, "error EINTR (waitpid): programming error\n");
    122           exit (1);
    123         default:
    124           fprintf (stderr, "unknown error for waitpid (%d): programming error\n", errno);
    125           exit (1);
    126       }
    127       break;
    128      
    129     case 0:  /* process not exited */
    130       job[0].state = JOB_BUSY;
    131       job[0].exit_status = 0;
    132       return (TRUE);
    133 
    134     default:
    135       if (result != job[0].pid) {
    136         fprintf (stderr, "waitpid error: mis-matched PID (%d vs %d).  programming error\n", result, job[0].pid);
    137         exit (1);
    138       }
    139       if (WIFEXITED(waitstatus)) {
    140         job[0].state = JOB_EXIT;
    141         job[0].exit_status = WEXITSTATUS(waitstatus);
    142       }
    143       if (WIFSIGNALED(waitstatus)) {
    144         job[0].state = JOB_CRASH;
    145         job[0].exit_status = WTERMSIG(waitstatus);
    146       }
    147       if (WIFSTOPPED(waitstatus)) {
    148         fprintf (stderr, "waitpid returns 'stopped': programming error\n");
    149         exit (1);
    150       }
    151   }
    152   return (FALSE);
    153 }
    154 
     159/* should this function close the fd's? */
    155160int KillLocalJob (Job *job) {
    156161
  • trunk/Ohana/src/opihi/pantasks/TaskOps.c

    r4693 r4697  
    6868      fprintf (stderr, "- ");
    6969    }
    70     fprintf (stderr, "%-15s %4d   %-20s\n", tasks[i][0].name, tasks[i][0].Njobs, tasks[i][0].argv[0]);
     70    if (tasks[i][0].argv == NULL) {
     71      fprintf (stderr, "%-15s %4d   %-20s\n", tasks[i][0].name, tasks[i][0].Njobs, "dynamic");
     72    } else {
     73      fprintf (stderr, "%-15s %4d   %-20s\n", tasks[i][0].name, tasks[i][0].Njobs, tasks[i][0].argv[0]);
     74    }
    7175    if (verbose) {
    7276      fprintf (stderr, "    spawn period: %f, polling period: %f, timeout period: %f\n",
     
    209213}
    210214
    211 int ValidateTask (Task *task) {
    212 
    213   if (task[0].argc == 0) {
     215int ValidateTask (Task *task, int RequireStatic) {
     216
     217  int i, hash;
     218
     219  /* is a static command defined? */
     220  if (task[0].argc != 0) {
     221    if (task[0].argv == NULL) {
     222      fprintf (stderr, "task command arguments not defined (programming error)\n");
     223      return (FALSE);
     224    }
     225    return (TRUE);
     226  }
     227  if (RequireStatic) {
    214228    fprintf (stderr, "task command not defined\n");
    215229    return (FALSE);
    216230  }
    217   if (task[0].argv == NULL) {
    218     fprintf (stderr, "task command arguments not defined (programming error)\n");
    219     return (FALSE);
    220   }
    221   return (TRUE);
     231
     232  /* no static command; dynamic command? */
     233  if (task[0].exec != NULL) {
     234    for (i = 0; i < task[0].exec[0].Nlines; i++) {
     235      hash = TaskHash (task[0].exec[0].line[i]);
     236      if (hash == TASK_COMMAND) return (TRUE);
     237    }
     238  }
     239  fprintf (stderr, "task command not defined\n");
     240  return (FALSE);
    222241}
    223242
     
    250269}
    251270
     271Task *GetActiveTask () {
     272  Task *task;
     273  if (ActiveTask < 0) return (NULL);
     274  task = tasks[ActiveTask];
     275  return (task);
     276}
     277
     278int TaskHash (char *input) {
     279 
     280  int hash;
     281  char *command;
     282
     283  hash = TASK_NONE;
     284
     285  command = thisword (input);
     286  if (command == NULL) return (TASK_EMPTY);
     287
     288  if (command[0] == '#')                  hash = TASK_COMMENT;
     289  if (!strcasecmp (command, "END"))       hash = TASK_END;
     290  if (!strcasecmp (command, "HOST"))      hash = TASK_HOST;
     291  if (!strcasecmp (command, "NMAX"))      hash = TASK_NMAX;
     292  if (!strcasecmp (command, "TRANGE"))    hash = TASK_TRANGE;
     293  if (!strcasecmp (command, "COMMAND"))   hash = TASK_COMMAND;
     294  if (!strcasecmp (command, "PERIODS"))   hash = TASK_PERIODS;
     295  if (!strcasecmp (command, "TASK.EXIT")) hash = TASK_EXIT;
     296  if (!strcasecmp (command, "TASK.EXEC")) hash = TASK_EXEC;
     297
     298  free (command);
     299  return (hash);
     300}
     301
    252302/*** task timer functions ***/
    253303
  • trunk/Ohana/src/opihi/pantasks/task.c

    r4693 r4697  
    22# define prompt "> "
    33
    4 enum {TASK_NONE, TASK_EMPTY, TASK_COMMENT, TASK_NMAX, TASK_TRANGE, TASK_END, TASK_HOST, TASK_COMMAND, TASK_PERIODS, TASK_EXIT, TASK_EXEC};
    5 
    64int task (int argc, char **argv) {
    75
    8   int N;
     6  int N, hash;
    97  int ThisList, status;
    108  char *input, *outline;
     
    6664
    6765    stripwhite (input);
    68     switch (TaskHash (input)) {
     66    hash = TaskHash (input);
     67    switch (hash) {
    6968
    7069      case TASK_EMPTY:
     
    7877        free (input);
    7978        /* validate the new task: all mandatory elements defined? */
    80         if (!ValidateTask (task)) {
     79        if (!ValidateTask (task, FALSE)) {
    8180          DeleteNewTask ();
    8281          return (FALSE);
     
    107106  return (FALSE);
    108107}
    109 
    110 int TaskHash (char *input) {
    111  
    112   int hash;
    113   char *command;
    114 
    115   hash = TASK_NONE;
    116 
    117   command = thisword (input);
    118   if (command == NULL) return (TASK_EMPTY);
    119 
    120   if (command[0] == '#')                  hash = TASK_COMMENT;
    121   if (!strcasecmp (command, "END"))       hash = TASK_END;
    122   if (!strcasecmp (command, "HOST"))      hash = TASK_HOST;
    123   if (!strcasecmp (command, "NMAX"))      hash = TASK_NMAX;
    124   if (!strcasecmp (command, "TRANGE"))    hash = TASK_TRANGE;
    125   if (!strcasecmp (command, "COMMAND"))   hash = TASK_COMMAND;
    126   if (!strcasecmp (command, "PERIODS"))   hash = TASK_PERIODS;
    127   if (!strcasecmp (command, "TASK.EXIT")) hash = TASK_EXIT;
    128   if (!strcasecmp (command, "TASK.EXEC")) hash = TASK_EXEC;
    129 
    130   free (command);
    131   return (hash);
    132 }
  • trunk/Ohana/src/opihi/pantasks/task_command.c

    r4693 r4697  
    1414  task = GetNewTask ();
    1515  if (task == NULL) {
    16     fprintf (stderr, "ERROR: not defining or running a task\n");
    17     return (FALSE);
     16    task = GetActiveTask ();
     17    if (task == NULL) {
     18      fprintf (stderr, "ERROR: not defining or running a task\n");
     19      return (FALSE);
     20    }
    1821  }
    1922
  • trunk/Ohana/src/opihi/scripts/sched.pro

    r4693 r4697  
    33
    44task test
    5   command ls /data/eugene
     5  command ls
    66  periods -poll 1.0
    7   periods -exec 5.0
     7  periods -exec 2.0
    88  periods -timeout 10.0
    99  # trange 07:09 07:10
     
    1818  end
    1919
     20  # stdout / stderr lines on named queues
    2021  task.exit 0
    21     # note that $stdout/$stderr may contain return characters
    22     # which will interfere with 'exec'
    23     # push ls.list $stdout
    24     echo $stdout
     22    echo "task exit 0"
     23    queuesize stdout
     24    queuesize stderr
    2525  end
    2626
    2727  task.exit 1
    28     output failure.log
    29     echo $stdout
    30     output stdout
     28    echo "task exit 1"
     29    queuesize stdout
     30    queuesize stderr
    3131  end
    3232
Note: See TracChangeset for help on using the changeset viewer.