]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/scheduler.c
kes Fix %g in filename returned by SQL for browse tree reported by
[bacula/bacula] / bacula / src / dird / scheduler.c
index 498bef71f7f20c817ccbfd2b897a972b557aadc7..0e888a7c128708033949faa0443bed4205bc24a0 100644 (file)
@@ -1,3 +1,30 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 /*
  *
  *   Bacula scheduler
@@ -9,20 +36,6 @@
  *
  *   Version $Id$
  */
-/*
-   Copyright (C) 2000-2006 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-   the file LICENSE for additional details.
-
- */
 
 #include "bacula.h"
 #include "dird.h"
@@ -162,11 +175,11 @@ again:
       }
       /* Recheck at least once per minute */
       bmicrosleep((next_check_secs < twait)?next_check_secs:twait, 0);
-      /* Attempt to handle clock shift from/to daylight savings time
+      /* Attempt to handle clock shift (but not daylight savings time changes)
        * we allow a skew of 10 seconds before invalidating everything.
        */
       now = time(NULL);
-      if (now < prev+10 || now > (prev+next_check_secs+10)) {
+      if (now < prev-10 || now > (prev+next_check_secs+10)) {
          schedules_invalidated = true;
       }
    }
@@ -205,7 +218,10 @@ again:
       jcr->run_diff_pool_override = true;
    }
    if (run->storage) {
-      set_storage(jcr, run->storage); /* override storage */
+      USTORE store;
+      store.store = run->storage;
+      pm_strcpy(store.store_source, _("run override"));
+      set_rwstorage(jcr, &store);     /* override storage */
    }
    if (run->msgs) {
       jcr->messages = run->msgs;      /* override messages */
@@ -259,7 +275,7 @@ static void find_runs()
 
    /* compute values for time now */
    now = time(NULL);
-   localtime_r(&now, &tm);
+   (void)localtime_r(&now, &tm);
    hour = tm.tm_hour;
    minute = tm.tm_min;
    mday = tm.tm_mday - 1;
@@ -268,13 +284,16 @@ static void find_runs()
    wom = mday / 7;
    woy = tm_woy(now);                     /* get week of year */
 
+   Dmsg7(dbglvl, "now = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
+        now, hour, month, mday, wday, wom, woy);
+
    /*
     * Compute values for next hour from now.
     * We do this to be sure we don't miss a job while
     * sleeping.
     */
    next_hour = now + 3600;
-   localtime_r(&next_hour, &tm);
+   (void)localtime_r(&next_hour, &tm);
    nh_hour = tm.tm_hour;
    nh_mday = tm.tm_mday - 1;
    nh_wday = tm.tm_wday;
@@ -283,6 +302,9 @@ static void find_runs()
    nh_wom = nh_mday / 7;
    nh_woy = tm_woy(now);                     /* get week of year */
 
+   Dmsg7(dbglvl, "nh = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
+        next_hour, nh_hour, nh_month, nh_mday, nh_wday, nh_wom, nh_woy);
+
    /* Loop through all jobs */
    LockRes();
    foreach_res(job, R_JOB) {
@@ -335,24 +357,20 @@ static void find_runs()
 
          Dmsg3(dbglvl, "run@%p: run_now=%d run_nh=%d\n", run, run_now, run_nh);
 
-         /* find time (time_t) job is to be run */
-         localtime_r(&now, &tm);      /* reset tm structure */
-         tm.tm_min = run->minute;     /* set run minute */
-         tm.tm_sec = 0;               /* zero secs */
-         if (run_now) {
-            runtime = mktime(&tm);
-            add_job(job, run, now, runtime);
-         }
-         /* If job is to be run in the next hour schedule it */
-         if (run_nh) {
-            /* Set correct values */
-            tm.tm_hour = nh_hour;
-            tm.tm_mday = nh_mday + 1; /* fixup because we biased for tests above */
-            tm.tm_mon = nh_month;
-            tm.tm_year = nh_year;
-            runtime = mktime(&tm);
-            add_job(job, run, now, runtime);
-         }
+        if (run_now || run_nh) {
+          /* find time (time_t) job is to be run */
+          (void)localtime_r(&now, &tm);      /* reset tm structure */
+          tm.tm_min = run->minute;     /* set run minute */
+          tm.tm_sec = 0;               /* zero secs */
+          runtime = mktime(&tm);
+          if (run_now) {
+            add_job(job, run, now, runtime);
+          }
+          /* If job is to be run in the next hour schedule it */
+          if (run_nh) {
+            add_job(job, run, now, runtime + 3600);
+          }
+        }
       }
    }
    UnlockRes();