]> granicus.if.org Git - fcron/commitdiff
don't fully disable @-line on apparent nextexe integer overflows: instead set nextexe...
authorThibault Godouet <fcron@free.fr>
Wed, 11 Jun 2014 09:01:52 +0000 (10:01 +0100)
committerThibault Godouet <fcron@free.fr>
Wed, 11 Jun 2014 09:01:52 +0000 (10:01 +0100)
conf.c
database.c
doc/en/changes.sgml
doc/en/todo.sgml

diff --git a/conf.c b/conf.c
index 3f2b32733a06897b99064de12b20b5d51e54c686..42eff29c2510e3408451dd34a2333e6fe04964c0 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -597,6 +597,9 @@ read_file(const char *file_name, cf_t * cf, int is_system_startup)
         error("could not get time and date of saving");
         goto err;
     }
+    else {
+        debug("file saved at %lu.", t_save);
+    }
 
     if (cf->cf_env_list == NULL)
         cf->cf_env_list = env_list_init();
@@ -940,6 +943,12 @@ add_line_to_file(cl_t * cl, cf_t * cf, uid_t runas, char *runas_str,
         }
     }
     else {                      /* is_td(cl->cl_option) */
+        if (cl->cl_timefreq < 10) {
+            error("Invalid timefreq %ld for job '%s': setting to 1 day",
+                  cl->cl_timefreq, cl->cl_shell);
+            cl->cl_timefreq = 3600 * 24;
+        }
+
         /* standard @-lines */
         if (is_system_startup && is_runatreboot(cl->cl_option)) {
             cl->cl_nextexe = now;
@@ -970,24 +979,21 @@ add_line_to_file(cl_t * cl, cf_t * cf, uid_t runas, char *runas_str,
             if (cl->cl_nextexe != LONG_MAX) {
                 cl->cl_nextexe += slept;
                 if (cl->cl_nextexe < now || cl->cl_nextexe > TIME_T_MAX) {
-                    /* there was an integer overflow! */
+                    /* either there was an integer overflow, or the slept time is incorrect
+                     * (e.g. fcron didn't shut down cleanly and the fcrontab wasn't saved correctly) */
                     error
                         ("Error while setting next exe time for job %s: cl_nextexe"
-                         " overflowed (case2). now=%lu, cl_timefreq=%lu, cl_nextexe=%lu.",
+                         " overflowed (case2). now=%lu, cl_timefreq=%lu, cl_nextexe=%lu. "
+                         "Did fcron shut down cleanly?",
                          cl->cl_shell, now, cl->cl_timefreq, cl->cl_nextexe);
                     error
-                        ("Setting cl_nextexe to TIME_T_MAX=%ld to prevent an infinite loop.",
-                         TIME_T_MAX);
-                    cl->cl_nextexe = TIME_T_MAX;
+                        ("Setting cl_nextexe to now+cl_timefreq to prevent an infinite loop.");
+                    cl->cl_nextexe = now + cl->cl_timefreq;
+                    error("next execution will now be at %ld.", cl->cl_nextexe);
                 }
             }
         }
 
-        if (cl->cl_timefreq < 10) {
-            error("Invalid timefreq for %s: set to 1 day", cl->cl_shell);
-            cl->cl_timefreq = 3600 * 24;
-        }
-
         insert_nextexe(cl);
     }
 
index 9d76f489a76dd14043ef65fa0977a5b962dd8ad0..51278ab2b40356103698ea098212c33e3d4206fe 100644 (file)
@@ -613,8 +613,8 @@ set_wday(struct tm *date)
     if (date->tm_wday >= 7)
         date->tm_wday -= 7;
 
-    debug("   dow of %d-%d-%d : %d", (date->tm_mon + 1), date->tm_mday,
-          (date->tm_year + 1900), date->tm_wday);
+    debug("   dow of %04d-%02d-%02d : %d", (date->tm_year + 1900),
+          (date->tm_mon + 1), date->tm_mday, date->tm_wday);
 
 }
 
@@ -1233,14 +1233,17 @@ set_next_exe(cl_t * line, char option, int info_fd)
         else {
             line->cl_nextexe = basetime + line->cl_timefreq;
             if (line->cl_nextexe <= basetime) {
-                /* there was an integer overflow! */
+                /* either there was an integer overflow, or the slept time is incorrect
+                 * (e.g. fcron didn't shut down cleanly and the fcrontab wasn't saved correctly) */
                 error("Error while setting next exe time for job %s: cl_nextexe"
-                      " overflowed (case3). basetime=%lu, cl_timefreq=%lu, cl_nextexe=%lu.",
+                      " overflowed (case3). basetime=%lu, cl_timefreq=%lu, cl_nextexe=%lu. "
+                      "Did fcron shut down cleanly?",
                       line->cl_shell, basetime, line->cl_timefreq,
                       line->cl_nextexe);
                 error
-                    ("Setting cl_nextexe to TIME_T_MAX to prevent an infinite loop.");
-                line->cl_nextexe = TIME_T_MAX;
+                    ("Setting cl_nextexe to now+cl_timefreq to prevent an infinite loop.");
+                line->cl_nextexe = now + line->cl_timefreq;
+                error("next execution will now be at %ld.", line->cl_nextexe);
             }
         }
 
index 7797f0fdc6e19e9fb2e500710e66ff228e8c7bd9..f1e893f34b85b3992ccf5d5ca006331e355245c3 100644 (file)
@@ -17,6 +17,9 @@ A copy of the license is included in gfdl.sgml.
            <listitem>
               <para>Print date as %Y-%m-%d (the ISO 8601 date format), to avoid being ambiguous in international context.  Also always use the ':' as hour:minute separator (there was a couple of 'h' instead).</para>
            </listitem>
+           <listitem>
+              <para>Don't fully disable a @-line when something goes wrong (e.g. fcron didn't shut down cleanly).  The idea was to prevent infinite loops, but this was overkill.  Instead set its next execution to now+frequency.`</para>
+           </listitem>
       </itemizedlist>
 
       <itemizedlist>
index 9ece3fdd1a2df83b04774a0bd393c1c069258a41..6c5956fbcced9baf4e018c170082ff0b1c84c32b 100644 (file)
@@ -26,6 +26,9 @@ A copy of the license is included in gfdl.sgml.
            <listitem>
               <para>Option to compile and install from git sources without generating the doc</para>
            </listitem>
+           <listitem>
+              <para>register in OS suspend/hibernate mechanism to stop fcron when going to sleep and start it again when resuming from sleep (see FAQ entry).</para>
+           </listitem>
            <listitem>
               <para></para>
            </listitem>