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