From: Thibault Godouet Date: Thu, 24 May 2001 19:57:10 +0000 (+0000) Subject: added option tzdiff X-Git-Tag: ver2_9_4~335 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54df51dcc71afcfc39c342f6a82d5f45184a1735;p=thirdparty%2Ffcron.git added option tzdiff --- diff --git a/conf.c b/conf.c index 601a1f0..b3b35da 100644 --- a/conf.c +++ b/conf.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: conf.c,v 1.43 2001-05-15 00:46:00 thib Exp $ */ + /* $Id: conf.c,v 1.44 2001-05-24 19:59:35 thib Exp $ */ #include "fcron.h" #include "conf.h" @@ -265,7 +265,16 @@ synchronize_file(char *file_name) if ( new_l->cl_runfreq == old_l->cl_runfreq ) new_l->cl_remain = old_l->cl_remain; - new_l->cl_nextexe = old_l->cl_nextexe; + /* check if there is a change about the tz diff */ + if ( (new_l->cl_file->cf_tzdiff != + old_l->cl_file->cf_tzdiff) && + (old_l->cl_nextexe - old_l->cl_file->cf_tzdiff + + new_l->cl_file->cf_tzdiff > now) ) + new_l->cl_nextexe = old_l->cl_nextexe + - old_l->cl_file->cf_tzdiff + + new_l->cl_file->cf_tzdiff; + else + new_l->cl_nextexe = old_l->cl_nextexe; insert_nextexe(new_l); if (debug_opt) { @@ -502,6 +511,15 @@ read_file(const char *file_name, CF *cf) } break; + case S_TZDIFF_T: + /* time diff between local (real) and system hour */ + if ( read(fileno(ff), &bufi, size) < size ) { + error_e("Error while reading tzdiff field"); + goto err; + } + cf->cf_tzdiff = (signed char) bufi; + break; + case S_SHELL_T: if ( read_strn(fileno(ff), &cl->cl_shell, size) != OK ) { error_e("Error while reading shell field"); @@ -1042,6 +1060,10 @@ save_file(CF *arg_file) /* S_USER_T *must* be the 3rd field of a binary fcrontab */ Save_lint(f, S_TIMEDATE_T, now); + /* Save the time diff between local (real) and system hour (if any) */ + if ( file->cf_tzdiff != 0 ) + Save_lint(f, S_TZDIFF_T, file->cf_tzdiff); + /* env variables, */ for (env = file->cf_env_base; env; env = env->e_next) Save_str(f, S_ENVVAR_T, env->e_val); diff --git a/database.c b/database.c index 4110425..b5bebd8 100644 --- a/database.c +++ b/database.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: database.c,v 1.51 2001-05-15 00:46:54 thib Exp $ */ + /* $Id: database.c,v 1.52 2001-05-24 19:59:47 thib Exp $ */ #include "fcron.h" #include "database.h" @@ -332,9 +332,12 @@ add_lavg_job(CL *line) if ( is_strict(line->cl_option) && line->cl_runfreq == 1) { struct tm *ft; struct tm ftime; - time_t end_of_cur_int = 0; + time_t begin_of_cur_int, end_of_cur_int = 0; - ft = localtime(&line->cl_nextexe); + /* handle timezone differences */ + begin_of_cur_int = line->cl_nextexe - (line->cl_file->cf_tzdiff*3600); + + ft = localtime( &begin_of_cur_int ); /* localtime() function seem to return every time the same pointer : it resets our previous changes, so we need to prevent it @@ -343,7 +346,7 @@ add_lavg_job(CL *line) goto_non_matching(line, &ftime, END_OF_INTERVAL); - end_of_cur_int = mktime(&ftime); + end_of_cur_int = mktime(&ftime) + (line->cl_file->cf_tzdiff * 3600); if ((line->cl_until > 0) && (line->cl_until + now < end_of_cur_int)) lavg_array[lavg_num].l_until = line->cl_until + now; @@ -628,10 +631,10 @@ goto_non_matching(CL *line, struct tm *ftime, char option) if (option != END_OF_INTERVAL) { if (debug_opt) set_wday(ftime); - debug(" %s beginning of next period %d/%d/%d wday:%d %02d:%02d", - line->cl_shell, (ftime->tm_mon + 1), ftime->tm_mday, - (ftime->tm_year + 1900), ftime->tm_wday, - ftime->tm_hour, ftime->tm_min); + debug(" %s beginning of next period %d/%d/%d wday:%d %02d:%02d " + "(tzdiff=%d)", line->cl_shell, (ftime->tm_mon + 1), + ftime->tm_mday, (ftime->tm_year + 1900), ftime->tm_wday, + ftime->tm_hour, ftime->tm_min, line->cl_file->cf_tzdiff); return; } @@ -752,11 +755,11 @@ goto_non_matching(CL *line, struct tm *ftime, char option) } } - debug(" %s %s %d/%d/%d wday:%d %02d:%02d", line->cl_shell, + debug(" %s %s %d/%d/%d wday:%d %02d:%02d (tzdiff=%d)",line->cl_shell, (option == STD) ? "first non matching" : "end of interval", - (ftime->tm_mon + 1), ftime->tm_mday, - (ftime->tm_year + 1900), ftime->tm_wday, - ftime->tm_hour, ftime->tm_min); + (ftime->tm_mon + 1), ftime->tm_mday, (ftime->tm_year + 1900), + ftime->tm_wday, ftime->tm_hour, ftime->tm_min, + line->cl_file->cf_tzdiff); return; } } @@ -776,8 +779,10 @@ set_next_exe(CL *line, char option) register char has_changed = 0; /* to prevent from invinite loop with unvalid lines : */ short int year_limit = MAXYEAR_SCHEDULE_TIME; + /* timezone difference */ + time_t now_tz = now - (line->cl_file->cf_tzdiff * 3600); - ft = localtime(&now); + ft = localtime(&now_tz); /* localtime() function seem to return every time the same pointer : it resets our previous changes, so we need to prevent it @@ -920,14 +925,15 @@ set_next_exe(CL *line, char option) } ftime.tm_min = i; - set_cl_nextexe: - line->cl_nextexe = mktime(&ftime); + set_cl_nextexe: + /* set cl_nextexe (handle the timezone differences) */ + line->cl_nextexe = mktime(&ftime) + (line->cl_file->cf_tzdiff * 3600); if ( option != NO_GOTO ) - debug(" cmd: %s next exec %d/%d/%d wday:%d %02d:%02d", - line->cl_shell, (ftime.tm_mon + 1), ftime.tm_mday, - (ftime.tm_year + 1900), ftime.tm_wday, - ftime.tm_hour, ftime.tm_min); + debug(" cmd: %s next exec %d/%d/%d wday:%d %02d:%02d " + "(tzdiff=%d)", line->cl_shell, (ftime.tm_mon + 1), + ftime.tm_mday, (ftime.tm_year + 1900), ftime.tm_wday, + ftime.tm_hour, ftime.tm_min, line->cl_file->cf_tzdiff); } else { @@ -947,7 +953,7 @@ set_next_exe_notrun(CL *line, char context) /* set the time of the next execution and send a mail to tell user his job * has not run if necessary */ { - time_t next_period = 0; + time_t previous_period = 0, next_period = 0; struct tm *ft = NULL; struct tm ftime, last_nextexe; char set_next_exe_opt = 0; @@ -957,14 +963,16 @@ set_next_exe_notrun(CL *line, char context) /* // */ if (context == SYSDOWN) { - ft = localtime(&line->cl_nextexe); + /* handle timezone differences */ + previous_period = line->cl_nextexe - (line->cl_file->cf_tzdiff * 3600); set_next_exe_opt = NO_GOTO; } else { - ft = localtime(&now); + previous_period = now - (line->cl_file->cf_tzdiff * 3600); set_next_exe_opt = NO_GOTO_LOG; } - + ft = localtime(&previous_period); + /* localtime() function seem to return every time the same pointer : it resets our previous changes, so we need to prevent it ( localtime() is used in the debug() function) */ @@ -974,7 +982,7 @@ set_next_exe_notrun(CL *line, char context) ftime.tm_sec = 0; goto_non_matching(line, &ftime, STD); - next_period = mktime(&ftime); + next_period = mktime(&ftime) + (line->cl_file->cf_tzdiff * 3600); set_next_exe(line, set_next_exe_opt); if ( line->cl_nextexe >= next_period ) { @@ -1106,7 +1114,8 @@ check_lavg(time_t lim) lavg_array[i].l_line->cl_shell); /* set time of the next execution and send a mail if needed */ - if ( is_notice_notrun(lavg_array[i].l_line->cl_option) ) + if ( is_td(lavg_array[i].l_line->cl_option) && + is_notice_notrun(lavg_array[i].l_line->cl_option) ) set_next_exe_notrun(lavg_array[i].l_line, LAVG); else set_next_exe(lavg_array[i].l_line, NO_GOTO_LOG); diff --git a/fileconf.c b/fileconf.c index 505c577..7c5e1c8 100644 --- a/fileconf.c +++ b/fileconf.c @@ -22,7 +22,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: fileconf.c,v 1.45 2001-05-17 00:53:29 thib Exp $ */ + /* $Id: fileconf.c,v 1.46 2001-05-24 19:57:10 thib Exp $ */ #include "fcrontab.h" #include "fileconf.h" @@ -465,7 +465,30 @@ read_opt(char *ptr, CL *cl) ptr++; } - if ( strcmp(opt_name, "s") == 0 || strcmp(opt_name, "serial") == 0 ) { + /* global options for a file */ + if ( strcmp(opt_name, "tzdiff") == 0 ) { + char negative = 0; + + if ( ! in_brackets ) + Handle_err; + if ( *ptr == '-' ) { + negative = 1; + ptr++; + } + if ( (ptr = get_num(ptr, &i, 24, 0, NULL)) == NULL ) + Handle_err; + if ( negative ) + cl->cl_file->cf_tzdiff = (- i); + else + cl->cl_file->cf_tzdiff = i; + + if (debug_opt) + fprintf(stderr, " Opt : \"%s\" (-)%d\n", opt_name, i); + } + + + /* options related to a line (or a set of lines) */ + else if(strcmp(opt_name, "s") == 0 || strcmp(opt_name, "serial") == 0){ if ( in_brackets && (ptr = get_bool(ptr, &i)) == NULL ) Handle_err; if (i == 0 ) @@ -796,7 +819,7 @@ read_opt(char *ptr, CL *cl) Handle_err; i = 0; - while ( isalnum(*ptr) ) + while ( isalnum(*ptr) && i + 1 < sizeof(buf) ) buf[i++] = *ptr++; if ( strcmp(buf, "\0") == 0 ) clear_mail(cl->cl_option); @@ -853,7 +876,7 @@ read_opt(char *ptr, CL *cl) Handle_err; cl->cl_nice = (char)i; if (debug_opt) - fprintf(stderr, " Opt : \"%s\" %d\n", opt_name, i); + fprintf(stderr, " Opt : \"%s\" (-)%d\n", opt_name, i); } else if(strcmp(opt_name, "runas") == 0) { @@ -1618,6 +1641,10 @@ save_file(char *path) /* S_USER_T *must* be the 3rd field of a binary fcrontab */ Save_lint(f, S_TIMEDATE_T, 0); + /* Save the time diff between local (real) and system hour (if any) */ + if ( file->cf_tzdiff != 0 ) + Save_lint(f, S_TZDIFF_T, file->cf_tzdiff); + /* env variables, */ for (env = file->cf_env_base; env; env = env->e_next) Save_str(f, S_ENVVAR_T, env->e_val); diff --git a/global.h b/global.h index f76dda8..23621de 100644 --- a/global.h +++ b/global.h @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: global.h,v 1.26 2001-05-17 00:57:26 thib Exp $ */ + /* $Id: global.h,v 1.27 2001-05-24 19:59:12 thib Exp $ */ /* @@ -126,9 +126,10 @@ typedef struct env_t { typedef struct CF { struct CF *cf_next; struct CL *cf_line_base; - char *cf_user; /* user-name */ - struct env_t *cf_env_base; /* list of all env variables to set */ - int cf_running; /* number of jobs running */ + char *cf_user; /* user-name */ + struct env_t *cf_env_base; /* list of all env variables to set */ + int cf_running; /* number of jobs running */ + signed char cf_tzdiff; /* time diff between system and local hour */ } CF; @@ -140,25 +141,25 @@ typedef struct CF { * in the save/load binary fcrontab functions */ typedef struct CL { struct CL *cl_next; - struct CF *cl_file; /* the file in which the line is */ - unsigned char cl_option[OPTION_SIZE]; /* line's option (see option.h)*/ - char *cl_shell; /* shell command */ - unsigned char cl_numexe; /* num of entries in lavg/serial queue */ - unsigned char cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins)*/ - time_t cl_until; /* timeout of the wait for a lavg value */ - char cl_nice; /* nice value to control priority */ - char *cl_runas; /* determine permissions of the job */ - char *cl_mailto; /* mail output to cl_mailto */ - time_t cl_nextexe; /* time and date of the next execution */ - unsigned short cl_remain; /* remaining until next execution */ - time_t cl_timefreq; /* Run every n seconds */ - unsigned short cl_runfreq; /* Run once every n matches */ + struct CF *cl_file; /* the file in which the line is */ + unsigned char cl_option[OPTION_SIZE]; /* line's option (see option.h) */ + char *cl_shell; /* shell command */ + unsigned char cl_numexe; /* num of entries in lavg/serial queue */ + unsigned char cl_lavg[LAVG_SIZE];/*load averages needed (1,5,15 mins) */ + time_t cl_until; /* timeout of the wait for a lavg value */ + char cl_nice; /* nice value to control priority */ + char *cl_runas; /* determine permissions of the job */ + char *cl_mailto; /* mail output to cl_mailto */ + time_t cl_nextexe; /* time and date of the next execution */ + unsigned short cl_remain; /* remaining until next execution */ + long int cl_timefreq; /* Run every n seconds */ + unsigned short cl_runfreq; /* Run once every n matches */ /* see bitstring(3) man page for more details */ - bitstr_t bit_decl(cl_mins, 60); /* 0-59 */ - bitstr_t bit_decl(cl_hrs, 24); /* 0-23 */ - bitstr_t bit_decl(cl_days, 32); /* 1-31 */ - bitstr_t bit_decl(cl_mons, 12); /* 0-11 */ - bitstr_t bit_decl(cl_dow, 8); /* 0-7, 0 and 7 are both Sunday */ + bitstr_t bit_decl(cl_mins, 60); /* 0-59 */ + bitstr_t bit_decl(cl_hrs, 24); /* 0-23 */ + bitstr_t bit_decl(cl_days, 32); /* 1-31 */ + bitstr_t bit_decl(cl_mons, 12); /* 0-11 */ + bitstr_t bit_decl(cl_dow, 8); /* 0-7, 0 and 7 are both Sunday */ } CL; typedef struct job { diff --git a/save.h b/save.h index 6a1ca32..17e2cb3 100644 --- a/save.h +++ b/save.h @@ -21,7 +21,7 @@ * `LICENSE' that comes with the fcron source distribution. */ - /* $Id: save.h,v 1.1 2001-04-21 08:52:16 thib Exp $ */ + /* $Id: save.h,v 1.2 2001-05-24 19:59:58 thib Exp $ */ /* here is the format fcron(tab) uses to save the fcrontabs : @@ -47,6 +47,7 @@ #define S_HEADER_T 1 /* file version */ #define S_USER_T 2 /* name of the fcrontab's owner */ #define S_TIMEDATE_T 3 /* time and date of saving */ +#define S_TZDIFF_T 4 /* time diff between the local and system hour */ /* env var */ #define S_ENVVAR_T 1000 /* an environment variable */