* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: database.c,v 1.59 2001-12-23 22:04:55 thib Exp $ */
+ /* $Id: database.c,v 1.60 2002-01-27 16:33:20 thib Exp $ */
#include "fcron.h"
struct tm *ft;
struct tm ftime;
+ time_t nextexe = 0;
register int i;
int max;
register char has_changed = 0;
set_cl_nextexe:
/* set cl_nextexe (handle the timezone differences) */
- line->cl_nextexe = mktime(&ftime) + (line->cl_file->cf_tzdiff * 3600);
+ nextexe = mktime(&ftime);
- if ( option != NO_GOTO )
+ if ( is_random(line->cl_option) ) {
+ /* run the job at a random time during its interval of execution */
+ struct tm intend;
+ time_t intend_int;
+
+ debug(" cmd: %s begin int 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);
+
+ memcpy(&intend, &ftime, sizeof(intend));
+ goto_non_matching(line, &intend, END_OF_INTERVAL);
+ intend_int = mktime(&intend);
+
+ /* set a random time to add to the first allowed time of execution */
+ nextexe += ( (i= intend_int - nextexe) > 0) ? (time_t)( rand() % i) : 0 ;
+
+ }
+
+ line->cl_nextexe = nextexe + (line->cl_file->cf_tzdiff * 3600);
+
+ if ( option != NO_GOTO ) {
+ if ( is_random(line->cl_option) ) {
+ ft = localtime(&nextexe);
+ memcpy(&ftime, ft, sizeof(ftime));
+ }
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 {
A copy of the license is included in gfdl.sgml.
-->
-<!-- $Id: fcrontab.5.sgml,v 1.2 2002-01-04 19:12:01 thib Exp $ -->
+<!-- $Id: fcrontab.5.sgml,v 1.3 2002-01-27 16:37:37 thib Exp $ -->
<refentry id="fcrontab.5">
<refmeta>
<para>&seealso; options &optdayor;, &optbootrun;, &optrunfreq;, &optmail;, &optnolog;, &optserial;, &optlavg;, &optnice;, &optrunas; (see below).</para>
</refsect2>
- <refsect2>
+ <refsect2 id="fcrontab.5.periodent">
<title>Entries run periodically</title>
<para>The third type of &fcrontabf;'s entries begin by a "%", followed by one of the keywords :</para>
<para><simplelist type="inline">
<para>a single number in a field is considered as an interval : <programlisting>%mins 15 2-4 * * * echo</programlisting> will run at 2:15, 3:15 AND 4:15 every day.</para>
<para>But every fields below the keywords are ignored in interval definition : <programlisting>%hours 15 2-4 * * * echo</programlisting> will run only ONCE either at 2:15, 3:15 OR 4:15.</para>
</note>
+ <para>&seealso; option &optrandom; (see below).</para>
</refsect2>
<refsect2>
<para>&seealso; options &optlavg;, &optstrict;.</para>
</listitem>
</varlistentry>
+ <varlistentry id="fcrontab.5.random">
+ <term>random</term>
+ <listitem>
+ <para><emphasis><type>boolean</type></emphasis>(<constant>0</constant>)</para>
+ <para>In a <link linkend="fcrontab.5.periodent">line run periodically</link>, this option answer the question : should this job be run as soon as possible in its interval of execution (safer), or should fcron set a random time of execution in that interval ? Note that if this option is set, the job may not run if fcron is not running during <emphasis>all</emphasis>the execution interval. Besides, you must know that the random scheme may be quite easy to guess for skilled people.</para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>A <type>boolean</type> argument can be inexistent, in which case brackets are not used and it means <constant>true</constant>; the string "true", "yes" or 1 to mean <constant>true</constant>; and the string "false", "no" or 0 to mean <constant>false</constant>. See above for explanations about time value (section <link linkend="uptent">"entries based on elapsed system up time"</link>).</para>
<para>Note that <varname>dayand</varname> and <varname>dayor</varname> are in fact the same option : a false value to <varname>dayand</varname> is equivalent to a true to <varname>dayor</varname>, and reciprocally a false value to <varname>dayor</varname> is equivalent a true value to <varname>dayand</varname>. It is the same for <varname>lavgand</varname> and <varname>lavgor</varname>.</para>
<!ENTITY optnice '<link linkend="fcrontab.5.nice"><varname>nice</varname></link>'>
<!ENTITY optnolog '<link linkend="fcrontab.5.nolog"><varname>nolog</varname></link>'>
<!ENTITY optnoticenotrun '<link linkend="fcrontab.5.noticenotrun"><varname>noticenotrun</varname></link>'>
+<!ENTITY optrandom '<link linkend="fcrontab.5.random"><varname>random</varname></link>'>
<!ENTITY optreset '<link linkend="fcrontab.5.reset"><varname>reset</varname></link>'>
<!ENTITY optrunas '<link linkend="fcrontab.5.runas"><varname>runas</varname></link>'>
<!ENTITY optrunfreq '<link linkend="fcrontab.5.runfreq"><varname>runfreq</varname></link>'>
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fcron.c,v 1.57 2001-12-23 22:04:37 thib Exp $ */
+ /* $Id: fcron.c,v 1.58 2002-01-27 16:32:53 thib Exp $ */
#include "fcron.h"
#include "conf.h"
#include "job.h"
-char rcs_info[] = "$Id: fcron.c,v 1.57 2001-12-23 22:04:37 thib Exp $";
+char rcs_info[] = "$Id: fcron.c,v 1.58 2002-01-27 16:32:53 thib Exp $";
void main_loop(void);
void check_signal(void);
if ( (lavg_array = calloc(lavg_array_size, sizeof(lavg))) == NULL )
die_e("could not calloc lavg_array");
-
+ /* initialize random number generator :
+ * WARNING : easy to guess !!! */
+ srand(time(NULL));
main_loop();
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: fileconf.c,v 1.55 2001-12-23 22:04:44 thib Exp $ */
+ /* $Id: fileconf.c,v 1.56 2002-01-27 16:33:10 thib Exp $ */
#include "fcrontab.h"
}
}
+ else if( strcmp(opt_name, "random") == 0 ) {
+ if ( in_brackets && (ptr = get_bool(ptr, &i)) == NULL )
+ Handle_err;
+ if ( i == 0 )
+ clear_random(cl->cl_option);
+ else
+ set_random(cl->cl_option);
+ if (debug_opt)
+ fprintf(stderr, " Opt : \"%s\" %d\n", opt_name, i);
+ }
+
else {
fprintf(stderr, "%s:%d: Option \"%s\" unknown: "
"skipping option.\n", file_name, line, opt_name);
* `LICENSE' that comes with the fcron source distribution.
*/
- /* $Id: option.h,v 1.19 2001-12-23 22:06:22 thib Exp $ */
+ /* $Id: option.h,v 1.20 2002-01-27 16:33:31 thib Exp $ */
/* This has been inspired from bitstring(3) : here is the original copyright :
*/
20 Should we remove a %-job from lavg queue if the interval is exceeded ?
21 Should user be mailed if a %-job has not run during a period ?
22 Should fcron log everything about this job or just errors ?
+ 23 Should this job be run asap, or randomly in its allowed interval of execution ?
*/
(_bit_clear(opt, 22))
+/*
+ bit 23 : set to 1 : run this job at a random time in its allowed interval of execution.
+ set to 0 : run this job asap (safer)
+*/
+#define is_random(opt) \
+ (_bit_test(opt, 23))
+#define set_random(opt) \
+ (_bit_set(opt, 23))
+#define clear_random(opt) \
+ (_bit_clear(opt, 23))
+
+
#endif /* __OPTIONH__ */