Added extra/crond.service for systemd
[dcron.git] / defs.h
blobb221636ce8559b00f025c7760043db6e5872fe46
2 /*
3 * DEFS.H
5 * Copyright 1994-1998 Matthew Dillon (dillon@backplane.com)
6 * Copyright 2009-2011 James Pryor <profjim@jimpryor.net>
7 * May be distributed under the GNU General Public License
8 */
11 * portability issues
12 * 0. gcc defaults to _BSD_SOURCE and _POSIX_SOURCE
13 * 1. need _POSIX_SOURCE or _XOPEN_SOURCE for getopt, fileno, sigaction
14 * 2. need _XOPEN_SOURCE for strptime
15 * 3. need _BSD_SOURCE for setenv, mk{d,s}temp, [v]snprintf, initgroups, strsep, strdup, setre{u,g}id, gethostname, perror
16 * 4. use concat.c instead of requiring asprintf / _GNU_SOURCE
19 #define _XOPEN_SOURCE 1
20 #define _BSD_SOURCE 1
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <sys/ioctl.h>
25 #include <sys/wait.h>
26 #include <sys/resource.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <errno.h>
30 #include <dirent.h>
31 #include <fcntl.h>
32 #include <pwd.h>
33 #ifndef S_SPLINT_S
34 #include <unistd.h>
35 #endif
36 #include <grp.h>
37 #include <syslog.h>
38 #include <signal.h>
39 #include <getopt.h>
40 #include <err.h>
41 #include <limits.h>
43 #include <time.h>
44 #include <string.h>
45 #include <stdio.h>
47 #define Prototype extern
48 #define arysize(ary) (sizeof(ary)/sizeof((ary)[0]))
50 #ifndef SCRONTABS
51 #define SCRONTABS "/etc/cron.d"
52 #endif
53 #ifndef CRONTABS
54 #define CRONTABS "/var/spool/cron/crontabs"
55 #endif
56 #ifndef CRONSTAMPS
57 #define CRONSTAMPS "/var/spool/cron/cronstamps"
58 #endif
59 #ifndef LOG_IDENT
60 #define LOG_IDENT "crond"
61 #endif
62 #ifndef TIMESTAMP_FMT
63 #define TIMESTAMP_FMT "%b %e %H:%M:%S"
64 #endif
66 #ifndef LOG_LEVEL
67 #define LOG_LEVEL LOG_NOTICE
68 #endif
69 #ifndef CRONSTAMP_FMT
70 #define CRONSTAMP_FMT "%Y-%m-%d %H:%M"
71 #endif
72 #ifndef CRONUPDATE
73 #define CRONUPDATE "cron.update"
74 #endif
75 #ifndef TMPDIR
76 #define TMPDIR "/tmp"
77 #endif
79 #ifndef SENDMAIL
80 #define SENDMAIL "/usr/sbin/sendmail"
81 #endif
82 #ifndef SENDMAIL_ARGS
83 #define SENDMAIL_ARGS "-t", "-oem", "-i"
84 #endif
85 #ifndef PATH_VI
86 #define PATH_VI "/usr/bin/vi" /* location of vi */
87 #endif
89 #ifndef ID_TAG
90 #define ID_TAG "ID="
91 #endif
92 #ifndef WAIT_TAG
93 #define WAIT_TAG "AFTER="
94 #endif
95 #ifndef FREQ_TAG
96 #define FREQ_TAG "FREQ="
97 #endif
99 #define HOURLY_FREQ 60 * 60
100 #define DAILY_FREQ 24 * HOURLY_FREQ
101 #define WEEKLY_FREQ 7 * DAILY_FREQ
102 #define MONTHLY_FREQ 30 * DAILY_FREQ
103 #define YEARLY_FREQ 365 * DAILY_FREQ
105 #define LOGHEADER TIMESTAMP_FMT " %%s " LOG_IDENT ": "
106 #define LOCALE_LOGHEADER "%c %%s " LOG_IDENT ": "
108 /* Limits */
109 #define MAXOPEN 256 /* close fds < this limit */
110 #define MAXLINES 256 /* max lines in non-root crontabs */
111 #define SMALL_BUFFER 256
112 #define RW_BUFFER 1024
113 #define LOG_BUFFER 2048 /* max size of log line */
118 typedef struct CronFile {
119 struct CronFile *cf_Next;
120 struct CronLine *cf_LineBase;
121 char *cf_DPath; /* Directory path to cronfile */
122 char *cf_FileName; /* Name of cronfile */
123 char *cf_UserName; /* username to execute jobs as */
124 int cf_Ready; /* bool: one or more jobs ready */
125 int cf_Running; /* bool: one or more jobs running */
126 int cf_Deleted; /* marked for deletion, ignore */
127 } CronFile;
129 typedef struct CronLine {
130 struct CronLine *cl_Next;
131 char *cl_Shell; /* shell command */
132 char *cl_Description; /* either "<cl_Shell>" or "job <cl_JobName>" */
133 char *cl_JobName; /* job name, if any */
134 char *cl_Timestamp; /* path to timestamp file, if cl_Freq defined */
135 struct CronWaiter *cl_Waiters;
136 struct CronNotifier *cl_Notifs;
137 int cl_Freq; /* 0 (use arrays), minutes, -1 (noauto), -2 (startup) */
138 int cl_Delay; /* defaults to cl_Freq or hourly */
139 time_t cl_LastRan;
140 time_t cl_NotUntil;
141 int cl_Pid; /* running pid, 0, or armed (-1), or waiting (-2) */
142 int cl_MailFlag; /* running pid is for mail */
143 int cl_MailPos; /* 'empty file' size */
144 char cl_Mins[60]; /* 0-59 */
145 char cl_Hrs[24]; /* 0-23 */
146 char cl_Days[32]; /* 1-31 */
147 char cl_Mons[12]; /* 0-11 */
148 char cl_Dow[7]; /* 0-6, beginning sunday */
149 } CronLine;
151 typedef struct CronWaiter {
152 struct CronWaiter *cw_Next;
153 struct CronNotifier *cw_Notifier;
154 struct CronLine *cw_NotifLine;
155 short cw_Flag;
156 int cw_MaxWait;
157 } CronWaiter;
159 typedef struct CronNotifier {
160 struct CronNotifier *cn_Next;
161 struct CronWaiter *cn_Waiter;
162 } CronNotifier;
164 #include "protos.h"