xref: /minix3/minix/commands/cron/tab.h (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1 /*	tab.h - in-core crontab data			Author: Kees J. Bot
2  *								7 Dec 1996
3  */
4 #ifndef TAB__H
5 #define TAB__H
6 
7 #include <sys/types.h>
8 #include <limits.h>
9 
10 struct crontab;
11 
12 typedef unsigned char bitmap_t[8];
13 
14 typedef struct cronjob {	/* One entry in a crontab file */
15 	struct cronjob	*next;
16 	struct crontab	*tab;		/* Associated table file. */
17 	bitmap_t	min;		/* Minute (0-59) */
18 	bitmap_t	hour;		/* Hour (0-23) */
19 	bitmap_t	mday;		/* Day of the month (1-31) */
20 	bitmap_t	mon;		/* Month (1-12) */
21 	bitmap_t	wday;		/* Weekday (0-7 with 0 = 7 = Sunday) */
22 	char		*user;		/* User to run it as (nil = root) */
23 	char		*cmd;		/* Command to run */
24 	time_t		rtime;		/* When next to run */
25 	char		do_mday;	/* True iff mon or mday is not '*' */
26 	char		do_wday;	/* True iff wday is not '*' */
27 	char		late;		/* True iff the job is late */
28 	char		atjob;		/* True iff it is an AT job */
29 	pid_t		pid;		/* Process-id of job if nonzero */
30 } cronjob_t;
31 
32 typedef struct crontab {
33 	struct crontab	*next;
34 	char		*file;		/* Crontab name */
35 	char		*user;		/* Owner if non-null */
36 	time_t		mtime;		/* Last modified time */
37 	cronjob_t	*jobs;		/* List of jobs in the file */
38 	char		*data;		/* File data */
39 	int		current;	/* True if current, i.e. file exists */
40 } crontab_t;
41 
42 crontab_t *crontabs;		/* All crontabs. */
43 
44 /* A time as far in the future as possible. */
45 #define NEVER		((time_t) ((time_t) -1 < 0 ? LONG_MAX : ULONG_MAX))
46 
47 /* Don't trust crontabs bigger than this: */
48 #define TAB_MAX		((sizeof(int) == 2 ? 8 : 128) * 1024)
49 
50 /* Pid if no process running, or a pid value you'll never see. */
51 #define IDLE_PID	((pid_t) 0)
52 #define NO_PID		((pid_t) -1)
53 
54 /* Bitmap operations. */
55 #define bit_set(map, n)		((void) ((map)[(n) >> 3] |= (1 << ((n) & 7))))
56 #define bit_clr(map, n)		((void) ((map)[(n) >> 3] &= ~(1 << ((n) & 7))))
57 #define bit_isset(map, n)	(!!((map)[(n) >> 3] & (1 << ((n) & 7))))
58 
59 /* Functions. */
60 void tab_parse(char *file, char *user);
61 void tab_find_atjob(char *atdir);
62 void tab_purge(void);
63 void tab_reap_job(pid_t pid);
64 void tab_reschedule(cronjob_t *job);
65 cronjob_t *tab_nextjob(void);
66 void tab_print(FILE *fp);
67 
68 #endif /* TAB__H */
69 
70 /*
71  * $PchId: tab.h,v 1.3 2000/07/17 07:57:27 philip Exp $
72  */
73