From: Kern Sibbald Date: Thu, 15 Oct 2009 13:25:06 +0000 (+0200) Subject: Fix bug #1391 Job status improperly set due to subtle variable overload problem X-Git-Tag: Release-5.0.0~285^2~2^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=97421396ff29e41490c17f49235b293a1cad0d1b;p=bacula%2Fbacula Fix bug #1391 Job status improperly set due to subtle variable overload problem --- diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index 50fbb6a197..fb039843c9 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -745,30 +745,6 @@ JCR *get_jcr_by_full_name(char *Job) return jcr; } -/* - * Priority runs from 0 (lowest) to 10 (highest) - */ -static int get_status_priority(int JobStatus) -{ - int priority = 0; - switch (JobStatus) { - case JS_ErrorTerminated: - case JS_FatalError: - case JS_Canceled: - case JS_Incomplete: - priority = 10; - break; - case JS_Error: - priority = 8; - break; - case JS_Differences: - priority = 7; - break; - } - return priority; -} - - static void update_wait_time(JCR *jcr, int newJobStatus) { bool enter_in_waittime; @@ -821,37 +797,69 @@ static void update_wait_time(JCR *jcr, int newJobStatus) } } +/* + * Priority runs from 0 (lowest) to 10 (highest) + */ +static int get_status_priority(int JobStatus) +{ + int priority = 0; + switch (JobStatus) { + case JS_ErrorTerminated: + case JS_FatalError: + case JS_Canceled: + case JS_Incomplete: + priority = 10; + break; + case JS_Error: + priority = 8; + break; + case JS_Differences: + priority = 7; + break; + } + return priority; +} + + void set_jcr_job_status(JCR *jcr, int JobStatus) { jcr->setJobStatus(JobStatus); } -void JCR::setJobStatus(int JobStatus) +void JCR::setJobStatus(int newJobStatus) { JCR *jcr = this; int priority, old_priority; - int oldJobStatus = JobStatus; - priority = get_status_priority(JobStatus); + int oldJobStatus = jcr->JobStatus; + priority = get_status_priority(newJobStatus); old_priority = get_status_priority(oldJobStatus); - Dmsg2(800, "set_jcr_job_status(%s, %c)\n", Job, JobStatus); + Dmsg2(800, "set_jcr_job_status(%s, %c)\n", Job, newJobStatus); /* Update wait_time depending on newJobStatus and oldJobStatus */ - update_wait_time(this, JobStatus); + update_wait_time(jcr, newJobStatus); /* * For a set of errors, ... keep the current status * so it isn't lost. For all others, set it. */ - Dmsg3(300, "jid=%u OnEntry JobStatus=%c set=%c\n", (uint32_t)JobId, - JobStatus, JobStatus); - if (priority >= old_priority) { - jcr->JobStatus = JobStatus; /* replace with new priority */ + Dmsg2(800, "OnEntry JobStatus=%c newJobstatus=%c\n", oldJobStatus, newJobStatus); + /* + * If status priority is > than proposed new status, change it. + * If status priority == new priority and both are zero, take + * the new status. + * If it is not zero, then we keep the first non-zero "error" that + * occurred. + */ + if (priority > old_priority || ( + priority == 0 && old_priority == 0)) { + Dmsg4(800, "Set new stat. old: %c,%d new: %c,%d\n", + jcr->JobStatus, old_priority, newJobStatus, priority); + jcr->JobStatus = newJobStatus; /* replace with new status */ } if (oldJobStatus != jcr->JobStatus) { - Dmsg3(200, "jid=%u leave set_old_job_status=%c new_set=%c\n", (uint32_t)jcr->JobId, - oldJobStatus, JobStatus); + Dmsg2(800, "leave set_job_status old=%c new=%c\n", oldJobStatus, newJobStatus); // generate_plugin_event(jcr, bEventStatusChange, NULL); } } diff --git a/bacula/technotes b/bacula/technotes index db249bddd5..10a3cb06ac 100644 --- a/bacula/technotes +++ b/bacula/technotes @@ -2,6 +2,8 @@ General: +15Oct09 +kes Fix bug #1391 Job status improperly set due to subtle variable overload problem 13Oct09 ebl Fix #1352 about double free with regexp and big filenames on windows 11Oct09