]> granicus.if.org Git - fcron/commitdiff
check that we are in a %-line before allowing a "hourly", "hours", etc option.
authorthib <thib>
Sun, 24 Feb 2002 16:50:56 +0000 (16:50 +0000)
committerthib <thib>
Sun, 24 Feb 2002 16:50:56 +0000 (16:50 +0000)
fileconf.c

index 966ec0a8afe5572f92b426484281367d7ac32e3a..a50a0769ecf39b8144d9a1988927a17f2da768a8 100644 (file)
@@ -22,7 +22,7 @@
  *  `LICENSE' that comes with the fcron source distribution.
  */
 
- /* $Id: fileconf.c,v 1.56 2002-01-27 16:33:10 thib Exp $ */
+ /* $Id: fileconf.c,v 1.57 2002-02-24 16:50:56 thib Exp $ */
 
 #include "fcrontab.h"
 
@@ -568,111 +568,21 @@ read_opt(char *ptr, CL *cl)
        }
 
        else if(strcmp(opt_name, "r")==0 || strcmp(opt_name, "runfreq")==0) {
-           if( !in_brackets || (ptr=get_num(ptr,&i,USHRT_MAX,0,NULL)) == NULL)
+           if ( cl->cl_runfreq == 1 ) {
+               fprintf(stderr, "cannot change runfreq value in a %%-line");
                Handle_err;
-           if (i <= 1)
+           }
+           if ( !in_brackets || (ptr=get_num(ptr,&i,USHRT_MAX,0,NULL)) == NULL)
+               Handle_err;
+           if (i <= 1) {
                fprintf(stderr, "runfreq must be 2 or more.\n");
-           if (i <= 1)
-               Handle_err;     
+               Handle_err;
+           }
            cl->cl_runfreq = i;
            if (debug_opt)
                fprintf(stderr, "  Opt : \"%s\" %d\n", opt_name, i);
        }
 
-       /* options to run once per interval :
-        * ignore every fields below the limit */
-       else if (strcmp(opt_name, "mins") == 0) {
-           /* nothing to do */
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-       else if (strcmp(opt_name, "hours") == 0) {
-           set_freq_mins(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-       else if (strcmp(opt_name, "days") == 0) {
-           set_freq_mins(cl->cl_option);
-           set_freq_hrs(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-       else if (strcmp(opt_name, "mons") == 0) {
-           set_freq_mins(cl->cl_option);
-           set_freq_hrs(cl->cl_option);
-           set_freq_days(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-       else if (strcmp(opt_name, "dow") == 0) {
-           set_freq_mins(cl->cl_option);
-           set_freq_hrs(cl->cl_option);
-           set_freq_days(cl->cl_option);
-           set_freq_mons(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-
-       /* run once an element of the selected field 
-        * (once an hour, once a day, etc) */
-       else if (strcmp(opt_name, "hourly") == 0) {
-           set_freq_hrs(cl->cl_option);
-           set_freq_periodically(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-       else if (strcmp(opt_name, "daily") == 0) {
-           set_freq_days(cl->cl_option);
-           set_freq_periodically(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-       else if (strcmp(opt_name, "monthly") == 0) {
-           set_freq_mons(cl->cl_option);
-           set_freq_periodically(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-       else if (strcmp(opt_name, "weekly") == 0) {
-           set_freq_dow(cl->cl_option);
-           set_freq_periodically(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-
-       /* run once an element of the selected field 
-        * from middle to middle of that field 
-        * (ie once from 12h to 12h the following day) */
-       else if (strcmp(opt_name, "midhourly") == 0) {
-           set_freq_hrs(cl->cl_option);
-           set_freq_periodically(cl->cl_option);
-           set_freq_mid(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-       else if (strcmp(opt_name, "middaily") == 0 
-                || strcmp(opt_name, "nightly") == 0) {
-           set_freq_days(cl->cl_option);
-           set_freq_periodically(cl->cl_option);
-           set_freq_mid(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-       else if (strcmp(opt_name, "midmonthly") == 0) {
-           set_freq_mons(cl->cl_option);
-           set_freq_periodically(cl->cl_option);
-           set_freq_mid(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-       else if (strcmp(opt_name, "midweekly") == 0) {
-           set_freq_dow(cl->cl_option);
-           set_freq_periodically(cl->cl_option);
-           set_freq_mid(cl->cl_option);
-           if (debug_opt)
-               fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
-       }
-
        else if ( strcmp(opt_name, "strict") == 0 ) {
            if ( in_brackets && (ptr = get_bool(ptr, &i)) == NULL )
                Handle_err;
@@ -941,6 +851,105 @@ read_opt(char *ptr, CL *cl)
                fprintf(stderr, "  Opt : \"%s\" %d\n", opt_name, i);
        }
 
+       /* handle %-line : we check if we are really in a %-line (which we do not do
+        * for other options), because writing "&hourly" in a fcrontab results in an
+        * error (hourly ignored) hard to find, and, in any case, annoying. */
+       else if ( cl->cl_runfreq == 1 ) {
+           /* options to run once per interval :
+            * ignore every fields below the limit */
+           if (strcmp(opt_name, "mins") == 0) {
+               /* nothing to do */
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+           else if (strcmp(opt_name, "hours") == 0) {
+               set_freq_mins(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+           else if (strcmp(opt_name, "days") == 0) {
+               set_freq_mins(cl->cl_option);
+               set_freq_hrs(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+           else if (strcmp(opt_name, "mons") == 0) {
+               set_freq_mins(cl->cl_option);
+               set_freq_hrs(cl->cl_option);
+               set_freq_days(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+           else if (strcmp(opt_name, "dow") == 0) {
+               set_freq_mins(cl->cl_option);
+               set_freq_hrs(cl->cl_option);
+               set_freq_days(cl->cl_option);
+               set_freq_mons(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+
+           /* run once an element of the selected field 
+            * (once an hour, once a day, etc) */
+           else if (strcmp(opt_name, "hourly") == 0) {
+               set_freq_hrs(cl->cl_option);
+               set_freq_periodically(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+           else if (strcmp(opt_name, "daily") == 0) {
+               set_freq_days(cl->cl_option);
+               set_freq_periodically(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+           else if (strcmp(opt_name, "monthly") == 0) {
+               set_freq_mons(cl->cl_option);
+               set_freq_periodically(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+           else if (strcmp(opt_name, "weekly") == 0) {
+               set_freq_dow(cl->cl_option);
+               set_freq_periodically(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+
+           /* run once an element of the selected field 
+            * from middle to middle of that field 
+            * (ie once from 12h to 12h the following day) */
+           else if (strcmp(opt_name, "midhourly") == 0) {
+               set_freq_hrs(cl->cl_option);
+               set_freq_periodically(cl->cl_option);
+               set_freq_mid(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+           else if (strcmp(opt_name, "middaily") == 0 
+                    || strcmp(opt_name, "nightly") == 0) {
+               set_freq_days(cl->cl_option);
+               set_freq_periodically(cl->cl_option);
+               set_freq_mid(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+           else if (strcmp(opt_name, "midmonthly") == 0) {
+               set_freq_mons(cl->cl_option);
+               set_freq_periodically(cl->cl_option);
+               set_freq_mid(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+           else if (strcmp(opt_name, "midweekly") == 0) {
+               set_freq_dow(cl->cl_option);
+               set_freq_periodically(cl->cl_option);
+               set_freq_mid(cl->cl_option);
+               if (debug_opt)
+                   fprintf(stderr, "  Opt : \"%s\"\n", opt_name);
+           }
+       }
+
        else {
            fprintf(stderr, "%s:%d: Option \"%s\" unknown: "
                    "skipping option.\n", file_name, line, opt_name);  
@@ -1255,15 +1264,16 @@ read_period(char *ptr, CF *cf)
     /* skip the % */
     ptr++;
 
+    /* a runfreq set to 1 means : this is a periodical line 
+     * (runfreq cannot be changed by read_opt() if already set to 1) */
+    cl->cl_remain = cl->cl_runfreq = 1;
+
     /* set cl_remain if not specified */
     if ( (ptr = read_opt(ptr, cl)) == NULL ) {
        goto exiterr;
     }
     Skip_blanks(ptr);
 
-    /* a runfreq set to 1 means : this is a periodical line */
-    cl->cl_remain = cl->cl_runfreq = 1;
-
     /* we set this here, because it may be unset by read_opt (reset option) */
     set_td(cl->cl_option);