From d7764219d4b785b06a3db21cb649a1dee8919d63 Mon Sep 17 00:00:00 2001 From: Thibault Godouet Date: Wed, 11 Jun 2014 10:01:52 +0100 Subject: [PATCH] don't fully disable @-line on apparent nextexe integer overflows: instead set nextexe=now+cl_runfreq --- conf.c | 26 ++++++++++++++++---------- database.c | 15 +++++++++------ doc/en/changes.sgml | 3 +++ doc/en/todo.sgml | 3 +++ 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/conf.c b/conf.c index 3f2b327..42eff29 100644 --- 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); } diff --git a/database.c b/database.c index 9d76f48..51278ab 100644 --- a/database.c +++ b/database.c @@ -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); } } diff --git a/doc/en/changes.sgml b/doc/en/changes.sgml index 7797f0f..f1e893f 100644 --- a/doc/en/changes.sgml +++ b/doc/en/changes.sgml @@ -17,6 +17,9 @@ A copy of the license is included in gfdl.sgml. 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). + + 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.` + diff --git a/doc/en/todo.sgml b/doc/en/todo.sgml index 9ece3fd..6c5956f 100644 --- a/doc/en/todo.sgml +++ b/doc/en/todo.sgml @@ -26,6 +26,9 @@ A copy of the license is included in gfdl.sgml. Option to compile and install from git sources without generating the doc + + register in OS suspend/hibernate mechanism to stop fcron when going to sleep and start it again when resuming from sleep (see FAQ entry). + -- 2.47.3