/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2009 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.
}
}
-/* Set Job type in JCR and also set appropriate read flag */
-void JCR::set_JobType(int32_t JobType)
-{
- m_JobType = JobType;
-}
-
-/* Set Job level in JCR and also set appropriate read flag */
-void JCR::set_JobLevel(int32_t JobLevel)
-{
- m_JobLevel = JobLevel;
-}
-
bool JCR::JobReads()
{
switch (m_JobType) {
/* Setup some dummy values */
bstrncpy(jcr->Job, "*System*", sizeof(jcr->Job));
jcr->JobId = 0;
- jcr->set_JobType(JT_SYSTEM); /* internal job until defined */
- jcr->set_JobLevel(L_NONE);
- set_jcr_job_status(jcr, JS_Created); /* ready to run */
+ jcr->setJobType(JT_SYSTEM); /* internal job until defined */
+ jcr->setJobLevel(L_NONE);
+ jcr->setJobStatus(JS_Created); /* ready to run */
set_jcr_in_tsd(jcr);
sigtimer.sa_flags = 0;
sigtimer.sa_handler = timeout_handler;
jcr->JobId, jcr->use_count(), jcr->Job);
}
remove_jcr(jcr); /* remove Jcr from chain */
+ unlock_jcr_chain();
dequeue_messages(jcr);
job_end_pop(jcr); /* pop and call hooked routines */
jcr->daemon_free_jcr(jcr); /* call daemon free routine */
}
- unlock_jcr_chain();
free_common_jcr(jcr);
close_msg(NULL); /* flush any daemon messages */
garbage_collect_memory_pool();
return jcr;
}
+/*
+ * Given a thread id, find the JobId
+ * Returns: JobId on success
+ * 0 on failure
+ */
+uint32_t get_jobid_from_tid(pthread_t tid)
+{
+ JCR *jcr = NULL;
+ bool found = false;
+
+ foreach_jcr(jcr) {
+ if (pthread_equal(jcr->my_thread_id, tid)) {
+ found = true;
+ break;
+ }
+ }
+ endeach_jcr(jcr);
+ if (found) {
+ return jcr->JobId;
+ }
+ return 0;
+}
+
+
/*
* Given a SessionId and SessionTime, find the JCR
* Returns: jcr on success
switch (JobStatus) {
case JS_ErrorTerminated:
case JS_FatalError:
- priority = 10;
- break;
case JS_Canceled:
- priority = 9;
+ case JS_Incomplete:
+ priority = 10;
break;
case JS_Error:
priority = 8;
void set_jcr_job_status(JCR *jcr, int JobStatus)
{
+ jcr->setJobStatus(JobStatus);
+}
+
+void JCR::setJobStatus(int JobStatus)
+{
+ JCR *jcr = this;
int priority, old_priority;
- int oldJobStatus = jcr->JobStatus;
+ int oldJobStatus = JobStatus;
priority = get_status_priority(JobStatus);
old_priority = get_status_priority(oldJobStatus);
- Dmsg2(800, "set_jcr_job_status(%s, %c)\n", jcr->Job, JobStatus);
+ Dmsg2(800, "set_jcr_job_status(%s, %c)\n", Job, JobStatus);
/* Update wait_time depending on newJobStatus and oldJobStatus */
- update_wait_time(jcr, JobStatus);
+ update_wait_time(this, JobStatus);
/*
* 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)jcr->JobId,
- jcr->JobStatus, JobStatus);
+ 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 */
}
Dmsg0(dbglvl, "Finished JCR timeout checks\n");
}
+/*
+ * Return next JobId from comma separated list
+ *
+ * Returns:
+ * 1 if next JobId returned
+ * 0 if no more JobIds are in list
+ * -1 there is an error
+ */
+int get_next_jobid_from_list(char **p, uint32_t *JobId)
+{
+ const int maxlen = 30;
+ char jobid[maxlen+1];
+ char *q = *p;
+
+ jobid[0] = 0;
+ for (int i=0; i<maxlen; i++) {
+ if (*q == 0) {
+ break;
+ } else if (*q == ',') {
+ q++;
+ break;
+ }
+ jobid[i] = *q++;
+ jobid[i+1] = 0;
+ }
+ if (jobid[0] == 0) {
+ return 0;
+ } else if (!is_a_number(jobid)) {
+ return -1; /* error */
+ }
+ *p = q;
+ *JobId = str_to_int64(jobid);
+ return 1;
+}
+
/*
* Timeout signal comes here
*/
fprintf(fp, "\tuse_count=%i\n",
jcr->use_count());
#else
- fprintf(fp, "\tuse_count=%i threadid=0x%x\n",
- jcr->use_count(), (int)jcr->my_thread_id);
+ /* KES -- removed non-portable code referencing pthread_t */
+ fprintf(fp, "\tuse_count=%d\n", jcr->use_count());
#endif
fprintf(fp, "\tJobType=%c JobLevel=%c\n",
jcr->get_JobType(), jcr->get_JobLevel());