Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/cron/cron/job.c
/* Copyright 1988,1990,1993,1994 by Paul Vixie | /* Copyright 1988,1990,1993,1994 by Paul Vixie | ||||
* All rights reserved | * All rights reserved | ||||
*/ | |||||
/* | |||||
* Copyright (c) 1997 by Internet Software Consortium | |||||
* | * | ||||
* Distribute freely, except: don't remove my name from the source or | * Permission to use, copy, modify, and distribute this software for any | ||||
* documentation (don't take credit for my work), mark your changes (don't | * purpose with or without fee is hereby granted, provided that the above | ||||
* get me blamed for your possible bugs), don't alter or remove this | * copyright notice and this permission notice appear in all copies. | ||||
* notice. May be sold if buildable source is provided to buyer. No | |||||
* warrantee of any kind, express or implied, is included with this | |||||
* software; use at your own risk, responsibility for damages (if any) to | |||||
* anyone resulting from the use of this software rests entirely with the | |||||
* user. | |||||
* | * | ||||
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||||
* I'll try to keep a version up to date. I can be reached as follows: | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||||
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||||
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | |||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | |||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | |||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |||||
* SOFTWARE. | |||||
*/ | */ | ||||
#if !defined(lint) && !defined(LINT) | #if !defined(lint) && !defined(LINT) | ||||
static const char rcsid[] = | static const char rcsid[] = "$Id: job.c,v 1.2 1998/08/14 00:32:40 vixie Exp $"; | ||||
"$FreeBSD$"; | |||||
#endif | #endif | ||||
#include "cron.h" | #include "cron.h" | ||||
typedef struct _job { | typedef struct _job { | ||||
struct _job *next; | struct _job *next; | ||||
entry *e; | entry *e; | ||||
user *u; | user *u; | ||||
} job; | } job; | ||||
static job *jhead = NULL, *jtail = NULL; | static job *jhead = NULL, *jtail = NULL; | ||||
void | void | ||||
job_add(entry *e, user *u) | job_add(entry *e, user *u) | ||||
{ | { | ||||
register job *j; | job *j; | ||||
/* if already on queue, keep going */ | /* if already on queue, keep going */ | ||||
for (j=jhead; j; j=j->next) | for (j = jhead; j != NULL; j = j->next) | ||||
if (j->e == e && j->u == u) { return; } | if (j->e == e && j->u == u) | ||||
return; | |||||
/* build a job queue element */ | /* build a job queue element */ | ||||
if ((j = (job*)malloc(sizeof(job))) == NULL) | if ((j = (job*)malloc(sizeof(job))) == NULL) | ||||
return; | return; | ||||
j->next = (job*) NULL; | j->next = (job*) NULL; | ||||
j->e = e; | j->e = e; | ||||
j->u = u; | j->u = u; | ||||
/* add it to the tail */ | /* add it to the tail */ | ||||
if (!jhead) { jhead=j; } | if (jhead == NULL) | ||||
else { jtail->next=j; } | jhead = j; | ||||
else | |||||
jtail->next = j; | |||||
jtail = j; | jtail = j; | ||||
} | } | ||||
int | int | ||||
job_runqueue(void) | job_runqueue(void) | ||||
{ | { | ||||
register job *j, *jn; | job *j, *jn; | ||||
register int run = 0; | int run = 0; | ||||
for (j=jhead; j; j=jn) { | for (j = jhead; j; j = jn) { | ||||
do_command(j->e, j->u); | do_command(j->e, j->u); | ||||
jn = j->next; | jn = j->next; | ||||
free(j); | free(j); | ||||
run++; | run++; | ||||
} | } | ||||
jhead = jtail = NULL; | jhead = jtail = NULL; | ||||
return run; | return (run); | ||||
} | } |