]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/scheduler.c
ebl Try to fix bug on RunScript {} resource parsing
[bacula/bacula] / bacula / src / dird / scheduler.c
index 8dc27249f3c3ef2d4c8887d46147db15ac91a8e9..684e694520830d475b9d9c03f3f74ad6c3d7c9ff 100644 (file)
@@ -50,7 +50,7 @@ struct job_item {
 static dlist *jobs_to_run;               /* list of jobs to be run */
 
 /* Time interval in secs to sleep if nothing to be run */
-static int const NEXT_CHECK_SECS = 60;
+static int const next_check_secs = 60;
 
 /* Forward referenced subroutines */
 static void find_runs();
@@ -85,7 +85,7 @@ JCR *wait_for_next_job(char *one_shot_job_to_run)
    JCR *jcr;
    JOB *job;
    RUN *run;
-   time_t now;
+   time_t now, prev;
    static bool first = true;
    job_item *next_job = NULL;
 
@@ -114,7 +114,7 @@ again:
       if (!jobs_to_run->empty()) {
          break;
       }
-      bmicrosleep(NEXT_CHECK_SECS, 0); /* recheck once per minute */
+      bmicrosleep(next_check_secs, 0); /* recheck once per minute */
    }
 
 #ifdef  list_chain
@@ -139,7 +139,9 @@ again:
    /* Now wait for the time to run the job */
    for (;;) {
       time_t twait;
-      if (schedules_invalidated) { /** discard scheduled queue and rebuild with new schedule objects. **/
+      /** discard scheduled queue and rebuild with new schedule objects. **/
+      lock_jobs();
+      if (schedules_invalidated) { 
           dump_job(next_job, "Invalidated job");
           free(next_job);
           while (!jobs_to_run->empty()) {
@@ -149,15 +151,26 @@ again:
               free(next_job);
           }
           schedules_invalidated = false;
+          unlock_jobs();
           goto again;
       }
-      now = time(NULL);
+      unlock_jobs();
+      prev = now = time(NULL);
       twait = next_job->runtime - now;
       if (twait <= 0) {               /* time to run it */
          break;
       }
-      bmicrosleep((NEXT_CHECK_SECS<twait)?NEXT_CHECK_SECS:twait, 0); /* recheck at least once per minute */      
+      /* 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
+       * we allow a skew of 10 seconds before invalidating everything.
+       */
+      now = time(NULL);
+      if (now < prev+10 || now > (prev+next_check_secs+10)) {
+         schedules_invalidated = true;
+      }
    }
+   jcr = new_jcr(sizeof(JCR), dird_free_jcr);
    run = next_job->run;               /* pick up needed values */
    job = next_job->job;
    if (job->enabled) {
@@ -165,11 +178,11 @@ again:
    }
    free(next_job);
    if (!job->enabled) {
+      free_jcr(jcr);
       goto again;                     /* ignore this job */
    }
    run->last_run = now;               /* mark as run now */
 
-   jcr = new_jcr(sizeof(JCR), dird_free_jcr);
    ASSERT(job);
    set_jcr_defaults(jcr, job);
    if (run->level) {
@@ -177,18 +190,22 @@ again:
    }
    if (run->pool) {
       jcr->pool = run->pool;          /* override pool */
+      jcr->run_pool_override = true;
    }
    if (run->full_pool) {
       jcr->full_pool = run->full_pool; /* override full pool */
+      jcr->run_full_pool_override = true;
    }
    if (run->inc_pool) {
       jcr->inc_pool = run->inc_pool;  /* override inc pool */
+      jcr->run_inc_pool_override = true;
    }
-   if (run->dif_pool) {
-      jcr->dif_pool = run->dif_pool;  /* override dif pool */
+   if (run->diff_pool) {
+      jcr->diff_pool = run->diff_pool;  /* override dif pool */
+      jcr->run_diff_pool_override = true;
    }
    if (run->storage) {
-      set_storage(jcr, run->storage); /* override storage */
+      set_rwstorage(jcr, run->storage); /* override storage */
    }
    if (run->msgs) {
       jcr->messages = run->msgs;      /* override messages */
@@ -242,7 +259,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;
@@ -257,7 +274,7 @@ static void find_runs()
     * 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;
@@ -319,7 +336,7 @@ 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 */
+         (void)localtime_r(&now, &tm);      /* reset tm structure */
          tm.tm_min = run->minute;     /* set run minute */
          tm.tm_sec = 0;               /* zero secs */
          if (run_now) {