afedbd3
afedbd3
 This patch should fix bug #812 where the DST time shift was 
afedbd3
 incorrectly handled. This patch was submitted by Martin Simmons.
afedbd3
 Apply it to Bacula version 2.0.3 with:
afedbd3
afedbd3
  cd <bacula-source>
afedbd3
  patch -p0 <2.0.3-scheduler-next-hour.patch
afedbd3
  make
afedbd3
  ...
afedbd3
  make install
afedbd3
afedbd3
Index: src/dird/scheduler.c
afedbd3
===================================================================
afedbd3
--- src/dird/scheduler.c	(revision 4445)
afedbd3
+++ src/dird/scheduler.c	(working copy)
afedbd3
@@ -175,11 +175,11 @@
afedbd3
       }
afedbd3
       /* Recheck at least once per minute */
afedbd3
       bmicrosleep((next_check_secs < twait)?next_check_secs:twait, 0);
afedbd3
-      /* Attempt to handle clock shift from/to daylight savings time
afedbd3
+      /* Attempt to handle clock shift (but not daylight savings time changes)
afedbd3
        * we allow a skew of 10 seconds before invalidating everything.
afedbd3
        */
afedbd3
       now = time(NULL);
afedbd3
-      if (now < prev+10 || now > (prev+next_check_secs+10)) {
afedbd3
+      if (now < prev-10 || now > (prev+next_check_secs+10)) {
afedbd3
          schedules_invalidated = true;
afedbd3
       }
afedbd3
    }
afedbd3
@@ -284,6 +284,9 @@
afedbd3
    wom = mday / 7;
afedbd3
    woy = tm_woy(now);                     /* get week of year */
afedbd3
 
afedbd3
+   Dmsg7(dbglvl, "now = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
afedbd3
+	 now, hour, month, mday, wday, wom, woy);
afedbd3
+
afedbd3
    /*
afedbd3
     * Compute values for next hour from now.
afedbd3
     * We do this to be sure we don't miss a job while
afedbd3
@@ -299,6 +302,9 @@
afedbd3
    nh_wom = nh_mday / 7;
afedbd3
    nh_woy = tm_woy(now);                     /* get week of year */
afedbd3
 
afedbd3
+   Dmsg7(dbglvl, "nh = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
afedbd3
+	 next_hour, nh_hour, nh_month, nh_mday, nh_wday, nh_wom, nh_woy);
afedbd3
+
afedbd3
    /* Loop through all jobs */
afedbd3
    LockRes();
afedbd3
    foreach_res(job, R_JOB) {
afedbd3
@@ -351,24 +357,20 @@
afedbd3
 
afedbd3
          Dmsg3(dbglvl, "run@%p: run_now=%d run_nh=%d\n", run, run_now, run_nh);
afedbd3
 
afedbd3
-         /* find time (time_t) job is to be run */
afedbd3
-         (void)localtime_r(&now, &tm;;      /* reset tm structure */
afedbd3
-         tm.tm_min = run->minute;     /* set run minute */
afedbd3
-         tm.tm_sec = 0;               /* zero secs */
afedbd3
-         if (run_now) {
afedbd3
-            runtime = mktime(&tm;;
afedbd3
-            add_job(job, run, now, runtime);
afedbd3
-         }
afedbd3
-         /* If job is to be run in the next hour schedule it */
afedbd3
-         if (run_nh) {
afedbd3
-            /* Set correct values */
afedbd3
-            tm.tm_hour = nh_hour;
afedbd3
-            tm.tm_mday = nh_mday + 1; /* fixup because we biased for tests above */
afedbd3
-            tm.tm_mon = nh_month;
afedbd3
-            tm.tm_year = nh_year;
afedbd3
-            runtime = mktime(&tm;;
afedbd3
-            add_job(job, run, now, runtime);
afedbd3
-         }
afedbd3
+	 if (run_now || run_nh) {
afedbd3
+	   /* find time (time_t) job is to be run */
afedbd3
+	   (void)localtime_r(&now, &tm;;      /* reset tm structure */
afedbd3
+	   tm.tm_min = run->minute;     /* set run minute */
afedbd3
+	   tm.tm_sec = 0;               /* zero secs */
afedbd3
+	   runtime = mktime(&tm;;
afedbd3
+	   if (run_now) {
afedbd3
+	     add_job(job, run, now, runtime);
afedbd3
+	   }
afedbd3
+	   /* If job is to be run in the next hour schedule it */
afedbd3
+	   if (run_nh) {
afedbd3
+	     add_job(job, run, now, runtime + 3600);
afedbd3
+	   }
afedbd3
+	 }
afedbd3
       }
afedbd3
    }
afedbd3
    UnlockRes();