-
Notifications
You must be signed in to change notification settings - Fork 13
/
option.h
526 lines (448 loc) · 15.1 KB
/
option.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
/*
* FCRON - periodic command scheduler
*
* Copyright 2000-2021 Thibault Godouet <fcron@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* The GNU General Public License can also be found in the file
* `LICENSE' that comes with the fcron source distribution.
*/
/* This has been inspired from bitstring(3) : here is the original copyright :
*/
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Paul Vixie.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*/
/* read and set options of a line */
/* WARNING : do not change any option number, nor remove any option, nor change
* the meaning of a value (i.e. bit set to 1 -> true).
* It can lead to errors with fcrontabs already saved to disk
* or loaded in memory.
*/
/* WARNING : if you add some options, make sure that OPTION_SIZE is big
* enough in global.h */
/*
The options are :
bit: option:
0 is this job based on time and date or system up time ?
1 is this job based on system load average ?
2 perform a logic OR or a logic AND between load averages ?
3 perform a logic OR or a logic AND between week day and month day ?
4 should we run this job at fcron startup if it should have been
executed during system down?
5 should this job be run serially ?
6 should this job be run serially only once (for bootrun) ?
7 does the output have to be mailed to user ?
8 does the output (even if zero-length) must be mailed to user ?
9 if time of execution is exceeded, exec the lavg job or not ?
10 can this job be executed several times simultaneously
11 can this job be put several times in the serial queue simultaneously
12 can this job be put several times in the lavg queue simultaneously
13 should mins field be ignored in goto_non_matching() ?
14 should hrs field be ignored in goto_non_matching() ?
15 should days field be ignored in goto_non_matching() ?
16 should mons field be ignored in goto_non_matching() ?
17 should dow field be ignored in goto_non_matching() ?
18 First freq is the freq (*ly) or the first field to take into account ?
19 Freq (ie daily) is from middle to middle of period (ie nightly) ?
20 Should we remove a %-job from lavg queue if the interval is exceeded ?
21 Should user be mailed if a %-job has not run during a period ?
22 Should fcron log everything about this job or just errors ?
23 Should this job be run asap, or randomly in its allowed interval of execution ?
24 Should first value be applied at each fcron startup, or before line first exe ?
25 if fcron is running in foreground, print jobs output to stderr/stdout or mail ?
26 should the output of the job be emailed to the user only non-zero exit status ?
27 rebootreset: if set then apply option first at each system startup
28 runatreboot: if set then run the job at each system startup
29 runonce: if set then run the job only once
30 hasrun: set if the job has been run at least once
31 runatresume: if set then run the job at each system resume (from suspend/hibernation)
*/
#ifndef __OPTIONH__
#define __OPTIONH__
/* we need to include this to get some default values */
#include "config.h"
/* internal macros */
#define _bit_byte(bit) \
((bit) >> 3)
#define _bit_set(opt, bit) \
((opt)[_bit_byte(bit)] |= (1 << ((bit)&0x7)))
#define _bit_test(opt, bit) \
((opt)[_bit_byte(bit)] & (1 << ((bit)&0x7)))
#define _bit_clear(opt, bit) \
((opt)[_bit_byte(bit)] &= ~(1 << ((bit)&0x7)))
/* external macros */
/* default value generally corresponds to a bit value of 0 : if you want to
* change the default value of an option, do it by modifying the following
* macro (set to 1 the needed bits) */
#define set_default_opt(opt) \
{ \
if ( SERIAL_ONCE >= 1 ) clear_serial_sev(opt); \
if ( LAVG_ONCE == 0 ) set_lavg_sev(opt); \
}
/*
bit 0 : set to 1 : line is based on system up time
set to 0 : line is based on time and date
*/
#define is_freq(opt) \
(_bit_test(opt, 0))
#define is_td(opt) \
( ! _bit_test(opt, 0))
#define set_freq(opt) \
(_bit_set(opt, 0))
#define set_td(opt) \
(_bit_clear(opt, 0))
/*
bit 1 : set to 1 : line based on system load average
set to 0 : line doesn't take care of load average
*/
#define is_lavg(opt) \
(_bit_test(opt, 1))
#define set_lavg(opt) \
(_bit_set(opt, 1))
#define clear_lavg(opt) \
(_bit_clear(opt, 1))
/*
bit 2 : set to 1 : perform a logic OR between load averages
set to 0 : perform a logic AND between load averages
*/
#define is_lor(opt) \
(_bit_test(opt, 2))
#define is_land(opt) \
( ! _bit_test(opt, 2))
#define set_lor(opt) \
(_bit_set(opt, 2))
#define set_land(opt) \
(_bit_clear(opt, 2))
/*
bit 3 : set to 1 : perform a logic OR between week day and month day
set to 0 : perform a logic AND between week day and month day
*/
#define is_dayor(opt) \
(_bit_test(opt, 3))
#define is_dayand(opt) \
( ! _bit_test(opt, 3))
#define set_dayor(opt) \
(_bit_set(opt, 3))
#define set_dayand(opt) \
(_bit_clear(opt, 3))
/*
bit 4 : set to 1 : run this line at fcron's startup if it should have been
executed during system down
set to 0 : do not run it at fcron's startup
*/
#define is_bootrun(opt) \
(_bit_test(opt, 4))
#define set_bootrun(opt) \
(_bit_set(opt, 4))
#define clear_bootrun(opt) \
(_bit_clear(opt, 4))
/*
bit 5 : set to 1 : run this line serially
set to 0 : do not run it serially
*/
#define is_serial(opt) \
(_bit_test(opt, 5))
#define set_serial(opt) \
(_bit_set(opt, 5))
#define clear_serial(opt) \
(_bit_clear(opt, 5))
/*
bit 6 : set to 1 : job is being serialized once
set to 0 : job is not being serialized once
*/
#define is_serial_once(opt) \
(_bit_test(opt, 6))
#define set_serial_once(opt) \
(_bit_set(opt, 6))
#define clear_serial_once(opt) \
(_bit_clear(opt, 6))
/*
bit 7 : set to 1 : do not mail output
set to 0 : mail output to user
*/
#define is_mail(opt) \
( ! _bit_test(opt, 7))
#define set_mail(opt) \
(_bit_clear(opt, 7))
#define clear_mail(opt) \
(_bit_set(opt, 7))
/*
bit 8 : set to 1 : mail output even if it is zero-length to user
set to 0 : mail output only if it is non-zero length
*/
#define is_mailzerolength(opt) \
(_bit_test(opt, 8))
#define set_mailzerolength(opt) \
(_bit_set(opt, 8))
#define clear_mailzerolength(opt) \
(_bit_clear(opt, 8))
/*
bit 9 : set to 1 : exec the job now if time of execution is exceeded
set to 0 : do not exec the job if time of execution is exceeded
*/
#define is_run_if_late(opt) \
(_bit_test(opt, 9))
#define set_run_if_late(opt) \
(_bit_set(opt, 9))
#define clear_run_if_late(opt) \
(_bit_clear(opt, 9))
/*
bit 10 : set to 1 : line can be executed several times simultaneously
set to 0 : line can only be executed once simultaneously
*/
#define is_exe_sev(opt) \
(_bit_test(opt, 10))
#define set_exe_sev(opt) \
(_bit_set(opt, 10))
#define clear_exe_sev(opt) \
(_bit_clear(opt, 10))
/*
bit 11 : set to 1 : can only be put once in serial queue simultaneously
set to 0 : can be put several times in serial queue simultaneously
*/
#define is_serial_sev(opt) \
( ! _bit_test(opt, 11))
#define set_serial_sev(opt) \
(_bit_clear(opt, 11))
#define clear_serial_sev(opt) \
(_bit_set(opt, 11))
/*
bit 12 : set to 1 : can only be put once in lavg queue simultaneously
set to 0 : can be put several times in lavg queue simultaneously
*/
#define is_lavg_sev(opt) \
(_bit_test(opt, 12))
#define set_lavg_sev(opt) \
(_bit_set(opt, 12))
#define clear_lavg_sev(opt) \
(_bit_clear(opt, 12))
/*
bit 13 : set to 1 : mins field is the limit
set to 0 : mins field is not the limit
*/
#define is_freq_mins(opt) \
(_bit_test(opt, 13))
#define set_freq_mins(opt) \
(_bit_set(opt, 13))
#define clear_freq_mins(opt) \
(_bit_clear(opt, 13))
/*
bit 14 : set to 1 : hrs field is the limit
set to 0 : hrs field is not the limit
*/
#define is_freq_hrs(opt) \
(_bit_test(opt, 14))
#define set_freq_hrs(opt) \
(_bit_set(opt, 14))
#define clear_freq_hrs(opt) \
(_bit_clear(opt, 14))
/*
bit 15 : set to 1 : days field is the limit
set to 0 : days field is not the limit
*/
#define is_freq_days(opt) \
(_bit_test(opt, 15))
#define set_freq_days(opt) \
(_bit_set(opt, 15))
#define clear_freq_days(opt) \
(_bit_clear(opt, 15))
/*
bit 16 : set to 1 : mons field is the limit
set to 0 : mons field is not the limit
*/
#define is_freq_mons(opt) \
(_bit_test(opt, 16))
#define set_freq_mons(opt) \
(_bit_set(opt, 16))
#define clear_freq_mons(opt) \
(_bit_clear(opt, 16))
/*
bit 17 : set to 1 : dow field is the limit
set to 0 : dow field is not the limit
*/
#define is_freq_dow(opt) \
(_bit_test(opt, 17))
#define set_freq_dow(opt) \
(_bit_set(opt, 17))
#define clear_freq_dow(opt) \
(_bit_clear(opt, 17))
/*
bit 18 : set to 1 : limit field is freq to run the line (once a hour, etc)
set to 0 : run once per interval of the limit field
*/
#define is_freq_periodically(opt) \
(_bit_test(opt, 18))
#define set_freq_periodically(opt) \
(_bit_set(opt, 18))
#define clear_freq_periodically(opt) \
(_bit_clear(opt, 18))
/*
bit 19 : set to 1 : run once from mid-period to mid-period (i.e. nightly)
set to 0 : run once from begin to the end of period (i.e. daily)
*/
#define is_freq_mid(opt) \
(_bit_test(opt, 19))
#define set_freq_mid(opt) \
(_bit_set(opt, 19))
#define clear_freq_mid(opt) \
(_bit_clear(opt, 19))
/*
bit 20 : set to 1 : let the job in the %-queue if interval is exceeded
set to 0 : remove %-job from lavg queue if interval is exceeded
*/
#define is_strict(opt) \
( ! _bit_test(opt, 20))
#define set_strict(opt) \
(_bit_clear(opt, 20))
#define clear_strict(opt) \
(_bit_set(opt, 20))
/*
bit 21 : set to 1 : mail user if a job has not run during a period
set to 0 : do not mail user if a job has not run during a period
*/
#define is_notice_notrun(opt) \
(_bit_test(opt, 21))
#define set_notice_notrun(opt) \
(_bit_set(opt, 21))
#define clear_notice_notrun(opt) \
(_bit_clear(opt, 21))
/*
bit 22 : set to 1 : do not log normal activity of this job (only errors)
set to 0 : log everything
*/
#define is_nolog(opt) \
(_bit_test(opt, 22))
#define set_nolog(opt) \
(_bit_set(opt, 22))
#define clear_nolog(opt) \
(_bit_clear(opt, 22))
/*
bit 23 : set to 1 : run this job at a random time in its allowed interval of execution.
set to 0 : run this job asap (safer)
*/
#define is_random(opt) \
(_bit_test(opt, 23))
#define set_random(opt) \
(_bit_set(opt, 23))
#define clear_random(opt) \
(_bit_clear(opt, 23))
/*
bit 24 : set to 1 : "volatile" system up time, i.e. restart counting each time fcron
is started
set to 0 : continue counting uptime where last fcron instance left of
*/
#define is_volatile(opt) \
(_bit_test(opt, 24))
#define set_volatile(opt) \
(_bit_set(opt, 24))
#define clear_volatile(opt) \
(_bit_clear(opt, 24))
/*
bit 25 : set to 1 : if fcron is running in the foreground, then also let jobs print
to stderr/stdout instead of mailing or discarding it
set to 0 : if fcron is not running in the foreground or this bit is not
set, then treat it as specified with the other options
*/
#define is_stdout(opt) \
(_bit_test(opt, 25))
#define set_stdout(opt) \
(_bit_set(opt, 25))
#define clear_stdout(opt) \
(_bit_clear(opt, 25))
/*
bit 26 : set to 1 : The ouput of a job will only be emailed to the user if the job
exited with a non-zero status.
set to 0 : The exit-status of the job won't be taken into account to decide
if the output should be emailed to the user.
*/
#define is_erroronlymail(opt) \
(_bit_test(opt, 26))
#define set_erroronlymail(opt) \
(_bit_set(opt, 26))
#define clear_erroronlymail(opt) \
(_bit_clear(opt, 26))
/*
bit 27 : set to 1 : at each system startup, run the job after the delay set
in the option first
set to 0 : leave the nextexe time as it
*/
#define is_rebootreset(opt) \
(_bit_test(opt, 27))
#define set_rebootreset(opt) \
(_bit_set(opt, 27))
#define clear_rebootreset(opt) \
(_bit_clear(opt, 27))
/*
bit 28 : set to 1 : run the job immediately after the system startup
set to 0 : leave the nextexe time as it
*/
#define is_runatreboot(opt) \
(_bit_test(opt, 28))
#define set_runatreboot(opt) \
(_bit_set(opt, 28))
#define clear_runatreboot(opt) \
(_bit_clear(opt, 28))
/*
bit 29 : set to 1 : run the job only once until next system reboot
(or next fcron restart if volatile is set)
set to 0 : don't limit the number of times the job is run
*/
#define is_runonce(opt) \
(_bit_test(opt, 29))
#define set_runonce(opt) \
(_bit_set(opt, 29))
#define clear_runonce(opt) \
(_bit_clear(opt, 29))
/*
bit 30 : set to 1 : the job has run at least once since system reboot
(or since fcron restart if volatile is set,
or since last resume if runatresume is set)
set to 0 : job hasn't run yet
*/
#define is_hasrun(opt) \
(_bit_test(opt, 30))
#define set_hasrun(opt) \
(_bit_set(opt, 30))
#define clear_hasrun(opt) \
(_bit_clear(opt, 30))
/*
bit 31 : set to 1 : run the job immediately after the system resume (from suspend/hibernation)
set to 0 : leave the nextexe time as it
*/
#define is_runatresume(opt) \
(_bit_test(opt, 31))
#define set_runatresume(opt) \
(_bit_set(opt, 31))
#define clear_runatresume(opt) \
(_bit_clear(opt, 31))
#endif /* __OPTIONH__ */