rpms/anacron/devel anacron-2.3-random.patch, NONE, 1.1 anacron-2.3-range.patch, NONE, 1.1 manAUX_Limit.patch, NONE, 1.1 anacron.spec, 1.57, 1.58 anacrontab, 1.5, 1.6 sources, 1.4, 1.5 anacron-2.3-hourly.patch, 1.2, NONE hourly.patch, 1.1, NONE

Marcela Mašláňová mmaslano at fedoraproject.org
Fri Feb 6 14:08:37 UTC 2009


Author: mmaslano

Update of /cvs/pkgs/rpms/anacron/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv19178

Modified Files:
	anacron.spec anacrontab sources 
Added Files:
	anacron-2.3-random.patch anacron-2.3-range.patch 
	manAUX_Limit.patch 
Removed Files:
	anacron-2.3-hourly.patch hourly.patch 
Log Message:
* Fri Feb  6 2009 Marcela Mašláňová <mmaslano at redhat.com> 2.3-68
- add two new options:
- 481775 some people don't want to run daily jobs at all, if they
 didn't run in specific time f.e. 4-7 hours.
- 470168 random delay was removed from crontabs and added into
 anacron, where could be better set.
- cron.d/0hourly will every hour run cron.hourly/0anacron which
 check whether the jobs should be running or not


anacron-2.3-random.patch:

--- NEW FILE anacron-2.3-random.patch ---
diff -up anacron-2.3/main.c.aux anacron-2.3/main.c
--- anacron-2.3/main.c.aux	2009-02-06 12:58:17.000000000 +0100
+++ anacron-2.3/main.c	2009-02-06 12:59:44.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.aux anacron-2.3/readtab.c
--- anacron-2.3/readtab.c.aux	2009-02-06 12:58:17.000000000 +0100
+++ anacron-2.3/readtab.c	2009-02-06 12:58:17.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);
@@ -257,7 +272,10 @@ parse_tab_line(char *line)
 		 &env_var, &value);
     if ((r != -1) && (strcmp(env_var, "START_HOURS_RANGE") == NULL))
         r = match_rx("^([[:digit:]]+)-([[:digit:]]+)$", value, 0);
-
+    if (strncmp(env_var, "RANDOM_DELAY", 12) == NULL) {
+        r = match_rx("([[:digit:]]+)$", value, 1);
+        RANDOM = atoi(value);
+    }
     if (r == -1) goto reg_err;
     if (r)
     {

anacron-2.3-range.patch:

--- NEW FILE anacron-2.3-range.patch ---
diff -up anacron-2.3/readtab.c.range anacron-2.3/readtab.c
--- anacron-2.3/readtab.c.range	2009-02-06 13:04:08.000000000 +0100
+++ anacron-2.3/readtab.c	2009-02-06 13:05:13.000000000 +0100
@@ -255,6 +255,9 @@ parse_tab_line(char *line)
     /* an environment assignment? */
     r = match_rx("^[ \t]*([^ \t=]+)[ \t]*=(.*)$", line, 2,
 		 &env_var, &value);
+    if ((r != -1) && (strcmp(env_var, "START_HOURS_RANGE") == NULL))
+        r = match_rx("^([[:digit:]]+)-([[:digit:]]+)$", value, 0);
+
     if (r == -1) goto reg_err;
     if (r)
     {
diff -up anacron-2.3/runjob.c.range anacron-2.3/runjob.c
--- anacron-2.3/runjob.c.range	2009-02-06 13:04:08.000000000 +0100
+++ anacron-2.3/runjob.c	2009-02-06 13:11:42.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,31 @@ launch_job(job_rec *jr)
     int fd;
     char hostname[512];
     char *mailto;
-
+    char *limit;
+    char *from;
+    char *to;
+    time_t now;
+    struct tm t;
+    int len;
     /* get hostname */
     if (gethostname(hostname, 512)) {
       strcpy (hostname,"unknown machine");
     }
 
     setup_env(jr);
-   
+
+    limit = getenv("START_HOURS_RANGE");
+    time(&now);
+    t = *localtime(&now);
+    if (limit != NULL) {
+        if ((match_rx("^([[:digit:]]+)-([[:digit:]]+)$", limit, 2, &from, &to) == -1) ||
+           (from == NULL) || (to == NULL))
+            explain("START_HOURS_RANGE wasn't set correctly: %s", limit);
+        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));
+            return 1;
+        }
+    }
     /* Get the destination email address if set, or current user otherwise */
     mailto = getenv("MAILTO");
 

