summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authordillon <dillon@FreeBSD.org>1998-12-13 06:07:38 +0000
committerdillon <dillon@FreeBSD.org>1998-12-13 06:07:38 +0000
commitd2013aefd04d7ec6dcceccae50845084d5fe80e2 (patch)
tree830c2e85603a10295538ac72b3e06e1c2b0021cc /usr.sbin
parent7e32ff5f288ae9ec2a881fd11878793b858a037d (diff)
downloadFreeBSD-src-d2013aefd04d7ec6dcceccae50845084d5fe80e2.zip
FreeBSD-src-d2013aefd04d7ec6dcceccae50845084d5fe80e2.tar.gz
PR: bin/5572
Prevent cron from going crazy if the time steps. For example, if you have a system with hundreds of users and lots of different crontabs and your time steps back an hour, the old cron would then attempt to run an hours worth of cron jobs in a few seconds.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/cron/cron/cron.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/usr.sbin/cron/cron/cron.c b/usr.sbin/cron/cron/cron.c
index 2389c9b..ff90831 100644
--- a/usr.sbin/cron/cron/cron.c
+++ b/usr.sbin/cron/cron/cron.c
@@ -17,7 +17,7 @@
#if !defined(lint) && !defined(LINT)
static const char rcsid[] =
- "$Id: cron.c,v 1.6 1997/09/15 06:39:04 charnier Exp $";
+ "$Id: cron.c,v 1.7 1998/07/06 20:28:04 bde Exp $";
#endif
#define MAIN_PROGRAM
@@ -227,28 +227,40 @@ cron_sync() {
static void
cron_sleep() {
- register int seconds_to_wait;
+ int seconds_to_wait = 0;
- do {
+ /*
+ * Loop until we reach the top of the next minute, sleep when possible.
+ */
+
+ for (;;) {
seconds_to_wait = (int) (TargetTime - time((time_t*)0));
+
+ /*
+ * If the seconds_to_wait value is insane, jump the cron
+ */
+
+ if (seconds_to_wait < -600 || seconds_to_wait > 600) {
+ cron_sync();
+ continue;
+ }
+
Debug(DSCH, ("[%d] TargetTime=%ld, sec-to-wait=%d\n",
getpid(), (long)TargetTime, seconds_to_wait))
- /* if we intend to sleep, this means that it's finally
- * time to empty the job queue (execute it).
- *
- * if we run any jobs, we'll probably screw up our timing,
- * so go recompute.
- *
- * note that we depend here on the left-to-right nature
- * of &&, and the short-circuiting.
+ /*
+ * If we've run out of wait time or there are no jobs left
+ * to run, break
*/
- } while (seconds_to_wait > 0 && job_runqueue());
- while (seconds_to_wait > 0) {
- Debug(DSCH, ("[%d] sleeping for %d seconds\n",
- getpid(), seconds_to_wait))
- seconds_to_wait = (int) sleep((unsigned int) seconds_to_wait);
+ if (seconds_to_wait <= 0)
+ break;
+ if (job_runqueue() == 0) {
+ Debug(DSCH, ("[%d] sleeping for %d seconds\n",
+ getpid(), seconds_to_wait))
+
+ sleep(seconds_to_wait);
+ }
}
}
OpenPOWER on IntegriCloud