This repository has been archived on 2026-01-16. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
anacron/anacron-2.3-random.patch
Marcela Mašláňová e76c227507 - incorrect logging of jobs - fixed number of executed jobs
- really planed jobs are mentioned
- 252254 fix typo in bash script 0anacron
2009-02-19 14:06:19 +00:00

82 lines
2.5 KiB
Diff

diff -up anacron-2.3/main.c.random anacron-2.3/main.c
--- anacron-2.3/main.c.random 2009-02-16 10:27:46.000000000 +0100
+++ anacron-2.3/main.c 2009-02-16 10:27:46.000000000 +0100
@@ -24,6 +24,7 @@
#include <time.h>
+#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
@@ -430,6 +431,13 @@ main(int argc, char *argv[])
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];
diff -up anacron-2.3/readtab.c.random anacron-2.3/readtab.c
--- anacron-2.3/readtab.c.random 2009-02-16 10:27:46.000000000 +0100
+++ anacron-2.3/readtab.c 2009-02-16 10:30:05.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;
+
/* some definitions for the obstack macros */
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
@@ -144,6 +146,15 @@ register_env(const char *env_var, const
Debug(("on line %d: %s", line_num, er->assign));
}
+static int
+random_delay(int delay) {
+ int i = random();
+ double x = 0;
+
+ x = (double) i / (double) RAND_MAX * (double) delay;
+ return (int)x;
+}
+
static void
register_job(const char *periods, const char *delays,
const char *ident, char *command)
@@ -167,6 +178,8 @@ register_job(const char *periods, const
jr = obstack_alloc(&tab_o, sizeof(job_rec));
jr->period = period;
jr->named_period = 0;
+ if (RANDOM > 0)
+ delay += random_delay(RANDOM);
jr->delay = delay;
jr->tab_line = line_num;
jr->ident = obstack_alloc(&tab_o, ident_len + 1);
@@ -215,6 +228,8 @@ register_period_job(const char *periods,
anacrontab, line_num);
}
jr->period = 0;
+ if (RANDOM > 0)
+ delay += random_delay(RANDOM);
jr->delay = delay;
jr->tab_line = line_num;
jr->ident = obstack_alloc(&tab_o, ident_len + 1);
@@ -263,6 +278,10 @@ parse_tab_line(char *line)
r = match_rx("^([[:digit:]]+-[[:digit:]]+)$", value, 0);
if (r == -1) goto reg_invalid;
}
+ if (strncmp(env_var, "RANDOM_DELAY", 12) == NULL) {
+ r = match_rx("^([[:digit:]]+)$", value, 1);
+ RANDOM = atoi(value);
+ }
register_env(env_var, value);
return;
}