manAUX_Limit.patch:

--- NEW FILE manAUX_Limit.patch ---
diff -up anacron-2.3/anacrontab.5.mmm anacron-2.3/anacrontab.5
--- anacron-2.3/anacrontab.5.mmm	2009-02-04 14:40:29.000000000 +0100
+++ anacron-2.3/anacrontab.5	2009-02-04 14:56:56.000000000 +0100
@@ -1,4 +1,4 @@
-.TH ANACRONTAB 5 2004-07-11 "Pascal Hakim" "Anacron Users' Manual"
+.TH ANACRONTAB 5 2009-02-02 "Marcela Mašláňová" "Anacron Users' Manual"
 .SH NAME
 /etc/anacrontab \- configuration file for anacron
 .SH DESCRIPTION
@@ -19,7 +19,11 @@ The
 .I period
 is specified in days, the
 .I delay
-in minutes.  The
+in minutes. It could be also defined random delay which is set by value of
+.I RANDOM_DELAY
+. The value in this variable denotes maximal delay. 
+The random delay is added to normal delay from anacrontab. Also the random delay could
+be set to zero or not set at all. The
 .I job-identifier
 can contain any non-blank character, except slashes.  It is used to identify
 the job in Anacron messages,
@@ -42,12 +46,28 @@ are removed.  No spaces around
 .I VALUE
 are allowed (unless you want them to be part of the value).  The assignment
 takes effect from the next line to the end of the file, or to the next
-assignment of the same variable.
+assignment of the same variable. The enviroment variable 
+.I START_HOURS_RANGE
+sets the time frame, when the job could started.
 .PP
 Empty lines are either blank lines, line containing white-space only, or
 lines with white-space followed by a '#' followed by an arbitrary comment.
 .PP
 You can continue a line onto the next line by ending it with a '\'.
+.SH EXAMPLE
+.nf
+# environment variable
+SHELL=/bin/sh
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+MAILTO=root
+RANDOM_DELAY=60
+# Anacron jobs will start between 6 and 8 o'clock.
+START_HOURS_RANGE=6-8
+# delay will be 5 minutes + RANDOM_DELAY for cron.daily
+1		5	cron.daily		nice run-parts /etc/cron.daily
+7		8	cron.weekly		nice run-parts /etc/cron.weekly
+ at monthly	35	cron.monthly		nice run-parts /etc/cron.monthly
+.fi
 .SH "SEE ALSO"
 .B anacron(8)
 .PP


Index: anacron.spec
===================================================================
RCS file: /cvs/pkgs/rpms/anacron/devel/anacron.spec,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- anacron.spec	28 Jan 2009 12:34:43 -0000	1.57
+++ anacron.spec	6 Feb 2009 14:08:07 -0000	1.58
@@ -1,22 +1,23 @@
 Summary: A cron-like program that can run jobs lost during downtime
 Name: anacron
 Version: 2.3
-Release: 67%{?dist}
+Release: 68%{?dist}
 License: GPLv2+
 Group: System Environment/Base
 URL: http://packages.debian.org/stable/source/anacron
 Source: http://ftp.debian.org/debian/pool/main/a/anacron/%{name}_%{version}.orig.tar.gz
 Source1: anacrontab
-Source2: anacron.init
-Source3: 0hourly
+Source2: 0hourly
+Source3: anacron
 Patch1: anacron_2.3-13.patch
 Patch2: anacron-2.3-mail-content-type-77108.patch
 Patch3: anacron-2.3-fdclose.patch
 Patch4: anacron-2.3-pic.patch
 Patch5: anacron-2.3-memleaking.patch
 Patch6: anacron-2.3-spooldir.patch
-Patch7: anacron-2.3-hourly.patch
-Patch8: hourly.patch
+Patch7: anacron-2.3-range.patch
+Patch8: anacron-2.3-random.patch
+Patch9: manAUX_Limit.patch
 
 Requires: crontabs
 Requires: initscripts
@@ -49,8 +50,9 @@
 %patch4 -p1 -b .pic
 %patch5 -p1 -b .memleaking
 %patch6 -p1 -b .spool
-%patch7 -p1
-%patch8 -p1
+%patch7 -p1 -b .range
+%patch8 -p1 -b .random
+%patch9 -p1
 
 %build
 make CFLAGS="$RPM_OPT_FLAGS" %{?_smp_mflags}
@@ -69,53 +71,34 @@
 mkdir -p $RPM_BUILD_ROOT/etc/$i/
 done
 
