1 /* $NetBSD: job.c,v 1.5 2003/08/13 03:51:15 atatat Exp $ */
3 /* Copyright 1988,1990,1993,1994 by Paul Vixie
6 * Distribute freely, except: don't remove my name from the source or
7 * documentation (don't take credit for my work), mark your changes (don't
8 * get me blamed for your possible bugs), don't alter or remove this
9 * notice. May be sold if buildable source is provided to buyer. No
10 * warrantee of any kind, express or implied, is included with this
11 * software; use at your own risk, responsibility for damages (if any) to
12 * anyone resulting from the use of this software rests entirely with the
15 * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
16 * I'll try to keep a version up to date. I can be reached as follows:
17 * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
20 #include <sys/cdefs.h>
23 # include <sys/time.h>
27 #if !defined(lint) && !defined(LINT)
29 static char rcsid
[] = "Id: job.c,v 1.6 1994/01/15 20:43:43 vixie Exp";
31 __RCSID("$NetBSD: job.c,v 1.5 2003/08/13 03:51:15 atatat Exp $");
47 static job
*jhead
= NULL
, *jtail
= NULL
;
50 static int okay_to_go(job
*);
54 job_add(entry
*e
, user
*u
)
58 /* if already on queue, keep going */
59 for (j
=jhead
; j
; j
=j
->next
)
60 if (j
->e
== e
&& j
->u
== u
) {
65 /* build a job queue element */
66 j
= (job
*)malloc(sizeof(job
));
67 j
->next
= (job
*) NULL
;
72 /* add it to the tail */
73 if (!jhead
) { jhead
=j
; }
74 else { jtail
->next
=j
; }
85 for (j
=jhead
; j
; j
=jn
) {
87 do_command(j
->e
, j
->u
);
89 char *x
= mkprints((u_char
*)j
->e
->cmd
,
91 char *usernm
= env_get("LOGNAME", j
->e
->envp
);
93 log_it(usernm
, getpid(), "CMD (skipped)", x
);
100 jhead
= jtail
= NULL
;
111 if (j
->e
->flags
& WHEN_REBOOT
)
114 within
= env_get("CRON_WITHIN", j
->e
->envp
);
118 /* XXX handle 2m, 4h, etc? */
120 delta
= strtol(within
, &t
, 10);
121 if (errno
== ERANGE
|| *t
!= '\0' || delta
<= 0)
124 return ((j
->t
+ delta
) > time(NULL
));