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-range.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

80 lines
2.2 KiB
Diff

diff -up anacron-2.3/readtab.c.range anacron-2.3/readtab.c
--- anacron-2.3/readtab.c.range 2009-02-16 10:20:08.000000000 +0100
+++ anacron-2.3/readtab.c 2009-02-16 10:25:15.000000000 +0100
@@ -258,6 +258,11 @@ parse_tab_line(char *line)
if (r == -1) goto reg_err;
if (r)
{
+ if (strcmp(env_var, "START_HOURS_RANGE") == 0)
+ {
+ r = match_rx("^([[:digit:]]+-[[:digit:]]+)$", value, 0);
+ if (r == -1) goto reg_invalid;
+ }
register_env(env_var, value);
return;
}
@@ -284,6 +289,7 @@ parse_tab_line(char *line)
return;
}
+ reg_invalid:
complain("Invalid syntax in %s on line %d - skipping this line",
anacrontab, line_num);
return;
diff -up anacron-2.3/runjob.c.range anacron-2.3/runjob.c
--- anacron-2.3/runjob.c.range 2009-02-16 10:20:08.000000000 +0100
+++ anacron-2.3/runjob.c 2009-02-16 10:20:08.000000000 +0100
@@ -34,8 +34,9 @@
#include <stdio.h>
#include <string.h>
#include "global.h"
-
+#include <time.h>
#include <langinfo.h>
+#include <fnmatch.h>
static int
temp_file(job_rec *jr)
@@ -236,14 +237,40 @@ launch_job(job_rec *jr)
int fd;
char hostname[512];
char *mailto;
-
+ char *limit;
+ char *from;
+ char *to;
+ time_t now;
+ struct tm *t;
/* get hostname */
if (gethostname(hostname, 512)) {
strcpy (hostname,"unknown machine");
}
setup_env(jr);
-
+
+ limit = getenv("START_HOURS_RANGE");
+ if (limit != NULL)
+ limit = strdup(limit);
+ if (limit != NULL)
+ {
+ time(&now);
+ t = localtime(&now);
+ if ((match_rx("^([[:digit:]]+)-([[:digit:]]+)$", limit, 2, &from, &to) == -1) ||
+ (from == NULL) || (to == NULL))
+ {
+ complain("START_HOURS_RANGE wasn't set correctly: %s", limit);
+ free(limit);
+ return;
+ }
+ if (!((atoi(from) < t->tm_hour) && (t->tm_hour < atoi(to))))
+ {
+ Debug(("Limit for start of job is set between %s and %s hours, which passed already.", from, to));
+ free(limit);
+ return;
+ }
+ free(limit);
+ }
/* Get the destination email address if set, or current user otherwise */
mailto = getenv("MAILTO");