xref: /dragonfly/usr.sbin/cron/cron/job.c (revision 6e285212)
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          <paul@vix.com>          uunet!decwrl!vixie!paul
16  *
17  * $FreeBSD: src/usr.sbin/cron/cron/job.c,v 1.6 1999/08/28 01:15:50 peter Exp $
18  * $DragonFly: src/usr.sbin/cron/cron/job.c,v 1.2 2003/06/17 04:29:53 dillon Exp $
19  */
20 
21 #include "cron.h"
22 
23 
24 typedef	struct _job {
25 	struct _job	*next;
26 	entry		*e;
27 	user		*u;
28 } job;
29 
30 
31 static job	*jhead = NULL, *jtail = NULL;
32 
33 
34 void
35 job_add(e, u)
36 	register entry *e;
37 	register user *u;
38 {
39 	register job *j;
40 
41 	/* if already on queue, keep going */
42 	for (j=jhead; j; j=j->next)
43 		if (j->e == e && j->u == u) { return; }
44 
45 	/* build a job queue element */
46 	if ((j = (job*)malloc(sizeof(job))) == NULL)
47 		return;
48 	j->next = (job*) NULL;
49 	j->e = e;
50 	j->u = u;
51 
52 	/* add it to the tail */
53 	if (!jhead) { jhead=j; }
54 	else { jtail->next=j; }
55 	jtail = j;
56 }
57 
58 
59 int
60 job_runqueue()
61 {
62 	register job	*j, *jn;
63 	register int	run = 0;
64 
65 	for (j=jhead; j; j=jn) {
66 		do_command(j->e, j->u);
67 		jn = j->next;
68 		free(j);
69 		run++;
70 	}
71 	jhead = jtail = NULL;
72 	return run;
73 }
74