/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2014 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.
- This program is Free Software; you can redistribute it and/or
- modify it under the terms of version three of the GNU Affero General Public
- License as published by the Free Software Foundation and included
- in the file LICENSE.
+ The main author of Bacula is Kern Sibbald, with contributions from many
+ others, a complete list can be found in the file AUTHORS.
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
+ You may use this file and others of this release according to the
+ license defined in the LICENSE file, which includes the Affero General
+ Public License, v3.0 ("AGPLv3") and some additional permissions and
+ terms pursuant to its AGPLv3 Section 7.
Bacula® is a registered trademark of Kern Sibbald.
- The licensor of Bacula is the Free Software Foundation Europe
- (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
- Switzerland, email:ftf@fsfeurope.org.
*/
/*
* Manipulation routines for Job Control Records and
* The result is that there is one lock/unlock for each entry
* in the list while traversing it rather than a single lock
* at the beginning of a traversal and one at the end. This
- * incurs slightly more overhead, but effectively eliminates
+ * incurs slightly more overhead, but effectively eliminates
* the possibilty of race conditions. In addition, with the
* exception of the global locking of the list during the
* re-reading of the config file, no recursion is needed.
int num_jobs_run;
dlist *last_jobs = NULL;
const int max_last_jobs = 10;
-
+
static dlist *jcrs = NULL; /* JCR chain */
static pthread_mutex_t jcr_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_key_t jcr_key; /* Pointer to jcr for each thread */
-pthread_once_t key_once = PTHREAD_ONCE_INIT;
+pthread_once_t key_once = PTHREAD_ONCE_INIT;
static char Job_status[] = "Status Job=%s JobStatus=%d\n";
}
jcr->job_end_push.init(1, false);
jcr->sched_time = time(NULL);
+ jcr->initial_sched_time = jcr->sched_time;
jcr->daemon_free_jcr = daemon_free_jcr; /* plug daemon free routine */
jcr->init_mutex();
- jcr->inc_use_count();
+ jcr->inc_use_count();
jcr->VolumeName = get_pool_memory(PM_FNAME);
jcr->VolumeName[0] = 0;
jcr->errmsg = get_pool_memory(PM_MESSAGE);
jcr->msg_queue = NULL;
pthread_mutex_destroy(&jcr->msg_queue_mutex);
}
- close_msg(jcr); /* close messages for this job */
/* do this after closing messages */
if (jcr->client_name) {
jcr->VolumeName = NULL;
}
- if (jcr->dir_bsock) {
- bnet_close(jcr->dir_bsock);
- jcr->dir_bsock = NULL;
- }
+ free_bsock(jcr->dir_bsock);
+
if (jcr->errmsg) {
free_pool_memory(jcr->errmsg);
jcr->errmsg = NULL;
{
struct s_last_job *je;
- Dmsg3(dbglvl, "Enter free_jcr jid=%u use_count=%d Job=%s\n",
+ Dmsg3(dbglvl, "Enter free_jcr jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
#endif
jcr->use_count(), jcr->JobId);
}
if (jcr->JobId > 0) {
- Dmsg3(dbglvl, "Dec free_jcr jid=%u use_count=%d Job=%s\n",
+ Dmsg3(dbglvl, "Dec free_jcr jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
}
if (jcr->use_count() > 0) { /* if in use */
return;
}
if (jcr->JobId > 0) {
- Dmsg3(dbglvl, "remove jcr jid=%u use_count=%d Job=%s\n",
+ Dmsg3(dbglvl, "remove jcr jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
}
remove_jcr(jcr); /* remove Jcr from chain */
unlock_jcr_chain();
dequeue_messages(jcr);
+ close_msg(jcr); /* close messages for this job */
job_end_pop(jcr); /* pop and call hooked routines */
Dmsg1(dbglvl, "End job=%d\n", jcr->JobId);
}
free_common_jcr(jcr);
- close_msg(NULL); /* flush any daemon messages */
Dmsg0(dbglvl, "Exit free_jcr\n");
}
void remove_jcr_from_tsd(JCR *jcr)
{
JCR *tjcr = get_jcr_from_tsd();
- if (tjcr == jcr) {
+ if (tjcr == jcr) {
set_jcr_in_tsd(INVALID_JCR);
}
}
JCR *jcr = this;
jcr->lock();
jcr->my_thread_killable = killable;
- if (killable) {
- jcr->my_thread_id = pthread_self();
- } else {
- memset(&jcr->my_thread_id, 0, sizeof(jcr->my_thread_id));
- }
jcr->unlock();
}
int status = pthread_setspecific(jcr_key, (void *)jcr);
if (status != 0) {
berrno be;
- Jmsg1(jcr, M_ABORT, 0, _("pthread_setspecific failed: ERR=%s\n"),
+ Jmsg1(jcr, M_ABORT, 0, _("pthread_setspecific failed: ERR=%s\n"),
be.bstrerror(status));
}
}
return jcr;
}
-
+
/*
* Find which JobId corresponds to the current thread
*/
foreach_jcr(jcr) {
if (jcr->JobId == JobId) {
jcr->inc_use_count();
- Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
+ Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
break;
}
if (jcr->VolSessionId == SessionId &&
jcr->VolSessionTime == SessionTime) {
jcr->inc_use_count();
- Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
+ Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
break;
}
foreach_jcr(jcr) {
if (strncmp(Job, jcr->Job, len) == 0) {
jcr->inc_use_count();
- Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
+ Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
break;
}
foreach_jcr(jcr) {
if (strcmp(jcr->Job, Job) == 0) {
jcr->inc_use_count();
- Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
+ Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
break;
}
enter_in_waittime = false; /* not a Wait situation */
break;
}
-
+
/*
* If we were previously waiting and are not any more
* we want to update the wait_time variable, which is
}
}
-/*
+/*
* Priority runs from 0 (lowest) to 10 (highest)
*/
static int get_status_priority(int JobStatus)
{
int priority = 0;
switch (JobStatus) {
- case JS_Incomplete:
- priority = 10;
- break;
case JS_ErrorTerminated:
case JS_FatalError:
case JS_Canceled:
if (jcr->dir_bsock) {
return jcr->dir_bsock->fsend(Job_status, jcr->Job, jcr->JobStatus);
}
- return true;
+ return true;
}
/*
return jcr->dir_bsock->fsend(Job_status, jcr->Job, jcr->JobStatus);
}
}
- return true;
+ return true;
}
void JCR::setJobStarted()
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, newJobStatus);
/* Update wait_time depending on newJobStatus and oldJobStatus */
/*
* If status priority is > than proposed new status, change it.
* If status priority == new priority and both are zero, take
- * the new status.
+ * the new status.
* If it is not zero, then we keep the first non-zero "error" that
* occurred.
*/
* released with:
*
* free_jcr(jcr);
- *
+ *
*/
-JCR *jcr_walk_start()
+JCR *jcr_walk_start()
{
JCR *jcr;
lock_jcr_chain();
if (jcr) {
jcr->inc_use_count();
if (jcr->JobId > 0) {
- Dmsg3(dbglvl, "Inc walk_start jid=%u use_count=%d Job=%s\n",
+ Dmsg3(dbglvl, "Inc walk_start jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
}
}
if (jcr) {
jcr->inc_use_count();
if (jcr->JobId > 0) {
- Dmsg3(dbglvl, "Inc walk_next jid=%u use_count=%d Job=%s\n",
+ Dmsg3(dbglvl, "Inc walk_next jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
}
}
{
if (jcr) {
if (jcr->JobId > 0) {
- Dmsg3(dbglvl, "Free walk_end jid=%u use_count=%d Job=%s\n",
+ Dmsg3(dbglvl, "Free walk_end jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
}
free_jcr(jcr);
bs->set_timed_out();
Qmsg(jcr, M_ERROR, 0, _(
"Watchdog sending kill after %d secs to thread stalled reading Storage daemon.\n"),
- watchdog_time - timer_start);
+ (int)(watchdog_time - timer_start));
jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
}
}
bs->set_timed_out();
Qmsg(jcr, M_ERROR, 0, _(
"Watchdog sending kill after %d secs to thread stalled reading File daemon.\n"),
- watchdog_time - timer_start);
+ (int)(watchdog_time - timer_start));
jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
}
}
bs->set_timed_out();
Qmsg(jcr, M_ERROR, 0, _(
"Watchdog sending kill after %d secs to thread stalled reading Director.\n"),
- watchdog_time - timer_start);
+ (int)(watchdog_time - timer_start));
jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
}
}
Dmsg0(dbglvl, "Finished JCR timeout checks\n");
}
-/*
- * Return next JobId from comma separated list
+/*
+ * Return next JobId from comma separated list
*
* Returns:
* 1 if next JobId returned
return; /* thus interrupting the function */
}
-/* Used to display specific daemon information after a fatal signal
+/* Used to display specific daemon information after a fatal signal
* (like B_DB in the director)
*/
#define MAX_DBG_HOOK 10
dbg_jcr_hooks[dbg_jcr_handler_count++] = hook;
}
+/* on win32, the pthread_t is a struct, so we don't display it */
+#ifdef HAVE_MINGW_W64
+# define get_threadid(a) (void *)0
+#else
+# define get_threadid(a) (void *)(a)
+#endif
/*
- * !!! WARNING !!!
+ * !!! WARNING !!!
*
* This function should be used ONLY after a fatal signal. We walk through the
* JCR chain without doing any lock, Bacula should not be running.
fprintf(fp, "Attempt to dump current JCRs. njcrs=%d\n", jcrs->size());
for (JCR *jcr = (JCR *)jcrs->first(); jcr ; jcr = (JCR *)jcrs->next(jcr)) {
- fprintf(fp, "threadid=%p JobId=%d JobStatus=%c jcr=%p name=%s\n",
- (void *)jcr->my_thread_id, (int)jcr->JobId, jcr->JobStatus, jcr, jcr->Job);
+ fprintf(fp, "threadid=%p JobId=%d JobStatus=%c jcr=%p name=%s\n",
+ get_threadid(jcr->my_thread_id), (int)jcr->JobId, jcr->JobStatus, jcr, jcr->Job);
fprintf(fp, "threadid=%p killable=%d JobId=%d JobStatus=%c "
"jcr=%p name=%s\n",
- (void *)jcr->my_thread_id, jcr->is_killable(),
+ get_threadid(jcr->my_thread_id), jcr->is_killable(),
(int)jcr->JobId, jcr->JobStatus, jcr, jcr->Job);
fprintf(fp, "\tuse_count=%i\n", jcr->use_count());
fprintf(fp, "\tJobType=%c JobLevel=%c\n",
bstrftime(buf4, sizeof(buf4), jcr->wait_time);
fprintf(fp, "\tsched_time=%s start_time=%s\n\tend_time=%s wait_time=%s\n",
buf1, buf2, buf3, buf4);
- fprintf(fp, "\tdb=%p db_batch=%p batch_started=%i\n",
+ fprintf(fp, "\tdb=%p db_batch=%p batch_started=%i\n",
jcr->db, jcr->db_batch, jcr->batch_started);
-
+
/*
* Call all the jcr debug hooks
*/