2 * FCRON - periodic command scheduler
4 * Copyright 2000-2010 Thibault Godouet <fcron@free.fr>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * The GNU General Public License can also be found in the file
21 * `LICENSE' that comes with the fcron source distribution.
24 /* $Id: global.h,v 1.51 2007-06-24 22:01:49 thib Exp $ */
28 WARNING : this file should not be modified.
29 Compilation's options are in config.h
35 /* config.h must be included before every other includes
36 * (contains the compilation options) */
48 #include <get_context_list.h>
49 #include <selinux/flask.h>
50 #include <selinux/av_permissions.h>
83 #ifdef HAVE_SYS_FILE_H
88 #include <sys/types.h>
90 #ifdef HAVE_SYS_WAIT_H
98 #ifdef TIME_WITH_SYS_TIME
100 #elif HAVE_SYS_TIME_H
101 #include <sys/time.h>
104 #ifdef HAVE_TERMIOS_H
114 #elif HAVE_SYS_FCNTL_H
115 #include <sys/fcntl.h>
124 #ifdef HAVE_SYS_CRED_H
125 #include <sys/cred.h>
127 #ifdef HAVE_SYS_UCRED_H
128 #include <sys/ucred.h>
135 #include "bitstring.h" /* bit arrays */
136 #include "option.h" /* manage fcrontab's options */
137 #include "env_list.h" /* manage fcrontab's environment variable lists */
139 /* you should not change this (nor need to do it) */
143 /* options for local functions */
148 #define seteuid(arg) setresuid(-1,(arg),-1)
152 #define setegid(arg) setresgid(-1,(arg),-1)
155 #define Alloc(PTR, TYPE) \
156 if( (PTR = calloc(1, sizeof(TYPE))) == NULL ) \
157 die_e("Could not calloc.");
159 #define Set(VAR, VALUE) \
162 VAR = strdup2(VALUE); \
165 #define Skip_blanks(PTR) \
166 while((*(PTR) == ' ') || (*(PTR) == '\t')) \
169 #define Overwrite(x) \
171 register char *__xx__; \
177 #define debug if(debug_opt) Debug
179 typedef struct cf_t {
180 struct cf_t *cf_next;
181 struct cl_t *cf_line_base;
182 char *cf_user; /* user-name */
183 env_list_t *cf_env_list; /* list of all parsed env var */
184 int cf_running; /* number of jobs running */
185 signed char cf_tzdiff; /* time diff between system and local hour */
187 security_context_t cf_user_context;
188 security_context_t cf_file_context;
193 #define OPTION_SIZE 4 /* number of bytes to hold the cl_option bit array */
195 /* warning : do not change the order of the members of this structure
196 * because some tests made are dependent to that order */
197 /* warning : if you change a field type, you may have to also make some changes
198 * in the save/load binary fcrontab functions */
199 typedef struct cl_t {
200 struct cl_t *cl_next;
201 struct cf_t *cl_file; /* the file in which the line is */
202 char *cl_shell; /* shell command */
203 char *cl_runas; /* determine permissions of the job */
204 char *cl_mailto; /* mail output to cl_mailto */
205 char *cl_tz; /* time zone of the line */
206 unsigned long cl_id; /* line's unique id number */
207 time_t cl_until; /* timeout of the wait for a lavg value */
208 time_t cl_first; /* initial delay preserved for volatile entries */
209 time_t cl_nextexe; /* time and date of the next execution */
210 long int cl_timefreq; /* Run every n seconds */
211 unsigned short cl_remain; /* remaining until next execution */
212 unsigned short cl_runfreq; /* Run once every n matches(=1 for %-lines)*/
213 unsigned char cl_option[OPTION_SIZE]; /* line's option (see option.h) */
214 unsigned char cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins) */
215 unsigned char cl_numexe; /* entries in queues & running processes */
216 char cl_nice; /* nice value to control priority */
217 unsigned char cl_jitter; /* run randomly late up to jitter seconds */
218 /* see bitstring(3) man page for more details */
219 bitstr_t bit_decl(cl_mins, 60); /* 0-59 */
220 bitstr_t bit_decl(cl_hrs, 24); /* 0-23 */
221 bitstr_t bit_decl(cl_days, 32); /* 1-31 */
222 bitstr_t bit_decl(cl_mons, 12); /* 0-11 */
223 bitstr_t bit_decl(cl_dow, 8); /* 0-7, 0 and 7 are both Sunday */
226 typedef struct job_t {
228 struct job_t *j_next;
232 #if SIZEOF_TIME_T == SIZEOF_SHORT_INT
233 #define ATTR_SIZE_TIMET "h"
234 #define CAST_TIMET_PTR (short int *)
235 #elif SIZEOF_TIME_T == SIZEOF_INT
236 #define ATTR_SIZE_TIMET ""
237 #define CAST_TIMET_PTR (int *)
238 #elif SIZEOF_TIME_T == SIZEOF_LONG_INT
239 #define ATTR_SIZE_TIMET "l"
240 #define CAST_TIMET_PTR (long int *)
241 #elif SIZEOF_TIME_T == SIZEOF_LONG_LONG_INT
242 #define ATTR_SIZE_TIMET "ll"
243 #define CAST_TIMET_PTR (long long int *)
245 #error "SIZEOF_TIME_T does not correspond with a known format."
248 #if SIZEOF_PID_T == SIZEOF_SHORT_INT
249 #define ATTR_SIZE_PIDT "h"
250 #define CAST_PIDT_PTR (short int *)
251 #elif SIZEOF_PID_T == SIZEOF_INT
252 #define ATTR_SIZE_PIDT ""
253 #define CAST_PIDT_PTR (int *)
254 #elif SIZEOF_PID_T == SIZEOF_LONG_INT
255 #define ATTR_SIZE_PIDT "l"
256 #define CAST_PIDT_PTR (long int *)
257 #elif SIZEOF_PID_T == SIZEOF_LONG_LONG_INT
258 #define ATTR_SIZE_PIDT "ll"
259 #define CAST_PIDT_PTR (long long int *)
261 #error "SIZEOF_PID_T does not correspond with a known format."
265 /* local header files : we include here the headers which may use some types defined
268 /* constants for fcrontabs needed to load and save the fcrontabs to disk */
272 /* functions used by fcrontab, fcrondyn, and fcron */
276 #endif /* __GLOBAL_H__ */