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