home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / CronVixie2.1 / job.c < prev    next >
C/C++ Source or Header  |  1992-01-14  |  2KB  |  77 lines

  1. #if !defined(lint) && !defined(LINT)
  2. static char rcsid[] = "$Header: job.c,v 1.2 90/07/18 00:23:59 vixie Exp $";
  3. #endif
  4.  
  5. /* Copyright 1988,1990 by Paul Vixie
  6.  * All rights reserved
  7.  *
  8.  * Distribute freely, except: don't remove my name from the source or
  9.  * documentation (don't take credit for my work), mark your changes (don't
  10.  * get me blamed for your possible bugs), don't alter or remove this
  11.  * notice.  May be sold if buildable source is provided to buyer.  No
  12.  * warrantee of any kind, express or implied, is included with this
  13.  * software; use at your own risk, responsibility for damages (if any) to
  14.  * anyone resulting from the use of this software rests entirely with the
  15.  * user.
  16.  *
  17.  * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  18.  * I'll try to keep a version up to date.  I can be reached as follows:
  19.  * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  20.  * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  21.  */
  22.  
  23.  
  24. #include "cron.h"
  25.  
  26.  
  27. typedef    struct    _job
  28.     {
  29.         struct _job    *next;
  30.         char        *cmd;
  31.         user        *u;
  32.     }
  33.     job;
  34.  
  35.  
  36. static job    *jhead = NULL, *jtail = NULL;
  37.  
  38.  
  39. void
  40. job_add(cmd, u)
  41.     register char *cmd;
  42.     register user *u;
  43. {
  44.     register job *j;
  45.  
  46.     /* if already on queue, keep going */
  47.     for (j=jhead; j; j=j->next)
  48.         if (j->cmd == cmd && j->u == u) { return; }
  49.  
  50.     /* build a job queue element */
  51.     j = (job*)malloc(sizeof(job));
  52.     j->next = (job*) NULL;
  53.     j->cmd = cmd;
  54.     j->u = u;
  55.  
  56.     /* add it to the tail */
  57.     if (!jhead) { jhead=j; }
  58.     else { jtail->next=j; }
  59.     jtail = j;
  60. }
  61.  
  62.  
  63. int
  64. job_runqueue()
  65. {
  66.     register job    *j;
  67.     register int    run = 0;
  68.  
  69.     for (j=jhead; j; j=j->next) {
  70.         do_command(j->cmd, j->u);
  71.         free(j);
  72.         run++;
  73.     }
  74.     jhead = jtail = NULL;
  75.     return run;
  76. }
  77.