BSOCK *file_bsock; /* File daemon connection socket */
JCR_free_HANDLER *daemon_free_jcr; /* Local free routine */
dlist *msg_queue; /* Queued messages */
+ pthread_mutex_t msg_queue_mutex; /* message queue mutex */
alist job_end_push; /* Job end pushed calls */
- bool dequeuing; /* dequeuing messages */
POOLMEM *VolumeName; /* Volume name desired -- pool_memory */
POOLMEM *errmsg; /* edited error message */
char Job[MAX_NAME_LENGTH]; /* Unique name of this Job */
memset(jcr, 0, size);
jcr->my_thread_id = pthread_self();
jcr->msg_queue = New(dlist(item, &item->link));
+ if ((status = pthread_mutex_init(&jcr->msg_queue_mutex, NULL)) != 0) {
+ berrno be;
+ Jmsg(NULL, M_ABORT, 0, _("Could not init msg_queue mutex. ERR=%s\n"),
+ be.bstrerror(status));
+ }
jcr->job_end_push.init(1, false);
jcr->sched_time = time(NULL);
jcr->daemon_free_jcr = daemon_free_jcr; /* plug daemon free routine */
if (jcr->msg_queue) {
delete jcr->msg_queue;
jcr->msg_queue = NULL;
+ pthread_mutex_destroy(&jcr->msg_queue_mutex);
}
close_msg(jcr); /* close messages for this job */
* !!! 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.
+ * JCR chain without doing any lock, Bacula should not be running.
*/
void _dbg_print_jcr(FILE *fp)
{
fprintf(fp, "Attempt to dump current JCRs\n");
for (JCR *jcr = (JCR *)jcrs->first(); jcr ; jcr = (JCR *)jcrs->next(jcr)) {
- if (!jcr) { /* protect us against something ? */
- continue;
- }
-
+
fprintf(fp, "JCR=%p JobId=%i name=%s JobStatus=%c\n",
jcr, jcr->JobId, jcr->Job, jcr->JobStatus);
-#ifdef HAVE_WIN32
- fprintf(fp, "\tuse_count=%i\n",
- jcr->use_count());
-#else
- /* KES -- removed non-portable code referencing pthread_t */
- fprintf(fp, "\tuse_count=%d\n", jcr->use_count());
-#endif
+ fprintf(fp, "\tuse_count=%i\n", jcr->use_count());
fprintf(fp, "\tJobType=%c JobLevel=%c\n",
jcr->get_JobType(), jcr->get_JobLevel());
bstrftime(buf1, sizeof(buf1), jcr->sched_time);
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, "\tdequeing=%i\n", jcr->dequeuing);
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
+ */
for(int i=0; i < dbg_jcr_handler_count; i++) {
dbg_jcr_hook_t *fct = dbg_jcr_hooks[i];
fct(jcr, fp);
/*
* !!! WARNING !!!
- * Use this function only after a fatal signal
- * We don't use any lock to display information
+ * Use this function is used only after a fatal signal
+ * We don't use locking to display the information
*/
void dbg_print_lock(FILE *fp)
{
/*
* !!! WARNING !!!
- * Use this function only after a fatal signal
- * We don't use any lock to display information
+ * Use this function is used only after a fatal signal
+ * We don't use locking to display information
*/
void dbg_print_lock(FILE *fp)
{
*
* Kern Sibbald, April 2000
*
- * Version $Id$
- *
*/
-
#include "bacula.h"
#include "jcr.h"
}
-static pthread_mutex_t msg_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
-
/*
* We queue messages rather than print them directly. This
* is generally used in low level routines (msg handler, bnet)
if (!jcr) {
jcr = get_jcr_from_tsd();
}
- /* If no jcr or dequeuing send to daemon to avoid recursion */
- if ((jcr && !jcr->msg_queue) || !jcr || jcr->dequeuing) {
+ /* If no jcr or no queue send to daemon */
+ if ((jcr && !jcr->msg_queue) || !jcr) {
/* jcr==NULL => daemon message, safe to send now */
Jmsg(jcr, item->type, item->mtime, "%s", item->msg);
free(item);
} else {
/* Queue message for later sending */
- P(msg_queue_mutex);
+ P(jcr->msg_queue_mutex);
jcr->msg_queue->append(item);
- V(msg_queue_mutex);
+ V(jcr->msg_queue_mutex);
}
free_memory(pool_buf);
}
void dequeue_messages(JCR *jcr)
{
MQUEUE_ITEM *item;
- P(msg_queue_mutex);
if (!jcr->msg_queue) {
- goto bail_out;
+ return;
}
- jcr->dequeuing = true;
+ P(jcr->msg_queue_mutex);
foreach_dlist(item, jcr->msg_queue) {
Jmsg(jcr, item->type, item->mtime, "%s", item->msg);
}
+ /* Remove messages just sent */
jcr->msg_queue->destroy();
- jcr->dequeuing = false;
-
-bail_out:
- V(msg_queue_mutex);
+ V(jcr->msg_queue_mutex);
}
* !!! WARNING !!!
*
* This function should be used ONLY after a violent signal. We walk through the
- * JCR chain without doing any lock, bacula should not be running.
+ * JCR chain without locking, Bacula should not be running.
*/
static void dbg_print_bacula()
{
if (sig == SIGTERM) {
// Emsg1(M_TERM, -1, "Shutting down Bacula service: %s ...\n", my_name);
} else {
-/* ***FIXME*** Display a message without taking any lock in the system
+/* ***FIXME*** Display a message without locking
* Emsg2(M_FATAL, -1, _("Bacula interrupted by signal %d: %s\n"), sig, get_signal_name(sig));
*/
fprintf(stderr, _("Bacula interrupted by signal %d: %s\n"), sig, get_signal_name(sig));