-#install -m755 fedora/anacron.daily $RPM_BUILD_ROOT/etc/cron.daily/0anacron
-#ln -s ../cron.daily/0anacron $RPM_BUILD_ROOT/etc/cron.weekly/0anacron
-#ln -s ../cron.daily/0anacron $RPM_BUILD_ROOT/etc/cron.monthly/0anacron
-install -m755 fedora/anacron.hourly $RPM_BUILD_ROOT/etc/cron.hourly/0anacron
-
-mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d/
-install -c -m755 %SOURCE2 $RPM_BUILD_ROOT/etc/rc.d/init.d/anacron
-
 mkdir -p $RPM_BUILD_ROOT/etc/cron.d/
-install -c -m755 %SOURCE3 $RPM_BUILD_ROOT/etc/cron.d/0hourly
+install -c -m755 %SOURCE2 $RPM_BUILD_ROOT/etc/cron.d/0hourly
+install -c -m755 %SOURCE3 $RPM_BUILD_ROOT/etc/cron.hourly/0anacron
 
-%clean 
+%clean
 rm -rf $RPM_BUILD_ROOT
 
-%post
-/sbin/chkconfig  --add anacron
-if [ "$1" -ge 1 ]; then
-	/sbin/chkconfig --level 2345 anacron resetpriorities
-fi
-
-%preun
-if [ "$1" = "0" ]; then
-	service anacron stop >/dev/null 2>&1 ||:
-	/sbin/chkconfig --del anacron
-fi
-
-%postun
-if [ "$1" -ge "1" ]; then
-	service anacron condrestart >/dev/null 2>&1 ||:
-fi
-
 %files
 %defattr(-,root,root,0755)
 %doc COPYING README
 %config(noreplace) /etc/anacrontab
 %dir /var/spool/anacron/
-%dir /etc/rc.d/init.d/*
 %{_mandir}/man5/*
 %{_mandir}/man8/*
 /usr/sbin/anacron
-%dir /etc/cron.hourly/0anacron
 %attr(644,root,root) /etc/cron.d/0hourly
-#%dir /etc/cron.daily/0anacron
-#%dir /etc/cron.weekly/0anacron
-#%dir /etc/cron.monthly/0anacron
+%attr(755,root,root) /etc/cron.hourly/0anacron
 
 %changelog
+* Fri Feb  6 2009 Marcela Mašláňová <mmaslano at redhat.com> 2.3-68
+- add two new options:
+- 481775 some people don't want to run daily jobs at all, if they
+ didn't run in specific time f.e. 4-7 hours.
+- 470168 random delay was removed from crontabs and added into
+ anacron, where could be better set.
+- cron.d/0hourly will every hour run cron.hourly/0anacron which
+ check whether the jobs should be running or not
+
 * Thu Jan 28 2009 Marcela Mašláňová <mmaslano at redhat.com> 2.3-67
 - 482782 output in init script redirected
 


Index: anacrontab
===================================================================
RCS file: /cvs/pkgs/rpms/anacron/devel/anacrontab,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- anacrontab	9 Aug 2007 13:25:22 -0000	1.5
+++ anacrontab	6 Feb 2009 14:08:07 -0000	1.6
@@ -5,7 +5,11 @@
 SHELL=/bin/sh
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 MAILTO=root
+# the maximal random delay
+RANDOM_DELAY=45
+# in between this hours will started daily jobs
+#START_HOURS_RANGE=3-22
 
-1	 65	cron.daily		nice run-parts /etc/cron.daily
-7	 70	cron.weekly		nice run-parts /etc/cron.weekly
- at monthly 75	cron.monthly		nice run-parts /etc/cron.monthly
+1	5	cron.daily		nice run-parts /etc/cron.daily
+7	25	cron.weekly		nice run-parts /etc/cron.weekly
+ at monthly 45	cron.monthly		nice run-parts /etc/cron.monthly


Index: sources
===================================================================
RCS file: /cvs/pkgs/rpms/anacron/devel/sources,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- sources	26 Jan 2009 09:25:53 -0000	1.4
+++ sources	6 Feb 2009 14:08:07 -0000	1.5
@@ -1,3 +1,3 @@
 9fdfc50f5741643332722a9145146278  anacron_2.3.orig.tar.gz
-094af5e05723d2c4924d60f73d738509  anacron.init
 e354dcd88554723abd476f069c90069d  0hourly
+489b434e72a434ead53efc941330cb59  anacron


--- anacron-2.3-hourly.patch DELETED ---


--- hourly.patch DELETED ---




More information about the scm-commits mailing list