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>
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>
119 #include "bitstring.h" /* bit arrays */
120 #include "option.h" /* manage fcrontab's options */
122 /* you should not change this (nor need to do it) */
126 /* options for local functions */
131 #define seteuid(arg) setresuid(-1,(arg),-1)
135 #define setegid(arg) setresgid(-1,(arg),-1)
138 #define Alloc(PTR, TYPE) \
139 if( (PTR = calloc(1, sizeof(TYPE))) == NULL ) \
140 die_e("Could not calloc.");
142 #define Set(VAR, VALUE) \
145 VAR = strdup2(VALUE); \
154 #define Skip_blanks(PTR) \
155 while((*(PTR) == ' ') || (*(PTR) == '\t')) \
158 #define Overwrite(x) \
160 register char *__xx__; \
166 #define debug if(debug_opt) Debug
168 typedef struct env_t {
169 char *e_val; /* env value */
170 struct env_t *e_next;
173 typedef struct cf_t {
174 struct cf_t *cf_next;
175 struct cl_t *cf_line_base;
176 char *cf_user; /* user-name */
177 struct env_t *cf_env_base; /* list of all env variables to set */
178 int cf_running; /* number of jobs running */
179 signed char cf_tzdiff; /* time diff between system and local hour */
181 security_context_t cf_user_context;
182 security_context_t cf_file_context;
187 #define OPTION_SIZE 4
189 /* warning : do not change the order of the members of this structure
190 * because some tests made are dependent to that order */
191 /* warning : if you change a field type, you may have to also make some changes
192 * in the save/load binary fcrontab functions */
193 typedef struct cl_t {
194 struct cl_t *cl_next;
195 struct cf_t *cl_file; /* the file in which the line is */
196 char *cl_shell; /* shell command */
197 char *cl_runas; /* determine permissions of the job */
198 char *cl_mailto; /* mail output to cl_mailto */
199 char *cl_tz; /* time zone of the line */
200 long int cl_id; /* line's unique id number */
201 time_t cl_until; /* timeout of the wait for a lavg value */
202 time_t cl_first; /* initial delay preserved for volatile entries */
203 time_t cl_nextexe; /* time and date of the next execution */
204 long int cl_timefreq; /* Run every n seconds */
205 unsigned short cl_remain; /* remaining until next execution */
206 unsigned short cl_runfreq; /* Run once every n matches(=1 for %-lines)*/
207 unsigned char cl_option[OPTION_SIZE]; /* line's option (see option.h) */
208 unsigned char cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins) */
209 unsigned char cl_numexe; /* entries in queues & running processes */
210 char cl_nice; /* nice value to control priority */
211 /* see bitstring(3) man page for more details */
212 bitstr_t bit_decl(cl_mins, 60); /* 0-59 */
213 bitstr_t bit_decl(cl_hrs, 24); /* 0-23 */
214 bitstr_t bit_decl(cl_days, 32); /* 1-31 */
215 bitstr_t bit_decl(cl_mons, 12); /* 0-11 */
216 bitstr_t bit_decl(cl_dow, 8); /* 0-7, 0 and 7 are both Sunday */
219 typedef struct job_t {
221 struct job_t *j_next;
224 typedef struct lavg_t {
226 time_t l_until; /* the timeout of the wait for load averages */
229 typedef struct exe_t {
231 pid_t e_ctrl_pid; /* pid of the fcron process controling the job */
232 pid_t e_job_pid; /* pid of the job itself */
236 #if SIZEOF_TIME_T == SIZEOF_SHORT_INT
237 #define ATTR_SIZE_TIMET "h"
238 #define CAST_TIMET_PTR (short int *)
239 #elif SIZEOF_TIME_T == SIZEOF_INT
240 #define ATTR_SIZE_TIMET ""
241 #define CAST_TIMET_PTR (int *)
242 #elif SIZEOF_TIME_T == SIZEOF_LONG_INT
243 #define ATTR_SIZE_TIMET "l"
244 #define CAST_TIMET_PTR (long int *)
245 #elif SIZEOF_TIME_T == SIZEOF_LONG_LONG_INT
246 #define ATTR_SIZE_TIMET "ll"
247 #define CAST_TIMET_PTR (long long int *)
249 #error "SIZEOF_TIME_T does not correspond with a known format."
252 #if SIZEOF_PID_T == SIZEOF_SHORT_INT
253 #define ATTR_SIZE_PIDT "h"
254 #define CAST_PIDT_PTR (short int *)
255 #elif SIZEOF_PID_T == SIZEOF_INT
256 #define ATTR_SIZE_PIDT ""
257 #define CAST_PIDT_PTR (int *)
258 #elif SIZEOF_PID_T == SIZEOF_LONG_INT
259 #define ATTR_SIZE_PIDT "l"
260 #define CAST_PIDT_PTR (long int *)
261 #elif SIZEOF_PID_T == SIZEOF_LONG_LONG_INT
262 #define ATTR_SIZE_PIDT "ll"
263 #define CAST_PIDT_PTR (long long int *)
265 #error "SIZEOF_PID_T does not correspond with a known format."
269 /* local header files : we include here the headers which may use some types defined
272 /* constants for fcrontabs needed to load and save the fcrontabs to disk */
276 /* functions used by fcrontab, fcrondyn, and fcron */
280 #endif /* __GLOBAL_H__ */