199 lines
5.9 KiB
Diff
199 lines
5.9 KiB
Diff
diff -up anacron-2.3.new/main.c.range-rnd anacron-2.3.new/main.c
|
|
--- anacron-2.3.new/main.c.range-rnd 2009-03-24 10:12:23.000000000 +0100
|
|
+++ anacron-2.3.new/main.c 2009-03-24 12:01:24.000000000 +0100
|
|
@@ -24,6 +24,7 @@
|
|
|
|
|
|
#include <time.h>
|
|
+#include <sys/time.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <signal.h>
|
|
@@ -31,6 +32,7 @@
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <string.h>
|
|
+#include <stdlib.h>
|
|
#include "global.h"
|
|
#include "gregor.h"
|
|
|
|
@@ -56,6 +58,8 @@ env_rec *first_env_rec;
|
|
static time_t start_sec; /* time anacron started */
|
|
static volatile int got_sigalrm, got_sigchld, got_sigusr1;
|
|
int running_jobs, running_mailers; /* , number of */
|
|
+int range_start = -1;
|
|
+int range_stop = -1;
|
|
|
|
static void
|
|
print_version()
|
|
@@ -402,6 +406,7 @@ static void
|
|
explain_intentions()
|
|
{
|
|
int j;
|
|
+ struct tm *t;
|
|
|
|
j = 0;
|
|
while (j < njobs)
|
|
@@ -412,8 +417,21 @@ explain_intentions()
|
|
}
|
|
else
|
|
{
|
|
- explain("Will run job `%s' in %d min.",
|
|
+ time_t jobtime = start_sec + job_array[j]->delay * 60;
|
|
+
|
|
+ t = localtime(&jobtime);
|
|
+ if (range_start != -1 && range_stop != -1 &&
|
|
+ (t->tm_hour < range_start || t->tm_hour >= range_stop))
|
|
+ {
|
|
+ Debug(("The job `%s' falls out of the %02d:00-%02d:00 hours range, skipping.",
|
|
+ job_array[j]->ident, range_start, range_stop));
|
|
+ job_array[j]->drop_job = 1;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ explain("Will run job `%s' in %d min.",
|
|
job_array[j]->ident, job_array[j]->delay);
|
|
+ }
|
|
}
|
|
j++;
|
|
}
|
|
@@ -428,8 +446,17 @@ main(int argc, char *argv[])
|
|
|
|
int cwd;
|
|
|
|
+ int dropped_jobs = 0;
|
|
+
|
|
anacrontab = NULL;
|
|
spooldir = NULL;
|
|
+ struct timeval tv;
|
|
+ struct timezone tz;
|
|
+
|
|
+ if (gettimeofday(&tv, &tz) != 0)
|
|
+ explain("Can't get exact time, failure.");
|
|
+
|
|
+ srandom(getpid()+tv.tv_usec);
|
|
|
|
if((program_name = strrchr(argv[0], '/')) == NULL)
|
|
program_name = argv[0];
|
|
@@ -486,11 +513,16 @@ main(int argc, char *argv[])
|
|
running_jobs = running_mailers = 0;
|
|
for(j = 0; j < njobs; ++j)
|
|
{
|
|
+ if (job_array[j]->drop_job == 1)
|
|
+ {
|
|
+ ++dropped_jobs;
|
|
+ continue;
|
|
+ }
|
|
xsleep(time_till(job_array[j]));
|
|
if (serialize) wait_jobs();
|
|
launch_job(job_array[j]);
|
|
}
|
|
wait_children();
|
|
- explain("Normal exit (%d job%s run)", njobs, (njobs == 1 ? "" : "s"));
|
|
+ explain("Normal exit (%d job%s run)", njobs-dropped_jobs, (njobs-dropped_jobs == 1 ? "" : "s"));
|
|
exit(0);
|
|
}
|
|
diff -up anacron-2.3.new/global.h.range-rnd anacron-2.3.new/global.h
|
|
--- anacron-2.3.new/global.h.range-rnd 2009-03-24 10:12:23.000000000 +0100
|
|
+++ anacron-2.3.new/global.h 2009-03-24 12:01:10.000000000 +0100
|
|
@@ -68,6 +68,7 @@ struct job_rec1 {
|
|
int mail_header_size;
|
|
pid_t job_pid;
|
|
pid_t mailer_pid;
|
|
+ int drop_job;
|
|
|
|
struct job_rec1 *next;
|
|
env_rec *prev_env_rec;
|
|
@@ -100,6 +101,10 @@ extern int running_jobs,running_mailers;
|
|
|
|
extern int complaints;
|
|
|
|
+/* time ranges for START_HOURS_RANGE */
|
|
+extern int range_start;
|
|
+extern int range_stop;
|
|
+
|
|
/* Function prototypes */
|
|
|
|
/* main.c */
|
|
diff -up anacron-2.3.new/log.c.range-rnd anacron-2.3.new/log.c
|
|
--- anacron-2.3.new/log.c.range-rnd 2009-03-24 10:12:23.000000000 +0100
|
|
+++ anacron-2.3.new/log.c 2009-03-24 12:01:56.000000000 +0100
|
|
@@ -43,6 +43,7 @@
|
|
#include <signal.h>
|
|
#include <sys/types.h>
|
|
#include <string.h>
|
|
+#include <stdlib.h>
|
|
#include "global.h"
|
|
|
|
static char truncated[] = " (truncated)";
|
|
diff -up anacron-2.3.new/readtab.c.range-rnd anacron-2.3.new/readtab.c
|
|
--- anacron-2.3.new/readtab.c.range-rnd 2009-03-24 10:12:23.000000000 +0100
|
|
+++ anacron-2.3.new/readtab.c 2009-03-24 11:51:08.000000000 +0100
|
|
@@ -48,6 +48,8 @@ static int line_num; /* curr
|
|
static job_rec *last_job_rec; /* last job stored in memory, at the moment */
|
|
static env_rec *last_env_rec; /* last environment assignment stored */
|
|
|
|
+static int random_number = 0;
|
|
+
|
|
/* some definitions for the obstack macros */
|
|
#define obstack_chunk_alloc xmalloc
|
|
#define obstack_chunk_free free
|
|
@@ -167,6 +169,7 @@ register_job(const char *periods, const
|
|
jr = obstack_alloc(&tab_o, sizeof(job_rec));
|
|
jr->period = period;
|
|
jr->named_period = 0;
|
|
+ delay += random_number;
|
|
jr->delay = delay;
|
|
jr->tab_line = line_num;
|
|
jr->ident = obstack_alloc(&tab_o, ident_len + 1);
|
|
@@ -215,6 +218,7 @@ register_period_job(const char *periods,
|
|
anacrontab, line_num);
|
|
}
|
|
jr->period = 0;
|
|
+ delay += random_number;
|
|
jr->delay = delay;
|
|
jr->tab_line = line_num;
|
|
jr->ident = obstack_alloc(&tab_o, ident_len + 1);
|
|
@@ -242,6 +246,8 @@ parse_tab_line(char *line)
|
|
char *delays;
|
|
char *ident;
|
|
char *command;
|
|
+ char *from;
|
|
+ char *to;
|
|
|
|
/* an empty line? */
|
|
r = match_rx("^[ \t]*($|#)", line, 0);
|
|
@@ -258,6 +264,25 @@ parse_tab_line(char *line)
|
|
if (r == -1) goto reg_err;
|
|
if (r)
|
|
{
|
|
+ if (strncmp(env_var, "START_HOURS_RANGE", 17) == 0)
|
|
+ {
|
|
+ r = match_rx("^([[:digit:]]+)-([[:digit:]]+)$", value, 2, &from, &to);
|
|
+ if ((r == -1) || (from == NULL) || (to == NULL)) goto reg_invalid;
|
|
+ range_start = atoi(from);
|
|
+ range_stop = atoi(to);
|
|
+ Debug(("Jobs will start in the %02d:00-%02d:00 range.", range_start, range_stop));
|
|
+ }
|
|
+ if (strncmp(env_var, "RANDOM_DELAY", 12) == 0) {
|
|
+ r = match_rx("^([[:digit:]]+)$", value, 1);
|
|
+ if (r != -1) {
|
|
+ int i = random();
|
|
+ double x = 0;
|
|
+ x = (double) i / (double) RAND_MAX * (double) (atoi(value));
|
|
+ random_number = (int)x;
|
|
+ Debug(("Randomized delay set: %d", random_number));
|
|
+ }
|
|
+ else goto reg_invalid;
|
|
+ }
|
|
register_env(env_var, value);
|
|
return;
|
|
}
|
|
@@ -284,6 +309,7 @@ parse_tab_line(char *line)
|
|
return;
|
|
}
|
|
|
|
+ reg_invalid:
|
|
complain("Invalid syntax in %s on line %d - skipping this line",
|
|
anacrontab, line_num);
|
|
return;
|