Andreas Thienemann b41752
Andreas Thienemann b41752
This patch should fix the logic error in checking for the MaxWaitTime of
Andreas Thienemann b41752
a job in src/dird/job.c.  It fixes bug #802.
Andreas Thienemann b41752
Andreas Thienemann b41752
Apply it to Bacula version 2.0.3 with:
Andreas Thienemann b41752
Andreas Thienemann b41752
  cd <bacula-source>
Andreas Thienemann b41752
  patch -p0 <2.0.3-maxwaittime.patch
Andreas Thienemann b41752
  make
Andreas Thienemann b41752
  ...
Andreas Thienemann b41752
  make install
Andreas Thienemann b41752
Andreas Thienemann b41752
Andreas Thienemann b41752
Andreas Thienemann b41752
Index: src/dird/job.c
Andreas Thienemann b41752
===================================================================
Andreas Thienemann b41752
--- src/dird/job.c	(revision 4349)
Andreas Thienemann b41752
+++ src/dird/job.c	(working copy)
Andreas Thienemann b41752
@@ -481,7 +481,6 @@
Andreas Thienemann b41752
 static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr)
Andreas Thienemann b41752
 {
Andreas Thienemann b41752
    bool cancel = false;
Andreas Thienemann b41752
-   bool ok_to_cancel = false;
Andreas Thienemann b41752
    JOB *job = jcr->job;
Andreas Thienemann b41752
 
Andreas Thienemann b41752
    if (job_canceled(jcr)) {
Andreas Thienemann b41752
@@ -493,69 +492,18 @@
Andreas Thienemann b41752
    } 
Andreas Thienemann b41752
    if (jcr->JobLevel == L_FULL && job->FullMaxWaitTime != 0 &&
Andreas Thienemann b41752
          (watchdog_time - jcr->start_time) >= job->FullMaxWaitTime) {
Andreas Thienemann b41752
-      ok_to_cancel = true;
Andreas Thienemann b41752
+      cancel = true;
Andreas Thienemann b41752
    } else if (jcr->JobLevel == L_DIFFERENTIAL && job->DiffMaxWaitTime != 0 &&
Andreas Thienemann b41752
          (watchdog_time - jcr->start_time) >= job->DiffMaxWaitTime) {
Andreas Thienemann b41752
-      ok_to_cancel = true;
Andreas Thienemann b41752
+      cancel = true;
Andreas Thienemann b41752
    } else if (jcr->JobLevel == L_INCREMENTAL && job->IncMaxWaitTime != 0 &&
Andreas Thienemann b41752
          (watchdog_time - jcr->start_time) >= job->IncMaxWaitTime) {
Andreas Thienemann b41752
-      ok_to_cancel = true;
Andreas Thienemann b41752
+      cancel = true;
Andreas Thienemann b41752
    } else if (job->MaxWaitTime != 0 &&
Andreas Thienemann b41752
          (watchdog_time - jcr->start_time) >= job->MaxWaitTime) {
Andreas Thienemann b41752
-      ok_to_cancel = true;
Andreas Thienemann b41752
-   }
Andreas Thienemann b41752
-   if (!ok_to_cancel) {
Andreas Thienemann b41752
-      return false;
Andreas Thienemann b41752
-   }
Andreas Thienemann b41752
-
Andreas Thienemann b41752
-/*
Andreas Thienemann b41752
- * I don't see the need for all this -- kes 17Dec06
Andreas Thienemann b41752
- */
Andreas Thienemann b41752
-#ifdef xxx
Andreas Thienemann b41752
-   Dmsg3(800, "Job %d (%s): MaxWaitTime of %d seconds exceeded, "
Andreas Thienemann b41752
-         "checking status\n",
Andreas Thienemann b41752
-         jcr->JobId, jcr->Job, job->MaxWaitTime);
Andreas Thienemann b41752
-   switch (jcr->JobStatus) {
Andreas Thienemann b41752
-   case JS_Created:
Andreas Thienemann b41752
-   case JS_Blocked:
Andreas Thienemann b41752
-   case JS_WaitFD:
Andreas Thienemann b41752
-   case JS_WaitSD:
Andreas Thienemann b41752
-   case JS_WaitStoreRes:
Andreas Thienemann b41752
-   case JS_WaitClientRes:
Andreas Thienemann b41752
-   case JS_WaitJobRes:
Andreas Thienemann b41752
-   case JS_WaitPriority:
Andreas Thienemann b41752
-   case JS_WaitMaxJobs:
Andreas Thienemann b41752
-   case JS_WaitStartTime:
Andreas Thienemann b41752
       cancel = true;
Andreas Thienemann b41752
-      Dmsg0(200, "JCR blocked in #1\n");
Andreas Thienemann b41752
-      break;
Andreas Thienemann b41752
-   case JS_Running:
Andreas Thienemann b41752
-      Dmsg0(800, "JCR running, checking SD status\n");
Andreas Thienemann b41752
-      switch (jcr->SDJobStatus) {
Andreas Thienemann b41752
-      case JS_WaitMount:
Andreas Thienemann b41752
-      case JS_WaitMedia:
Andreas Thienemann b41752
-      case JS_WaitFD:
Andreas Thienemann b41752
-         cancel = true;
Andreas Thienemann b41752
-         Dmsg0(800, "JCR blocked in #2\n");
Andreas Thienemann b41752
-         break;
Andreas Thienemann b41752
-      default:
Andreas Thienemann b41752
-         Dmsg0(800, "JCR not blocked in #2\n");
Andreas Thienemann b41752
-         break;
Andreas Thienemann b41752
-      }
Andreas Thienemann b41752
-      break;
Andreas Thienemann b41752
-   case JS_Terminated:
Andreas Thienemann b41752
-   case JS_ErrorTerminated:
Andreas Thienemann b41752
-   case JS_Canceled:
Andreas Thienemann b41752
-   case JS_FatalError:
Andreas Thienemann b41752
-      Dmsg0(800, "JCR already dead in #3\n");
Andreas Thienemann b41752
-      break;
Andreas Thienemann b41752
-   default:
Andreas Thienemann b41752
-      Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
Andreas Thienemann b41752
-            jcr->JobStatus);
Andreas Thienemann b41752
    }
