* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fileconf.c,v 1.25 2000-11-14 19:46:23 thib Exp $ */
+ /* $Id: fileconf.c,v 1.26 2000-12-04 20:16:50 thib Exp $ */
#include "fcrontab.h"
char *get_runas(char *ptr, uid_t *uid);
char *get_nice(char *ptr, int *nice);
char *get_bool(char *ptr, int *i);
-char *read_field(char *ptr, bitstr_t *ary, int max, const char **names);
+char *read_field(char *ptr, bitstr_t *ary, int max, const char **names,
+ char is_runfreq1);
void read_freq(char *ptr, CF *cf);
void read_arys(char *ptr, CF *cf);
void read_env(char *ptr, CF *cf);
NULL
};
+/* warning : all names must have the same length */
+/* we want a number from 1 to 5: we set the first string to a number,
+ * in order to make get_num() ignore it */
+const char *field_ary[] = {
+ "333", "min", "hrs", "day", "mon", "dow", NULL
+};
char *
get_string(char *ptr)
fprintf(stderr, " Opt : '%s' %d\n", opt_name, i);
}
+ else if (strcmp(opt_name, "lavgonce") == 0 ) {
+ if ( in_brackets && (ptr = get_bool(ptr, &i)) == NULL )
+ Handle_err;
+ if (i == 0 )
+ set_lavg_sev(cl->cl_option);
+ else
+ clear_lavg_sev(cl->cl_option);
+ if (debug_opt)
+ fprintf(stderr, " Opt : '%s' %d\n", opt_name, i);
+ }
+
else if (strcmp(opt_name, "exesev") == 0 ) {
if ( in_brackets && (ptr = get_bool(ptr, &i)) == NULL )
Handle_err;
fprintf(stderr, " Opt : '%s' %d\n", opt_name, i);
}
+ else if( strcmp(opt_name, "ignore") == 0 ) {
+ do {
+ if(!in_brackets || (ptr=get_num(ptr,&i,5,0,field_ary)) == NULL)
+ Handle_err;
+ switch (i) {
+ case 1:
+ set_ign_mins(cl->cl_option); break;
+ case 2:
+ set_ign_hrs(cl->cl_option); break;
+ case 3:
+ set_ign_days(cl->cl_option); break;
+ case 4:
+ set_ign_mons(cl->cl_option); break;
+ case 5:
+ set_ign_dow(cl->cl_option); break;
+ default:
+ Handle_err;
+ }
+ if (debug_opt)
+ fprintf(stderr, " Opt : '%s' %s\n",opt_name,field_ary[i]);
+
+ } while (*ptr == ',' && ptr++);
+ }
+
+ else if( strcmp(opt_name, "account") == 0 ) {
+ do {
+ if(!in_brackets || (ptr=get_num(ptr,&i,5,0,field_ary)) == NULL)
+ Handle_err;
+ switch (i) {
+ case 1:
+ clear_ign_mins(cl->cl_option); break;
+ case 2:
+ clear_ign_hrs(cl->cl_option); break;
+ case 3:
+ clear_ign_days(cl->cl_option); break;
+ case 4:
+ clear_ign_mons(cl->cl_option); break;
+ case 5:
+ clear_ign_dow(cl->cl_option); break;
+ default:
+ Handle_err;
+ }
+ if (debug_opt)
+ fprintf(stderr, " Opt : '%s' %s\n",opt_name,field_ary[i]);
+
+ } while (*ptr == ',' && ptr++);
+ }
+
else if( strcmp(opt_name, "lavg") == 0 ) {
if(!in_brackets ||(ptr=get_num(ptr, &i, UCHAR_MAX, 1, NULL))==NULL)
Handle_err;
#define R_field(ptr, ary, max, aryconst, descrp) \
- if((ptr = read_field(ptr, ary, max, aryconst)) == NULL) { \
+ if((ptr = read_field(ptr, ary, max, aryconst, is_runfreq1)) == NULL) { \
if (debug_opt) \
fprintf(stderr, "\n"); \
fprintf(stderr, "%s:%d: Error while reading " descrp " field: " \
{
CL *cl = NULL;
unsigned int i = 0;
+ char is_runfreq1 = 0;
Alloc(cl, CL);
memcpy(cl, &default_line, sizeof(CL));
if (debug_opt)
fprintf(stderr, " ");
+ /* set is_runfreq1 : this is used in R_field */
+ is_runfreq1 = (cl->cl_runfreq == 1) ? 1 : 0;
+
/* get the fields (check for errors) */
R_field(ptr, cl->cl_mins, 59, NULL, "minutes");
R_field(ptr, cl->cl_hrs, 23, NULL, "hours");
const size_t s_dow=8;
int j = 0;
- bit_ffc(cl->cl_mins, s_mins, &j);
- if ( j != -1 ) goto ok;
- bit_ffc(cl->cl_hrs, s_hrs, &j);
- if ( j != -1 ) goto ok;
- bit_ffc(cl->cl_days, s_days, &j);
- if ( j != -1 ) {
- if ( is_dayand(cl->cl_option) )
- goto ok;
- else {
- bit_ffc(cl->cl_dow, s_dow, &j);
- if ( j != -1 ) goto ok;
+ if ( ! is_ign_mins(cl->cl_option) ) {
+ bit_ffc(cl->cl_mins, s_mins, &j);
+ if ( j != -1 ) goto ok;
+ }
+ if ( ! is_ign_hrs(cl->cl_option) ) {
+ bit_ffc(cl->cl_hrs, s_hrs, &j);
+ if ( j != -1 ) goto ok;
+ }
+ if ( ! is_ign_days(cl->cl_option) ) {
+ bit_ffc(cl->cl_days, s_days, &j);
+ if ( j != -1 ) {
+ if ( is_dayand(cl->cl_option) )
+ goto ok;
+ else {
+ if ( ! is_ign_dow(cl->cl_option) ) {
+ bit_ffc(cl->cl_dow, s_dow, &j);
+ if ( j != -1 ) goto ok;
+ }
+ }
}
}
- bit_ffc(cl->cl_mons, s_mons, &j);
- if ( j != -1 ) goto ok;
- bit_ffc(cl->cl_dow, s_dow, &j);
- if ( j != -1 && is_dayand(cl->cl_option) ) goto ok;
+ if ( ! is_ign_mons(cl->cl_option) ) {
+ bit_ffc(cl->cl_mons, s_mons, &j);
+ if ( j != -1 ) goto ok;
+ }
+ if ( ! is_ign_dow(cl->cl_option) ) {
+ bit_ffc(cl->cl_dow, s_dow, &j);
+ if ( j != -1 && is_dayand(cl->cl_option) ) goto ok;
+ }
fprintf(stderr, "%s:%d: runfreq=1 with no intervals: skipping line.\n",
file_name, line);
char *
-read_field(char *ptr, bitstr_t *ary, int max, const char **names)
+read_field(char *ptr, bitstr_t *ary, int max, const char **names,
+ char is_runfreq1)
/* read a field like "2,5-8,10-20/2,21-30~25" and fill ary */
{
int start = 0;
int step = 0;
int rm = 0;
int i = 0;
+ char is_single = 0;
+ char is_interval = 0;
while ( (*ptr != ' ') && (*ptr != '\t') && (*ptr != '\0') ) {
/* this is a single number : set up array and continue */
if (debug_opt)
fprintf(stderr, " %d", start);
+ if (is_interval == 1) {
+ fprintf(stderr, "\n%s:%d: Could not have both single "
+ "numbers and intervals with option runfreq set"
+ " to 1", file_name, line);
+ need_correction = 1;
+ return NULL;
+ }
bit_set(ary, start);
+ is_single = 1;
continue;
}
if (debug_opt)
fprintf(stderr, " %d-%d/%d", start, stop, step);
+ if (step == 1) {
+ if (is_single == 1) {
+ fprintf(stderr, "\n%s:%d: Could not have both single numbers "
+ "and intervals with option runfreq set to 1",
+ file_name, line);
+ need_correction = 1;
+ return NULL;
+ }
+ is_interval = 1;
+ }
+ else
+ is_single = 1;
+
if (start < stop)
for (i = start; i <= stop; i += step)
bit_set(ary, i);
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: option.h,v 1.10 2000-09-30 11:59:34 thib Exp $ */
+ /* $Id: option.h,v 1.11 2000-12-04 20:20:09 thib Exp $ */
+
+/* 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 */
9 does this line use option runas ?
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() ?
*/
/* internal macros */
+#define _bit_byte(bit) \
+ ((bit) >> 3)
+
#define _bit_set(opt, bit) \
- (opt |= (1u << bit))
+ ((opt)[_bit_byte(bit)] |= (1 << ((bit)&0x7)))
#define _bit_test(opt, bit) \
- (opt & (1u << bit))
+ ((opt)[_bit_byte(bit)] & (1 << ((bit)&0x7)))
#define _bit_clear(opt, bit) \
- (opt &= ~(1u << bit))
+ ((opt)[_bit_byte(bit)] &= ~(1 << ((bit)&0x7)))
/* external macros */
(_bit_clear(opt, 10))
-#if ( SERIAL_ONCE == 0 )
+#if ( SERIAL_ONCE == 1 )
/*
bit 11 : set to 1 : can be put several times in serial queue simultaneously
set to 0 : can only be put once in serial queue simultaneously
#endif /* SERIAL_ONCE == 0 */
+#if ( LAVG_ONCE == 1 )
+/*
+ bit 12 : set to 1 : can be put several times in lavg queue simultaneously
+ set to 0 : can only be put once 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))
+#else
+/*
+ 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_clear(opt, 12))
+#define clear_lavg_sev(opt) \
+ (_bit_set(opt, 12))
+#endif /* LAVG_ONCE == 0 */
+
+
+/*
+ bit 13 : set to 1 : mins field should be ignored in goto_non_matching()
+ set to 0 : mins field should not be ignored in goto_non_matching()
+*/
+#define is_ign_mins(opt) \
+ (_bit_test(opt, 13))
+#define set_ign_mins(opt) \
+ (_bit_set(opt, 13))
+#define clear_ign_mins(opt) \
+ (_bit_clear(opt, 13))
+
+
+/*
+ bit 14 : set to 1 : hrs field should be ignored in goto_non_matching()
+ set to 0 : hrs field should not be ignored in goto_non_matching()
+*/
+#define is_ign_hrs(opt) \
+ (_bit_test(opt, 14))
+#define set_ign_hrs(opt) \
+ (_bit_set(opt, 14))
+#define clear_ign_hrs(opt) \
+ (_bit_clear(opt, 14))
+
+
+/*
+ bit 15 : set to 1 : days field should be ignored in goto_non_matching()
+ set to 0 : days field should not be ignored in goto_non_matching()
+*/
+#define is_ign_days(opt) \
+ (_bit_test(opt, 15))
+#define set_ign_days(opt) \
+ (_bit_set(opt, 15))
+#define clear_ign_days(opt) \
+ (_bit_clear(opt, 15))
+
+
+/*
+ bit 16 : set to 1 : mons field should be ignored in goto_non_matching()
+ set to 0 : mons field should not be ignored in goto_non_matching()
+*/
+#define is_ign_mons(opt) \
+ (_bit_test(opt, 16))
+#define set_ign_mons(opt) \
+ (_bit_set(opt, 16))
+#define clear_ign_mons(opt) \
+ (_bit_clear(opt, 16))
+
+
+/*
+ bit 17 : set to 1 : dow field should be ignored in goto_non_matching()
+ set to 0 : dow field should not be ignored in goto_non_matching()
+*/
+#define is_ign_dow(opt) \
+ (_bit_test(opt, 17))
+#define set_ign_dow(opt) \
+ (_bit_set(opt, 17))
+#define clear_ign_dow(opt) \
+ (_bit_clear(opt, 17))
+
+
#endif /* __OPTIONH__ */