12311Sjkh/* Copyright 1988,1990,1993,1994 by Paul Vixie 22311Sjkh * All rights reserved 32311Sjkh * 42311Sjkh * Distribute freely, except: don't remove my name from the source or 52311Sjkh * documentation (don't take credit for my work), mark your changes (don't 62311Sjkh * get me blamed for your possible bugs), don't alter or remove this 72311Sjkh * notice. May be sold if buildable source is provided to buyer. No 82311Sjkh * warrantee of any kind, express or implied, is included with this 92311Sjkh * software; use at your own risk, responsibility for damages (if any) to 102311Sjkh * anyone resulting from the use of this software rests entirely with the 112311Sjkh * user. 122311Sjkh * 132311Sjkh * Send bug reports, bug fixes, enhancements, requests, flames, etc., and 142311Sjkh * I'll try to keep a version up to date. I can be reached as follows: 152311Sjkh * Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul 162311Sjkh */ 172311Sjkh 182311Sjkh#if !defined(lint) && !defined(LINT) 1929452Scharnierstatic const char rcsid[] = 2050479Speter "$FreeBSD$"; 212311Sjkh#endif 222311Sjkh 232311Sjkh 242311Sjkh#include "cron.h" 252311Sjkh 262311Sjkh 272311Sjkhtypedef struct _job { 282311Sjkh struct _job *next; 292311Sjkh entry *e; 302311Sjkh user *u; 312311Sjkh} job; 322311Sjkh 332311Sjkh 342311Sjkhstatic job *jhead = NULL, *jtail = NULL; 352311Sjkh 362311Sjkh 372311Sjkhvoid 382311Sjkhjob_add(e, u) 392311Sjkh register entry *e; 402311Sjkh register user *u; 412311Sjkh{ 422311Sjkh register job *j; 432311Sjkh 442311Sjkh /* if already on queue, keep going */ 452311Sjkh for (j=jhead; j; j=j->next) 462311Sjkh if (j->e == e && j->u == u) { return; } 472311Sjkh 482311Sjkh /* build a job queue element */ 4920573Spst if ((j = (job*)malloc(sizeof(job))) == NULL) 5020573Spst return; 512311Sjkh j->next = (job*) NULL; 522311Sjkh j->e = e; 532311Sjkh j->u = u; 542311Sjkh 552311Sjkh /* add it to the tail */ 562311Sjkh if (!jhead) { jhead=j; } 572311Sjkh else { jtail->next=j; } 582311Sjkh jtail = j; 592311Sjkh} 602311Sjkh 612311Sjkh 622311Sjkhint 632311Sjkhjob_runqueue() 642311Sjkh{ 652311Sjkh register job *j, *jn; 662311Sjkh register int run = 0; 672311Sjkh 682311Sjkh for (j=jhead; j; j=jn) { 692311Sjkh do_command(j->e, j->u); 702311Sjkh jn = j->next; 712311Sjkh free(j); 722311Sjkh run++; 732311Sjkh } 742311Sjkh jhead = jtail = NULL; 752311Sjkh return run; 762311Sjkh} 77