2 * FCRON - periodic command scheduler
4 * Copyright 2000-2009 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>
80 #ifdef HAVE_SYS_FILE_H
85 #include <sys/types.h>
87 #ifdef HAVE_SYS_WAIT_H
95 #ifdef TIME_WITH_SYS_TIME
101 #ifdef HAVE_TERMIOS_H
111 #elif HAVE_SYS_FCNTL_H
112 #include <sys/fcntl.h>
121 #ifdef HAVE_SYS_CRED_H
122 #include <sys/cred.h>
124 #ifdef HAVE_SYS_UCRED_H
125 #include <sys/ucred.h>
132 #include "bitstring.h" /* bit arrays */
133 #include "option.h" /* manage fcrontab's options */
134 #include "env_list.h" /* manage fcrontab's environment variable lists */
136 /* you should not change this (nor need to do it) */
140 /* options for local functions */
145 #define seteuid(arg) setresuid(-1,(arg),-1)
149 #define setegid(arg) setresgid(-1,(arg),-1)
152 #define Alloc(PTR, TYPE) \
153 if( (PTR = calloc(1, sizeof(TYPE))) == NULL ) \
154 die_e("Could not calloc.");
156 #define Set(VAR, VALUE) \
159 VAR = strdup2(VALUE); \
168 #define Skip_blanks(PTR) \
169 while((*(PTR) == ' ') || (*(PTR) == '\t')) \
172 #define Overwrite(x) \
174 register char *__xx__; \
180 #define debug if(debug_opt) Debug
182 typedef struct cf_t {
183 struct cf_t *cf_next;
184 struct cl_t *cf_line_base;
185 char *cf_user; /* user-name */
186 env_list_t *cf_env_list; /* list of all parsed env var */
187 int cf_running; /* number of jobs running */
188 signed char cf_tzdiff; /* time diff between system and local hour */
190 security_context_t cf_user_context;
191 security_context_t cf_file_context;
196 #define OPTION_SIZE 4
198 /* warning : do not change the order of the members of this structure
199 * because some tests made are dependent to that order */
200 /* warning : if you change a field type, you may have to also make some changes
201 * in the save/load binary fcrontab functions */
202 typedef struct cl_t {
203 struct cl_t *cl_next;
204 struct cf_t *cl_file; /* the file in which the line is */
205 char *cl_shell; /* shell command */
206 char *cl_runas; /* determine permissions of the job */
207 char *cl_mailto; /* mail output to cl_mailto */
208 char *cl_tz; /* time zone of the line */
209 long int cl_id; /* line's unique id number */
210 time_t cl_until; /* timeout of the wait for a lavg value */
211 time_t cl_first; /* initial delay preserved for volatile entries */
212 time_t cl_nextexe; /* time and date of the next execution */
213 long int cl_timefreq; /* Run every n seconds */
214 unsigned short cl_remain; /* remaining until next execution */
215 unsigned short cl_runfreq; /* Run once every n matches(=1 for %-lines)*/
216 unsigned char cl_option[OPTION_SIZE]; /* line's option (see option.h) */
217 unsigned char cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins) */
218 unsigned char cl_numexe; /* entries in queues & running processes */
219 char cl_nice; /* nice value to control priority */
220 unsigned char cl_jitter; /* run randomly late up to jitter seconds */
221 /* see bitstring(3) man page for more details */
222 bitstr_t bit_decl(cl_mins, 60); /* 0-59 */
223 bitstr_t bit_decl(cl_hrs, 24); /* 0-23 */
224 bitstr_t bit_decl(cl_days, 32); /* 1-31 */
225 bitstr_t bit_decl(cl_mons, 12); /* 0-11 */
226 bitstr_t bit_decl(cl_dow, 8); /* 0-7, 0 and 7 are both Sunday */
229 typedef struct job_t {
231 struct job_t *j_next;
235 #if SIZEOF_TIME_T == SIZEOF_SHORT_INT
236 #define ATTR_SIZE_TIMET "h"
237 #define CAST_TIMET_PTR (short int *)
238 #elif SIZEOF_TIME_T == SIZEOF_INT
239 #define ATTR_SIZE_TIMET ""
240 #define CAST_TIMET_PTR (int *)
241 #elif SIZEOF_TIME_T == SIZEOF_LONG_INT
242 #define ATTR_SIZE_TIMET "l"
243 #define CAST_TIMET_PTR (long int *)
244 #elif SIZEOF_TIME_T == SIZEOF_LONG_LONG_INT
245 #define ATTR_SIZE_TIMET "ll"
246 #define CAST_TIMET_PTR (long long int *)
248 #error "SIZEOF_TIME_T does not correspond with a known format."
251 #if SIZEOF_PID_T == SIZEOF_SHORT_INT
252 #define ATTR_SIZE_PIDT "h"
253 #define CAST_PIDT_PTR (short int *)
254 #elif SIZEOF_PID_T == SIZEOF_INT
255 #define ATTR_SIZE_PIDT ""
256 #define CAST_PIDT_PTR (int *)
257 #elif SIZEOF_PID_T == SIZEOF_LONG_INT
258 #define ATTR_SIZE_PIDT "l"
259 #define CAST_PIDT_PTR (long int *)
260 #elif SIZEOF_PID_T == SIZEOF_LONG_LONG_INT
261 #define ATTR_SIZE_PIDT "ll"
262 #define CAST_PIDT_PTR (long long int *)
264 #error "SIZEOF_PID_T does not correspond with a known format."
268 /* local header files : we include here the headers which may use some types defined
271 /* constants for fcrontabs needed to load and save the fcrontabs to disk */
275 /* functions used by fcrontab, fcrondyn, and fcron */
279 #endif /* __GLOBAL_H__ */