2 * FCRON - periodic command scheduler
4 * Copyright 2000-2012 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.
25 /* This has been inspired from bitstring(3) : here is the original copyright :
29 * Copyright (c) 1989 The Regents of the University of California.
30 * All rights reserved.
32 * This code is derived from software contributed to Berkeley by
35 * Redistribution and use in source and binary forms are permitted
36 * provided that the above copyright notice and this paragraph are
37 * duplicated in all such forms and that any documentation,
38 * advertising materials, and other materials related to such
39 * distribution and use acknowledge that the software was developed
40 * by the University of California, Berkeley. The name of the
41 * University may not be used to endorse or promote products derived
42 * from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
44 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
45 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
50 /* read and set options of a line */
52 /* WARNING : do not change any option number, nor remove any option, nor change
53 * the meaning of a value (i.e. bit set to 1 -> true).
54 * It can lead to errors with fcrontabs already saved to disk
55 * or loaded in memory.
58 /* WARNING : if you add some options, make sure that OPTION_SIZE is big
59 * enough in global.h */
66 0 is this job based on time and date or system up time ?
67 1 is this job based on system load average ?
68 2 perform a logic OR or a logic AND between load averages ?
69 3 perform a logic OR or a logic AND between week day and month day ?
70 4 should we run this job at fcron startup if it should have been
71 executed during system down?
72 5 should this job be run serially ?
73 6 should this job be run serially only once (for bootrun) ?
74 7 does the output have to be mailed to user ?
75 8 does the output (even if zero-length) must be mailed to user ?
76 9 if time of execution is exceeded, exec the lavg job or not ?
77 10 can this job be executed several times simultaneously
78 11 can this job be put several times in the serial queue simultaneously
79 12 can this job be put several times in the lavg queue simultaneously
80 13 should mins field be ignored in goto_non_matching() ?
81 14 should hrs field be ignored in goto_non_matching() ?
82 15 should days field be ignored in goto_non_matching() ?
83 16 should mons field be ignored in goto_non_matching() ?
84 17 should dow field be ignored in goto_non_matching() ?
85 18 First freq is the freq (*ly) or the first field to take into account ?
86 19 Freq (ie daily) is from middle to middle of period (ie nightly) ?
87 20 Should we remove a %-job from lavg queue if the interval is exceeded ?
88 21 Should user be mailed if a %-job has not run during a period ?
89 22 Should fcron log everything about this job or just errors ?
90 23 Should this job be run asap, or randomly in its allowed interval of execution ?
91 24 Should first value be applied at each fcron startup, or before line first exe ?
92 25 if fcron is running in foreground, print jobs output to stderr/stdout or mail ?
93 26 should the output of the job be emailed to the user only non-zero exit status ?
94 27 rebootreset: if set then apply option first at each system startup
95 28 runatreboot: if set then run the job at each system startup
96 29 runonce: if set then run the job only once
97 30 hasrun: set if the job has been run at least once
104 /* we need to include this to get some default values */
107 /* internal macros */
109 #define _bit_byte(bit) \
112 #define _bit_set(opt, bit) \
113 ((opt)[_bit_byte(bit)] |= (1 << ((bit)&0x7)))
115 #define _bit_test(opt, bit) \
116 ((opt)[_bit_byte(bit)] & (1 << ((bit)&0x7)))
118 #define _bit_clear(opt, bit) \
119 ((opt)[_bit_byte(bit)] &= ~(1 << ((bit)&0x7)))
122 /* external macros */
124 /* default value generally corresponds to a bit value of 0 : if you want to
125 * change the default value of an option, do it by modifying the following
126 * macro (set to 1 the needed bits) */
127 #define set_default_opt(opt) \
129 if ( SERIAL_ONCE >= 1 ) clear_serial_sev(opt); \
130 if ( LAVG_ONCE == 0 ) set_lavg_sev(opt); \
135 bit 0 : set to 1 : line is based on system up time
136 set to 0 : line is based on time and date
138 #define is_freq(opt) \
141 ( ! _bit_test(opt, 0))
142 #define set_freq(opt) \
144 #define set_td(opt) \
149 bit 1 : set to 1 : line based on system load average
150 set to 0 : line doesn't take care of load average
152 #define is_lavg(opt) \
154 #define set_lavg(opt) \
156 #define clear_lavg(opt) \
161 bit 2 : set to 1 : perform a logic OR between load averages
162 set to 0 : perform a logic AND between load averages
164 #define is_lor(opt) \
166 #define is_land(opt) \
167 ( ! _bit_test(opt, 2))
168 #define set_lor(opt) \
170 #define set_land(opt) \
174 bit 3 : set to 1 : perform a logic OR between week day and month day
175 set to 0 : perform a logic AND between week day and month day
177 #define is_dayor(opt) \
179 #define is_dayand(opt) \
180 ( ! _bit_test(opt, 3))
181 #define set_dayor(opt) \
183 #define set_dayand(opt) \
188 bit 4 : set to 1 : run this line at fcron's startup if it should have been
189 executed during system down
190 set to 0 : do not run it at fcron's startup
192 #define is_bootrun(opt) \
194 #define set_bootrun(opt) \
196 #define clear_bootrun(opt) \
201 bit 5 : set to 1 : run this line serially
202 set to 0 : do not run it serially
204 #define is_serial(opt) \
206 #define set_serial(opt) \
208 #define clear_serial(opt) \
213 bit 6 : set to 1 : job is being serialized once
214 set to 0 : job is not being serialized once
216 #define is_serial_once(opt) \
218 #define set_serial_once(opt) \
220 #define clear_serial_once(opt) \
225 bit 7 : set to 1 : do not mail output
226 set to 0 : mail output to user
228 #define is_mail(opt) \
229 ( ! _bit_test(opt, 7))
230 #define set_mail(opt) \
232 #define clear_mail(opt) \
237 bit 8 : set to 1 : mail output even if it is zero-length to user
238 set to 0 : mail output only if it is non-zero length
240 #define is_mailzerolength(opt) \
242 #define set_mailzerolength(opt) \
244 #define clear_mailzerolength(opt) \
249 bit 9 : set to 1 : exec the job now if time of execution is exceeded
250 set to 0 : do not exec the job if time of execution is exceeded
252 #define is_run_if_late(opt) \
254 #define set_run_if_late(opt) \
256 #define clear_run_if_late(opt) \
261 bit 10 : set to 1 : line can be executed several times simultaneously
262 set to 0 : line can only be executed once simultaneously
264 #define is_exe_sev(opt) \
266 #define set_exe_sev(opt) \
268 #define clear_exe_sev(opt) \
269 (_bit_clear(opt, 10))
273 bit 11 : set to 1 : can only be put once in serial queue simultaneously
274 set to 0 : can be put several times in serial queue simultaneously
276 #define is_serial_sev(opt) \
277 ( ! _bit_test(opt, 11))
278 #define set_serial_sev(opt) \
279 (_bit_clear(opt, 11))
280 #define clear_serial_sev(opt) \
285 bit 12 : set to 1 : can only be put once in lavg queue simultaneously
286 set to 0 : can be put several times in lavg queue simultaneously
288 #define is_lavg_sev(opt) \
290 #define set_lavg_sev(opt) \
292 #define clear_lavg_sev(opt) \
293 (_bit_clear(opt, 12))
297 bit 13 : set to 1 : mins field is the limit
298 set to 0 : mins field is not the limit
300 #define is_freq_mins(opt) \
302 #define set_freq_mins(opt) \
304 #define clear_freq_mins(opt) \
305 (_bit_clear(opt, 13))
309 bit 14 : set to 1 : hrs field is the limit
310 set to 0 : hrs field is not the limit
312 #define is_freq_hrs(opt) \
314 #define set_freq_hrs(opt) \
316 #define clear_freq_hrs(opt) \
317 (_bit_clear(opt, 14))
321 bit 15 : set to 1 : days field is the limit
322 set to 0 : days field is not the limit
324 #define is_freq_days(opt) \
326 #define set_freq_days(opt) \
328 #define clear_freq_days(opt) \
329 (_bit_clear(opt, 15))
333 bit 16 : set to 1 : mons field is the limit
334 set to 0 : mons field is not the limit
336 #define is_freq_mons(opt) \
338 #define set_freq_mons(opt) \
340 #define clear_freq_mons(opt) \
341 (_bit_clear(opt, 16))
345 bit 17 : set to 1 : dow field is the limit
346 set to 0 : dow field is not the limit
348 #define is_freq_dow(opt) \
350 #define set_freq_dow(opt) \
352 #define clear_freq_dow(opt) \
353 (_bit_clear(opt, 17))
357 bit 18 : set to 1 : limit field is freq to run the line (once a hour, etc)
358 set to 0 : run once per interval of the limit field
360 #define is_freq_periodically(opt) \
362 #define set_freq_periodically(opt) \
364 #define clear_freq_periodically(opt) \
365 (_bit_clear(opt, 18))
369 bit 19 : set to 1 : run once from mid-period to mid-period (i.e. nightly)
370 set to 0 : run once from begin to the end of period (i.e. daily)
372 #define is_freq_mid(opt) \
374 #define set_freq_mid(opt) \
376 #define clear_freq_mid(opt) \
377 (_bit_clear(opt, 19))
381 bit 20 : set to 1 : let the job in the %-queue if interval is exceeded
382 set to 0 : remove %-job from lavg queue if interval is exceeded
384 #define is_strict(opt) \
385 ( ! _bit_test(opt, 20))
386 #define set_strict(opt) \
387 (_bit_clear(opt, 20))
388 #define clear_strict(opt) \
393 bit 21 : set to 1 : mail user if a job has not run during a period
394 set to 0 : do not mail user if a job has not run during a period
396 #define is_notice_notrun(opt) \
398 #define set_notice_notrun(opt) \
400 #define clear_notice_notrun(opt) \
401 (_bit_clear(opt, 21))
405 bit 22 : set to 1 : do not log normal activity of this job (only errors)
406 set to 0 : log everything
408 #define is_nolog(opt) \
410 #define set_nolog(opt) \
412 #define clear_nolog(opt) \
413 (_bit_clear(opt, 22))
417 bit 23 : set to 1 : run this job at a random time in its allowed interval of execution.
418 set to 0 : run this job asap (safer)
420 #define is_random(opt) \
422 #define set_random(opt) \
424 #define clear_random(opt) \
425 (_bit_clear(opt, 23))
429 bit 24 : set to 1 : "volatile" system up time, i.e. restart counting each time fcron
431 set to 0 : continue counting uptime where last fcron instance left of
433 #define is_volatile(opt) \
435 #define set_volatile(opt) \
437 #define clear_volatile(opt) \
438 (_bit_clear(opt, 24))
441 bit 25 : set to 1 : if fcron is running in the forground, then also let jobs print
442 to stderr/stdout instead of mailing or discarding it
443 set to 0 : if fcron is not running in the foreground or this bit is not
444 set, then treat it as specified with the other options
446 #define is_stdout(opt) \
448 #define set_stdout(opt) \
450 #define clear_stdout(opt) \
451 (_bit_clear(opt, 25))
454 bit 26 : set to 1 : The ouput of a job will only be emailed to the user if the job
455 exited with a non-zero status.
456 set to 0 : The exit-status of the job won't be taken into account to decide
457 if the output should be emailed to the user.
459 #define is_erroronlymail(opt) \
461 #define set_erroronlymail(opt) \
463 #define clear_erroronlymail(opt) \
464 (_bit_clear(opt, 26))
467 bit 27 : set to 1 : at each system startup, run the job after the delay set
469 set to 0 : leave the nextexe time as it
471 #define is_rebootreset(opt) \
473 #define set_rebootreset(opt) \
475 #define clear_rebootreset(opt) \
476 (_bit_clear(opt, 27))
479 bit 28 : set to 1 : run the job immediately after the system startup
480 set to 0 : leave the nextexe time as it
482 #define is_runatreboot(opt) \
484 #define set_runatreboot(opt) \
486 #define clear_runatreboot(opt) \
487 (_bit_clear(opt, 28))
490 bit 29 : set to 1 : run the job only once until next system reboot
491 (or next fcron restart if volatile is set)
492 set to 0 : don't limit the number of times the job is run
494 #define is_runonce(opt) \
496 #define set_runonce(opt) \
498 #define clear_runonce(opt) \
499 (_bit_clear(opt, 29))
502 bit 30 : set to 1 : the job has run at least once since system reboot
503 (or since fcron restart if volatile is set)
504 set to 0 : job hasn't run yet
506 #define is_hasrun(opt) \
508 #define set_hasrun(opt) \
510 #define clear_hasrun(opt) \
511 (_bit_clear(opt, 30))
513 #endif /* __OPTIONH__ */