]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/scheduler.c
Add new files
[bacula/bacula] / bacula / src / dird / scheduler.c
index 4e09a5b3ca3575d0a2f6a565c03557e0efa929d1..8ec070d77a0e9c34fcaed22b0be979c19df6604a 100644 (file)
@@ -10,7 +10,7 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -95,7 +95,7 @@ JCR *wait_for_next_job(char *job_to_run)
       if (rem_runjobs > 0) {
         break;
       }
-      sleep(60);
+      bmicrosleep(60, 0);            /* recheck once per minute */
    }
 
    /* 
@@ -118,7 +118,7 @@ JCR *wait_for_next_job(char *job_to_run)
 #ifdef xxxx_debug
       if (runtime > 0) {
         bstrftime(dt, sizeof(dt), runjobs[i].runtime);  
-         Dmsg2(000, "    %s run %s\n", dt, runjobs[i].job->hdr.name);
+         Dmsg2(100, "    %s run %s\n", dt, runjobs[i].job->hdr.name);
       }
 #endif
    }
@@ -128,14 +128,13 @@ JCR *wait_for_next_job(char *job_to_run)
 
    /* Now wait for the time to run the job */
    for (;;) {
-      int twait;
-      time(&now);
+      time_t twait;
+      now = time(NULL);
       twait = nexttime - now;
-      if (twait <= 0)                /* time to run it */
+      if (twait <= 0) {              /* time to run it */
         break;
-      if (twait > 1)                 /* sleep max 20 seconds */
-        twait--;
-      sleep(twait);
+      }
+      bmicrosleep(twait, 0);
    }
    run = runjobs[jobindex].run;
    job = runjobs[jobindex].job;
@@ -145,7 +144,6 @@ JCR *wait_for_next_job(char *job_to_run)
 
    jcr = new_jcr(sizeof(JCR), dird_free_jcr);
    ASSERT(job);
-   sm_check(__FILE__, __LINE__, False);
    set_jcr_defaults(jcr, job);
    if (run->level) {
       jcr->JobLevel = run->level;       /* override run level */
@@ -157,7 +155,7 @@ JCR *wait_for_next_job(char *job_to_run)
       jcr->store = run->storage;      /* override storage */
    }
    if (run->msgs) {
-      jcr->msgs = run->msgs;         /* override messages */
+      jcr->messages = run->msgs;      /* override messages */
    }
    Dmsg0(200, "Leave wait_for_next_job()\n");
    return jcr;
@@ -188,7 +186,7 @@ static void find_runs()
    JOB *job;
    SCHED *sched;
    struct tm tm;
-   int hour, next_hour, minute, mday, wday, month;
+   int hour, next_hour, minute, mday, wday, month, wpos;
 
    Dmsg0(200, "enter find_runs()\n");
    num_runjobs = 0;
@@ -204,6 +202,7 @@ static void find_runs()
    mday = tm.tm_mday - 1;
    wday = tm.tm_wday;
    month = tm.tm_mon;
+   wpos = (tm.tm_mday - 1) / 7; 
 
    /* Loop through all jobs */
    LockRes();
@@ -219,7 +218,7 @@ static void find_runs()
          */
         if ((bit_is_set(hour, run->hour) || bit_is_set(next_hour, run->hour)) &&
             (bit_is_set(mday, run->mday) || bit_is_set(wday, run->wday)) && 
-            bit_is_set(month, run->month)) {
+            bit_is_set(month, run->month) && bit_is_set(wpos, run->wpos)) {
 
            /* find time (time_t) job is to be run */
            localtime_r(&now, &tm);
@@ -259,7 +258,7 @@ static void add_job(JOB *job, RUN *run, time_t now, time_t runtime)
    /* Make sure array is big enough */
    if (num_runjobs == max_runjobs) {
       max_runjobs += 10;
-      runjobs = (RUNJOB *) realloc(runjobs, sizeof(RUNJOB) * max_runjobs);
+      runjobs = (RUNJOB *)realloc(runjobs, sizeof(RUNJOB) * max_runjobs);
       if (!runjobs)
          Emsg0(M_ABORT, 0, _("Out of memory\n"));
    }