Andreas Thienemann b41752
-   Dmsg3(800, "MaxWaitTime result: %scancel JCR %p (%s)\n",
Andreas Thienemann b41752
-         cancel ? "" : "do not ", jcr, jcr->Job);
Andreas Thienemann b41752
-#endif
Andreas Thienemann b41752
+
Andreas Thienemann b41752
    return cancel;
Andreas Thienemann b41752
 }
Andreas Thienemann b41752
 
Andreas Thienemann b41752
@@ -574,36 +522,6 @@
Andreas Thienemann b41752
       return false;
Andreas Thienemann b41752
    }
Andreas Thienemann b41752
 
Andreas Thienemann b41752
-#ifdef xxx
Andreas Thienemann b41752
-   switch (jcr->JobStatus) {
Andreas Thienemann b41752
-   case JS_Created:
Andreas Thienemann b41752
-   case JS_Running:
Andreas Thienemann b41752
-   case JS_Blocked:
Andreas Thienemann b41752
-   case JS_WaitFD:
Andreas Thienemann b41752
-   case JS_WaitSD:
Andreas Thienemann b41752
-   case JS_WaitStoreRes:
Andreas Thienemann b41752
-   case JS_WaitClientRes:
Andreas Thienemann b41752
-   case JS_WaitJobRes:
Andreas Thienemann b41752
-   case JS_WaitPriority:
Andreas Thienemann b41752
-   case JS_WaitMaxJobs:
Andreas Thienemann b41752
-   case JS_WaitStartTime:
Andreas Thienemann b41752
-   case JS_Differences:
Andreas Thienemann b41752
-      cancel = true;
Andreas Thienemann b41752
-      break;
Andreas Thienemann b41752
-   case JS_Terminated:
Andreas Thienemann b41752
-   case JS_ErrorTerminated:
Andreas Thienemann b41752
-   case JS_Canceled:
Andreas Thienemann b41752
-   case JS_FatalError:
Andreas Thienemann b41752
-      cancel = false;
Andreas Thienemann b41752
-      break;
Andreas Thienemann b41752
-   default:
Andreas Thienemann b41752
-      Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
Andreas Thienemann b41752
-            jcr->JobStatus);
Andreas Thienemann b41752
-   }
Andreas Thienemann b41752
-
Andreas Thienemann b41752
-   Dmsg3(200, "MaxRunTime result: %scancel JCR %p (%s)\n",
Andreas Thienemann b41752
-         cancel ? "" : "do not ", jcr, jcr->Job);
Andreas Thienemann b41752
-#endif
Andreas Thienemann b41752
    return true;
Andreas Thienemann b41752
 }
Andreas Thienemann b41752