1 /* $NetBSD: cron.h,v 1.4 2005/03/16 02:53:55 xtraeme 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 /* cron.h - header for vixie's cron
22 * Id: cron.h,v 2.10 1994/01/15 20:43:43 vixie Exp
24 * vix 14nov88 [rest of log is in RCS]
25 * vix 14jan87 [0 or 7 can be sunday; thanks, mwm@berkeley]
26 * vix 30dec86 [written]
29 /* reorder these #include's at your peril */
31 #include <sys/types.h>
32 #include <sys/param.h>
37 #include <bitstring.h>
41 #include "pathnames.h"
45 /* these are really immutable, and are
46 * defined for symbolic convenience only
47 * TRUE, FALSE, and ERR must be distinct
52 /* system calls return this on success */
54 /* or this on error */
57 /* turn this on to get '-x' code */
59 #define DEBUGGING FALSE
62 #define READ_PIPE 0 /* which end of a pipe pair do you read? */
63 #define WRITE_PIPE 1 /* or write to? */
64 #define STDIN 0 /* what is stdin's file descriptor? */
65 #define STDOUT 1 /* stdout's? */
66 #define STDERR 2 /* stderr's? */
67 #define ERROR_EXIT 1 /* exit() with this will scare the shell */
68 #define OK_EXIT 0 /* exit() with this is considered 'normal' */
69 #define MAX_FNAME 100 /* max length of internally generated fn */
70 #define MAX_COMMAND 1000 /* max length of internally generated cmd */
71 #define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */
72 #define MAX_TEMPSTR 100 /* obvious */
73 #define MAX_UNAME 20 /* max length of username, should be overkill */
74 #define ROOT_UID 0 /* don't change this, it really must be root */
75 #define ROOT_USER "root" /* ditto */
77 /* NOTE: these correspond to DebugFlagNames,
80 #define DEXT 0x0001 /* extend flag for other debug masks */
81 #define DSCH 0x0002 /* scheduling debug mask */
82 #define DPROC 0x0004 /* process control debug mask */
83 #define DPARS 0x0008 /* parsing debug mask */
84 #define DLOAD 0x0010 /* database loading debug mask */
85 #define DMISC 0x0020 /* misc debug mask */
86 #define DTEST 0x0040 /* test mode: don't execute any commands */
87 #define DBIT 0x0080 /* bit twiddling shown (long) */
89 #define CRON_TAB(u) "%s/%s", SPOOL_DIR, u
91 #define PPC_NULL ((const char * const *)NULL)
93 #ifndef MAXHOSTNAMELEN
94 #define MAXHOSTNAMELEN 64
97 #define Skip_Blanks(c, f) \
98 while (c == '\t' || c == ' ') \
101 #define Skip_Nonblanks(c, f) \
102 while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \
105 #define Skip_Line(c, f) \
106 do {c = get_char(f);} while (c != '\n' && c != EOF);
109 # define Debug(mask, message) \
110 if ( (DebugFlags & (mask) ) == (mask) ) \
112 #else /* !DEBUGGING */
113 # define Debug(mask, message) \
115 #endif /* DEBUGGING */
117 #define MkLower(ch) (isupper(ch) ? tolower(ch) : ch)
118 #define MkUpper(ch) (islower(ch) ? toupper(ch) : ch)
119 #define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \
123 #define FIRST_MINUTE 0
124 #define LAST_MINUTE 59
125 #define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1)
129 #define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1)
133 #define DOM_COUNT (LAST_DOM - FIRST_DOM + 1)
135 #define FIRST_MONTH 1
136 #define LAST_MONTH 12
137 #define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1)
139 /* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */
142 #define DOW_COUNT (LAST_DOW - FIRST_DOW + 1)
144 /* each user's crontab will be held as a list of
145 * the following structure.
147 * These are the cron commands.
150 typedef struct _entry
{
156 bitstr_t
bit_decl(minute
, MINUTE_COUNT
);
157 bitstr_t
bit_decl(hour
, HOUR_COUNT
);
158 bitstr_t
bit_decl(dom
, DOM_COUNT
);
159 bitstr_t
bit_decl(month
, MONTH_COUNT
);
160 bitstr_t
bit_decl(dow
, DOW_COUNT
);
162 #define DOM_STAR 0x01
163 #define DOW_STAR 0x02
164 #define WHEN_REBOOT 0x04
167 /* the crontab database will be a list of the
168 * following structure, one element per user
169 * plus one for the system.
171 * These are the crontabs.
174 typedef struct _user
{
175 struct _user
*next
, *prev
; /* links */
177 time_t mtime
; /* last modtime of crontab */
178 entry
*crontab
; /* this person's crontab */
181 typedef struct _cron_db
{
182 user
*head
, *tail
; /* links */
183 time_t mtime
; /* last modtime on spooldir */
187 void set_cron_uid(void),
189 load_database(cron_db
*),
192 job_add(entry
*, user
*),
193 do_command(entry
*, user
*),
194 link_user(cron_db
*, user
*),
195 unlink_user(cron_db
*, user
*),
198 unget_char(int, FILE *),
200 acquire_daemonlock(int),
201 skip_comments(FILE *),
202 log_it(const char *, int, const char *, const char *),
205 int job_runqueue(void),
206 set_debug_flags(char *),
208 get_string(char *, int, FILE *, const char *),
210 load_env(char *, FILE *),
212 strcmp_until(const char *, const char *, int),
216 char *env_get(const char *, char **),
218 *mkprints(unsigned char *, unsigned int),
219 *first_word(char *, const char *),
222 **env_set(char **, char *);
224 user
*load_user(int, struct passwd
*, const char *),
225 *find_user(cron_db
*, const char *);
227 entry
*load_entry(FILE *, void (*)(const char *),
228 struct passwd
*, char **);
230 FILE *cron_popen(char *, const char *);
233 /* in the C tradition, we only create
234 * variables for the main program, just
235 * extern them elsewhere.
239 # if !defined(LINT) && !defined(lint)
240 const char * const copyright
[] = {
241 "@(#) Copyright 1988,1989,1990,1993,1994 by Paul Vixie",
242 "@(#) All rights reserved"
246 const char * const MonthNames
[] = {
247 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
248 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
252 const char * const DowNames
[] = {
253 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
263 const char * const DebugFlagNames
[] = { /* sync with #defines */
264 "ext", "sch", "proc", "pars", "load", "misc", "test", "bit",
265 NULL
/* NULL must be last element */
267 # endif /* DEBUGGING */
268 #else /*MAIN_PROGRAM*/
271 * const MonthNames
[],
273 extern char *ProgramName
;
274 extern int LineNumber
;
275 extern time_t TargetTime
;
277 extern int DebugFlags
;
279 * const DebugFlagNames
[];
280 # endif /* DEBUGGING */
281 #endif /*MAIN_PROGRAM*/