see
.BR crontab (1)\ -s\ option.
.PP
+The
+.I RANDOM_DELAY
+variable allows delaying job startups by random amount of minutes with
+upper limit specified by the variable. The random scaling factor is
+determined during the cron daemon startup so it remains constant for
+the whole run time of the daemon.
+.PP
The format of a cron command is similar to the V7 standard, with a number
of upward-compatible extensions. Each line has five time-and-date fields
followed by a
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <sys/time.h>
#ifdef WITH_INOTIFY
# include <sys/inotify.h>
char *cs;
pid_t pid = getpid();
long oldGMToff;
+ struct timeval tv;
+ struct timezone tz;
+ char buf[256];
if ((ProgramName=strrchr(argv[0], '/')) == NULL) {
ProgramName = argv[0];
}
pid = getpid();
+
+ /* obtain a random scaling factor for RANDOM_DELAY */
+ if (gettimeofday(&tv, &tz) != 0)
+ tv.tv_usec = 0;
+ srandom(pid + tv.tv_usec);
+ RandomScale = random() / (double)RAND_MAX;
+ snprintf(buf, sizeof(buf), "RANDOM_DELAY will be scaled with factor %d%% if used.", (int)(RandomScale*100));
+ log_it("CRON", pid, "INFO", buf, 0);
+
acquire_daemonlock(0);
database.head = NULL;
database.tail = NULL;
static void find_jobs(int vtime, cron_db * db, int doWild, int doNonWild, long vGMToff) {
char *orig_tz, *job_tz;
- time_t virtualSecond = vtime * SECONDS_PER_MINUTE;
- time_t virtualGMTSecond = virtualSecond - vGMToff;
struct tm *tm;
int minute, hour, dom, month, dow;
user *u;
} while (0)
orig_tz = getenv("TZ");
- maketime(NULL, orig_tz);
- Debug(DSCH, ("[%ld] tick(%d,%d,%d,%d,%d) %s %s\n",
- (long) getpid(), minute, hour, dom, month, dow,
- doWild ? " " : "No wildcard", doNonWild ? " " : "Wildcard only"));
/* the dom/dow situation is odd. '* * 1,15 * Sun' will run on the
* first and fifteenth AND every Sunday; '* * * * Sun' will run *only*
* on Sundays; '* * 1,15 * *' will run *only* the 1st and 15th. this
uname = e->pwd->pw_name;
/* check if user exists in time of job is being run f.e. ldap */
if (getpwnam(uname) != NULL) {
+ time_t virtualSecond = (vtime - e->delay) * SECONDS_PER_MINUTE;
+ time_t virtualGMTSecond = virtualSecond - vGMToff;
job_tz = env_get("CRON_TZ", e->envp);
maketime(job_tz, orig_tz);
/* here we test whether time is NOW */
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
+#include <errno.h>
#include "bitstring.h"
#include "funcs.h"
char cmd[MAX_COMMAND];
char envstr[MAX_ENVSTR];
char **tenvp;
+ char *p;
Debug(DPARS, ("load_entry()...about to eat comments\n"));
}
memset(e->pwd->pw_passwd, 0, strlen(e->pwd->pw_passwd));
+ p = env_get("RANDOM_DELAY", envp);
+ if (p) {
+ char *endptr;
+ long val;
+
+ errno = 0; /* To distinguish success/failure after call */
+ val = strtol(p, &endptr, 10);
+ if (errno != 0 || val < 0 || val > 24*60) {
+ log_it("CRON", getpid(), "ERROR", "bad value of RANDOM_DELAY", 0);
+ } else {
+ e->delay = val * RandomScale;
+ }
+ }
+
/* copy and fix up environment. some variables are just defaults and
* others are overrides.
*/