+
+/* Used to display specific daemon information after a fatal signal
+ * (like B_DB in the director)
+ */
+#define MAX_DBG_HOOK 10
+static dbg_jcr_hook_t *dbg_jcr_hooks[MAX_DBG_HOOK];
+static int dbg_jcr_handler_count;
+
+void dbg_jcr_add_hook(dbg_jcr_hook_t *fct)
+{
+ ASSERT(dbg_jcr_handler_count < MAX_DBG_HOOK);
+ dbg_jcr_hooks[dbg_jcr_handler_count++] = fct;
+}
+
+/*
+ * !!! 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.
+ */
+void _dbg_print_jcr(FILE *fp)
+{
+ char buf1[128], buf2[128], buf3[128], buf4[128];
+ if (!jcrs) {
+ return;
+ }
+
+ 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
+ fprintf(fp, "\tuse_count=%i threadid=0x%x\n",
+ jcr->use_count(), (int)jcr->my_thread_id);
+#endif
+ fprintf(fp, "\tJobType=%c JobLevel=%c\n",
+ jcr->get_JobType(), jcr->get_JobLevel());
+ bstrftime(buf1, sizeof(buf1), jcr->sched_time);
+ bstrftime(buf2, sizeof(buf2), jcr->start_time);
+ bstrftime(buf3, sizeof(buf3), jcr->end_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);
+
+ for(int i=0; i < dbg_jcr_handler_count; i++) {
+ dbg_jcr_hook_t *fct = dbg_jcr_hooks[i];
+ fct(jcr, fp);
+ }
+ }
+}
+