2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Manipulation routines for Job Control Records and
30 * handling of last_jobs_list.
32 * Kern E. Sibbald, December 2000
36 * These routines are thread safe.
38 * The job list routines were re-written in May 2005 to
39 * eliminate the global lock while traversing the list, and
40 * to use the dlist subroutines. The locking is now done
41 * on the list each time the list is modified or traversed.
42 * That is it is "micro-locked" rather than globally locked.
43 * The result is that there is one lock/unlock for each entry
44 * in the list while traversing it rather than a single lock
45 * at the beginning of a traversal and one at the end. This
46 * incurs slightly more overhead, but effectively eliminates
47 * the possibilty of race conditions. In addition, with the
48 * exception of the global locking of the list during the
49 * re-reading of the config file, no recursion is needed.
56 const int dbglvl = 3400;
58 /* External variables we reference */
60 /* External referenced functions */
61 void free_bregexps(alist *bregexps);
63 /* Forward referenced functions */
64 extern "C" void timeout_handler(int sig);
65 static void jcr_timeout_check(watchdog_t *self);
66 #ifdef TRACE_JCR_CHAIN
67 static void b_lock_jcr_chain(const char *filen, int line);
68 static void b_unlock_jcr_chain(const char *filen, int line);
69 #define lock_jcr_chain() b_lock_jcr_chain(__FILE__, __LINE__);
70 #define unlock_jcr_chain() b_unlock_jcr_chain(__FILE__, __LINE__);
72 static void lock_jcr_chain();
73 static void unlock_jcr_chain();
78 dlist *last_jobs = NULL;
79 const int max_last_jobs = 10;
81 static dlist *jcrs = NULL; /* JCR chain */
82 static pthread_mutex_t jcr_lock = PTHREAD_MUTEX_INITIALIZER;
84 static pthread_mutex_t job_start_mutex = PTHREAD_MUTEX_INITIALIZER;
86 static pthread_mutex_t last_jobs_mutex = PTHREAD_MUTEX_INITIALIZER;
88 static pthread_key_t jcr_key; /* Pointer to jcr for each thread */
90 pthread_once_t key_once = PTHREAD_ONCE_INIT;
103 void init_last_jobs_list()
106 struct s_last_job *job_entry = NULL;
108 last_jobs = New(dlist(job_entry, &job_entry->link));
111 jcrs = New(dlist(jcr, &jcr->link));
115 void term_last_jobs_list()
118 lock_last_jobs_list();
119 while (!last_jobs->empty()) {
120 void *je = last_jobs->first();
121 last_jobs->remove(je);
126 unlock_last_jobs_list();
134 bool read_last_jobs_list(int fd, uint64_t addr)
136 struct s_last_job *je, job;
140 Dmsg1(100, "read_last_jobs seek to %d\n", (int)addr);
141 if (addr == 0 || lseek(fd, (boffset_t)addr, SEEK_SET) < 0) {
144 if (read(fd, &num, sizeof(num)) != sizeof(num)) {
147 Dmsg1(100, "Read num_items=%d\n", num);
148 if (num > 4 * max_last_jobs) { /* sanity check */
151 lock_last_jobs_list();
152 for ( ; num; num--) {
153 if (read(fd, &job, sizeof(job)) != sizeof(job)) {
155 Pmsg1(000, "Read job entry. ERR=%s\n", be.bstrerror());
160 je = (struct s_last_job *)malloc(sizeof(struct s_last_job));
161 memcpy((char *)je, (char *)&job, sizeof(job));
163 init_last_jobs_list();
165 last_jobs->append(je);
166 if (last_jobs->size() > max_last_jobs) {
167 je = (struct s_last_job *)last_jobs->first();
168 last_jobs->remove(je);
173 unlock_last_jobs_list();
177 uint64_t write_last_jobs_list(int fd, uint64_t addr)
179 struct s_last_job *je;
183 Dmsg1(100, "write_last_jobs seek to %d\n", (int)addr);
184 if (lseek(fd, (boffset_t)addr, SEEK_SET) < 0) {
188 lock_last_jobs_list();
189 /* First record is number of entires */
190 num = last_jobs->size();
191 if (write(fd, &num, sizeof(num)) != sizeof(num)) {
193 Pmsg1(000, "Error writing num_items: ERR=%s\n", be.bstrerror());
196 foreach_dlist(je, last_jobs) {
197 if (write(fd, je, sizeof(struct s_last_job)) != sizeof(struct s_last_job)) {
199 Pmsg1(000, "Error writing job: ERR=%s\n", be.bstrerror());
203 unlock_last_jobs_list();
205 /* Return current address */
206 stat = lseek(fd, 0, SEEK_CUR);
213 unlock_last_jobs_list();
217 void lock_last_jobs_list()
222 void unlock_last_jobs_list()
227 /* Get an ASCII representation of the Operation being performed as an english Noun */
228 const char *JCR::get_OperationName()
234 return _("Verifying");
236 return _("Restoring");
238 return _("Archiving");
242 return _("Migration");
244 return _("Scanning");
246 return _("Unknown operation");
250 /* Get an ASCII representation of the Action being performed either an english Verb or Adjective */
251 const char *JCR::get_ActionName(bool past)
257 return (past == true) ? _("verified") : _("verify");
259 return (past == true) ? _("restored") : _("restore");
261 return (past == true) ? _("archived") : _("archive");
263 return (past == true) ? _("copied") : _("copy");
265 return (past == true) ? _("migrated") : _("migrate");
267 return (past == true) ? _("scanned") : _("scan");
269 return _("unknown action");
282 if (m_JobLevel == L_VIRTUAL_FULL) {
293 * Push a subroutine address into the job end callback stack
295 void job_end_push(JCR *jcr, void job_end_cb(JCR *jcr,void *), void *ctx)
297 jcr->job_end_push.append((void *)job_end_cb);
298 jcr->job_end_push.append(ctx);
301 /* Pop each job_end subroutine and call it */
302 static void job_end_pop(JCR *jcr)
304 void (*job_end_cb)(JCR *jcr, void *ctx);
306 for (int i=jcr->job_end_push.size()-1; i > 0; ) {
307 ctx = jcr->job_end_push.get(i--);
308 job_end_cb = (void (*)(JCR *,void *))jcr->job_end_push.get(i--);
309 job_end_cb(jcr, ctx);
313 void create_jcr_key()
315 int status = pthread_key_create(&jcr_key, NULL);
318 Jmsg1(NULL, M_ABORT, 0, _("pthread key create failed: ERR=%s\n"),
319 be.bstrerror(status));
324 * Create a Job Control Record and link it into JCR chain
325 * Returns newly allocated JCR
326 * Note, since each daemon has a different JCR, he passes
329 JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
332 MQUEUE_ITEM *item = NULL;
333 struct sigaction sigtimer;
336 Dmsg0(dbglvl, "Enter new_jcr\n");
337 status = pthread_once(&key_once, create_jcr_key);
340 Jmsg1(NULL, M_ABORT, 0, _("pthread_once failed. ERR=%s\n"), be.bstrerror(status));
342 jcr = (JCR *)malloc(size);
343 memset(jcr, 0, size);
344 jcr->my_thread_id = pthread_self();
345 jcr->msg_queue = New(dlist(item, &item->link));
346 jcr->job_end_push.init(1, false);
347 jcr->sched_time = time(NULL);
348 jcr->daemon_free_jcr = daemon_free_jcr; /* plug daemon free routine */
350 jcr->inc_use_count();
351 jcr->VolumeName = get_pool_memory(PM_FNAME);
352 jcr->VolumeName[0] = 0;
353 jcr->errmsg = get_pool_memory(PM_MESSAGE);
355 /* Setup some dummy values */
356 bstrncpy(jcr->Job, "*System*", sizeof(jcr->Job));
358 jcr->setJobType(JT_SYSTEM); /* internal job until defined */
359 jcr->setJobLevel(L_NONE);
360 jcr->setJobStatus(JS_Created); /* ready to run */
362 sigtimer.sa_flags = 0;
363 sigtimer.sa_handler = timeout_handler;
364 sigfillset(&sigtimer.sa_mask);
365 sigaction(TIMEOUT_SIGNAL, &sigtimer, NULL);
368 * Locking jobs is a global lock that is needed
369 * so that the Director can stop new jobs from being
370 * added to the jcr chain while it processes a new
371 * conf file and does the job_end_push().
376 jcrs = New(dlist(jcr, &jcr->link));
387 * Remove a JCR from the chain
388 * NOTE! The chain must be locked prior to calling
391 static void remove_jcr(JCR *jcr)
393 Dmsg0(dbglvl, "Enter remove_jcr\n");
395 Emsg0(M_ABORT, 0, _("NULL jcr.\n"));
398 Dmsg0(dbglvl, "Leave remove_jcr\n");
402 * Free stuff common to all JCRs. N.B. Be careful to include only
403 * generic stuff in the common part of the jcr.
405 static void free_common_jcr(JCR *jcr)
407 jcr->destroy_mutex();
409 if (jcr->msg_queue) {
410 delete jcr->msg_queue;
411 jcr->msg_queue = NULL;
413 close_msg(jcr); /* close messages for this job */
415 /* do this after closing messages */
416 if (jcr->client_name) {
417 free_pool_memory(jcr->client_name);
418 jcr->client_name = NULL;
422 free_pool_memory(jcr->attr);
426 if (jcr->sd_auth_key) {
427 free(jcr->sd_auth_key);
428 jcr->sd_auth_key = NULL;
430 if (jcr->VolumeName) {
431 free_pool_memory(jcr->VolumeName);
432 jcr->VolumeName = NULL;
435 if (jcr->dir_bsock) {
436 bnet_close(jcr->dir_bsock);
437 jcr->dir_bsock = NULL;
440 free_pool_memory(jcr->errmsg);
447 if (jcr->RegexWhere) {
448 free(jcr->RegexWhere);
449 jcr->RegexWhere = NULL;
451 if (jcr->where_bregexp) {
452 free_bregexps(jcr->where_bregexp);
453 delete jcr->where_bregexp;
454 jcr->where_bregexp = NULL;
456 if (jcr->cached_path) {
457 free_pool_memory(jcr->cached_path);
458 jcr->cached_path = NULL;
462 free_guid_list(jcr->id_list);
465 remove_jcr_from_tsd(jcr);
470 * Global routine to free a jcr
473 void b_free_jcr(const char *file, int line, JCR *jcr)
475 struct s_last_job *je;
477 Dmsg3(dbglvl, "Enter free_jcr jid=%u from %s:%d\n", jcr->JobId, file, line);
481 void free_jcr(JCR *jcr)
483 struct s_last_job *je;
485 Dmsg3(dbglvl, "Enter free_jcr jid=%u use_count=%d Job=%s\n",
486 jcr->JobId, jcr->use_count(), jcr->Job);
491 jcr->dec_use_count(); /* decrement use count */
492 if (jcr->use_count() < 0) {
493 Jmsg2(jcr, M_ERROR, 0, _("JCR use_count=%d JobId=%d\n"),
494 jcr->use_count(), jcr->JobId);
496 if (jcr->JobId > 0) {
497 Dmsg3(dbglvl, "Dec free_jcr jid=%u use_count=%d Job=%s\n",
498 jcr->JobId, jcr->use_count(), jcr->Job);
500 if (jcr->use_count() > 0) { /* if in use */
504 if (jcr->JobId > 0) {
505 Dmsg3(dbglvl, "remove jcr jid=%u use_count=%d Job=%s\n",
506 jcr->JobId, jcr->use_count(), jcr->Job);
508 remove_jcr(jcr); /* remove Jcr from chain */
511 dequeue_messages(jcr);
512 job_end_pop(jcr); /* pop and call hooked routines */
514 Dmsg1(dbglvl, "End job=%d\n", jcr->JobId);
516 /* Keep some statistics */
517 switch (jcr->get_JobType()) {
524 /* Keep list of last jobs, but not Console where JobId==0 */
525 if (jcr->JobId > 0) {
526 lock_last_jobs_list();
528 je = (struct s_last_job *)malloc(sizeof(struct s_last_job));
529 memset(je, 0, sizeof(struct s_last_job)); /* zero in case unset fields */
530 je->Errors = jcr->JobErrors;
531 je->JobType = jcr->get_JobType();
532 je->JobId = jcr->JobId;
533 je->VolSessionId = jcr->VolSessionId;
534 je->VolSessionTime = jcr->VolSessionTime;
535 bstrncpy(je->Job, jcr->Job, sizeof(je->Job));
536 je->JobFiles = jcr->JobFiles;
537 je->JobBytes = jcr->JobBytes;
538 je->JobStatus = jcr->JobStatus;
539 je->JobLevel = jcr->get_JobLevel();
540 je->start_time = jcr->start_time;
541 je->end_time = time(NULL);
544 init_last_jobs_list();
546 last_jobs->append(je);
547 if (last_jobs->size() > max_last_jobs) {
548 je = (struct s_last_job *)last_jobs->first();
549 last_jobs->remove(je);
552 unlock_last_jobs_list();
559 if (jcr->daemon_free_jcr) {
560 jcr->daemon_free_jcr(jcr); /* call daemon free routine */
563 free_common_jcr(jcr);
564 close_msg(NULL); /* flush any daemon messages */
565 garbage_collect_memory_pool();
566 Dmsg0(dbglvl, "Exit free_jcr\n");
570 * Remove jcr from thread specific data, but
571 * but make sure it is us who are attached.
573 void remove_jcr_from_tsd(JCR *jcr)
575 JCR *tjcr = get_jcr_from_tsd();
577 set_jcr_in_tsd(INVALID_JCR);
582 * Put this jcr in the thread specifc data
584 void set_jcr_in_tsd(JCR *jcr)
586 int status = pthread_setspecific(jcr_key, (void *)jcr);
589 Jmsg1(jcr, M_ABORT, 0, _("pthread_setspecific failed: ERR=%s\n"), be.bstrerror(status));
594 * Give me the jcr that is attached to this thread
596 JCR *get_jcr_from_tsd()
598 JCR *jcr = (JCR *)pthread_getspecific(jcr_key);
599 // printf("get_jcr_from_tsd: jcr=%p\n", jcr);
600 /* set any INVALID_JCR to NULL which the rest of Bacula understands */
601 if (jcr == INVALID_JCR) {
609 * Find which JobId corresponds to the current thread
611 uint32_t get_jobid_from_tsd()
615 jcr = get_jcr_from_tsd();
616 // printf("get_jobid_from_tsr: jcr=%p\n", jcr);
618 JobId = (uint32_t)jcr->JobId;
624 * Given a JobId, find the JCR
625 * Returns: jcr on success
628 JCR *get_jcr_by_id(uint32_t JobId)
633 if (jcr->JobId == JobId) {
634 jcr->inc_use_count();
635 Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
636 jcr->JobId, jcr->use_count(), jcr->Job);
645 * Given a SessionId and SessionTime, find the JCR
646 * Returns: jcr on success
649 JCR *get_jcr_by_session(uint32_t SessionId, uint32_t SessionTime)
654 if (jcr->VolSessionId == SessionId &&
655 jcr->VolSessionTime == SessionTime) {
656 jcr->inc_use_count();
657 Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
658 jcr->JobId, jcr->use_count(), jcr->Job);
668 * Given a Job, find the JCR
669 * compares on the number of characters in Job
670 * thus allowing partial matches.
671 * Returns: jcr on success
674 JCR *get_jcr_by_partial_name(char *Job)
684 if (strncmp(Job, jcr->Job, len) == 0) {
685 jcr->inc_use_count();
686 Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
687 jcr->JobId, jcr->use_count(), jcr->Job);
697 * Given a Job, find the JCR
698 * requires an exact match of names.
699 * Returns: jcr on success
702 JCR *get_jcr_by_full_name(char *Job)
710 if (strcmp(jcr->Job, Job) == 0) {
711 jcr->inc_use_count();
712 Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
713 jcr->JobId, jcr->use_count(), jcr->Job);
722 * Priority runs from 0 (lowest) to 10 (highest)
724 static int get_status_priority(int JobStatus)
728 case JS_ErrorTerminated:
745 static void update_wait_time(JCR *jcr, int newJobStatus)
747 bool enter_in_waittime;
748 int oldJobStatus = jcr->JobStatus;
750 switch (newJobStatus) {
755 case JS_WaitStoreRes:
757 case JS_WaitClientRes:
759 case JS_WaitPriority:
760 enter_in_waittime = true;
763 enter_in_waittime = false; /* not a Wait situation */
768 * If we were previously waiting and are not any more
769 * we want to update the wait_time variable, which is
770 * the start of waiting.
772 switch (oldJobStatus) {
777 case JS_WaitStoreRes:
779 case JS_WaitClientRes:
781 case JS_WaitPriority:
782 if (!enter_in_waittime) { /* we get out the wait time */
783 jcr->wait_time_sum += (time(NULL) - jcr->wait_time);
788 /* if wait state is new, we keep current time for watchdog MaxWaitTime */
790 if (enter_in_waittime) {
791 jcr->wait_time = time(NULL);
797 void set_jcr_job_status(JCR *jcr, int JobStatus)
799 jcr->setJobStatus(JobStatus);
802 void JCR::setJobStatus(int JobStatus)
805 int priority, old_priority;
806 int oldJobStatus = JobStatus;
807 priority = get_status_priority(JobStatus);
808 old_priority = get_status_priority(oldJobStatus);
810 Dmsg2(800, "set_jcr_job_status(%s, %c)\n", Job, JobStatus);
812 /* Update wait_time depending on newJobStatus and oldJobStatus */
813 update_wait_time(this, JobStatus);
816 * For a set of errors, ... keep the current status
817 * so it isn't lost. For all others, set it.
819 Dmsg3(300, "jid=%u OnEntry JobStatus=%c set=%c\n", (uint32_t)JobId,
820 JobStatus, JobStatus);
821 if (priority >= old_priority) {
822 jcr->JobStatus = JobStatus; /* replace with new priority */
825 if (oldJobStatus != jcr->JobStatus) {
826 Dmsg3(200, "jid=%u leave set_old_job_status=%c new_set=%c\n", (uint32_t)jcr->JobId,
827 oldJobStatus, JobStatus);
828 // generate_plugin_event(jcr, bEventStatusChange, NULL);
832 #ifdef TRACE_JCR_CHAIN
833 static int lock_count = 0;
839 #ifdef TRACE_JCR_CHAIN
840 static void b_lock_jcr_chain(const char *fname, int line)
842 static void lock_jcr_chain()
845 #ifdef TRACE_JCR_CHAIN
846 Dmsg3(dbglvl, "Lock jcr chain %d from %s:%d\n", ++lock_count, fname, line);
854 #ifdef TRACE_JCR_CHAIN
855 static void b_unlock_jcr_chain(const char *fname, int line)
857 static void unlock_jcr_chain()
860 #ifdef TRACE_JCR_CHAIN
861 Dmsg3(dbglvl, "Unlock jcr chain %d from %s:%d\n", lock_count--, fname, line);
867 * Start walk of jcr chain
868 * The proper way to walk the jcr chain is:
875 * It is possible to leave out the endeach_jcr(jcr), but
876 * in that case, the last jcr referenced must be explicitly
882 JCR *jcr_walk_start()
886 jcr = (JCR *)jcrs->first();
888 jcr->inc_use_count();
889 if (jcr->JobId > 0) {
890 Dmsg3(dbglvl, "Inc walk_start jid=%u use_count=%d Job=%s\n",
891 jcr->JobId, jcr->use_count(), jcr->Job);
899 * Get next jcr from chain, and release current one
901 JCR *jcr_walk_next(JCR *prev_jcr)
906 jcr = (JCR *)jcrs->next(prev_jcr);
908 jcr->inc_use_count();
909 if (jcr->JobId > 0) {
910 Dmsg3(dbglvl, "Inc walk_next jid=%u use_count=%d Job=%s\n",
911 jcr->JobId, jcr->use_count(), jcr->Job);
922 * Release last jcr referenced
924 void jcr_walk_end(JCR *jcr)
927 if (jcr->JobId > 0) {
928 Dmsg3(dbglvl, "Free walk_end jid=%u use_count=%d Job=%s\n",
929 jcr->JobId, jcr->use_count(), jcr->Job);
937 * Setup to call the timeout check routine every 30 seconds
938 * This routine will check any timers that have been enabled.
940 bool init_jcr_subsystem(void)
942 watchdog_t *wd = new_watchdog();
944 wd->one_shot = false;
945 wd->interval = 30; /* FIXME: should be configurable somewhere, even
946 if only with a #define */
947 wd->callback = jcr_timeout_check;
949 register_watchdog(wd);
954 static void jcr_timeout_check(watchdog_t *self)
960 Dmsg0(dbglvl, "Start JCR timeout checks\n");
962 /* Walk through all JCRs checking if any one is
963 * blocked for more than specified max time.
966 Dmsg2(dbglvl, "jcr_timeout_check JobId=%u jcr=0x%x\n", jcr->JobId, jcr);
967 if (jcr->JobId == 0) {
970 bs = jcr->store_bsock;
972 timer_start = bs->timer_start;
973 if (timer_start && (watchdog_time - timer_start) > bs->timeout) {
974 bs->timer_start = 0; /* turn off timer */
976 Qmsg(jcr, M_ERROR, 0, _(
977 "Watchdog sending kill after %d secs to thread stalled reading Storage daemon.\n"),
978 watchdog_time - timer_start);
979 pthread_kill(jcr->my_thread_id, TIMEOUT_SIGNAL);
982 bs = jcr->file_bsock;
984 timer_start = bs->timer_start;
985 if (timer_start && (watchdog_time - timer_start) > bs->timeout) {
986 bs->timer_start = 0; /* turn off timer */
988 Qmsg(jcr, M_ERROR, 0, _(
989 "Watchdog sending kill after %d secs to thread stalled reading File daemon.\n"),
990 watchdog_time - timer_start);
991 pthread_kill(jcr->my_thread_id, TIMEOUT_SIGNAL);
996 timer_start = bs->timer_start;
997 if (timer_start && (watchdog_time - timer_start) > bs->timeout) {
998 bs->timer_start = 0; /* turn off timer */
1000 Qmsg(jcr, M_ERROR, 0, _(
1001 "Watchdog sending kill after %d secs to thread stalled reading Director.\n"),
1002 watchdog_time - timer_start);
1003 pthread_kill(jcr->my_thread_id, TIMEOUT_SIGNAL);
1009 Dmsg0(dbglvl, "Finished JCR timeout checks\n");
1013 * Return next JobId from comma separated list
1016 * 1 if next JobId returned
1017 * 0 if no more JobIds are in list
1018 * -1 there is an error
1020 int get_next_jobid_from_list(char **p, uint32_t *JobId)
1022 const int maxlen = 30;
1023 char jobid[maxlen+1];
1027 for (int i=0; i<maxlen; i++) {
1030 } else if (*q == ',') {
1037 if (jobid[0] == 0) {
1039 } else if (!is_a_number(jobid)) {
1040 return -1; /* error */
1043 *JobId = str_to_int64(jobid);
1048 * Timeout signal comes here
1050 extern "C" void timeout_handler(int sig)
1052 return; /* thus interrupting the function */
1055 /* Used to display specific daemon information after a fatal signal
1056 * (like B_DB in the director)
1058 #define MAX_DBG_HOOK 10
1059 static dbg_jcr_hook_t *dbg_jcr_hooks[MAX_DBG_HOOK];
1060 static int dbg_jcr_handler_count;
1062 void dbg_jcr_add_hook(dbg_jcr_hook_t *fct)
1064 ASSERT(dbg_jcr_handler_count < MAX_DBG_HOOK);
1065 dbg_jcr_hooks[dbg_jcr_handler_count++] = fct;
1071 * This function should be used ONLY after a fatal signal. We walk through the
1072 * JCR chain without doing any lock, bacula should not be running.
1074 void _dbg_print_jcr(FILE *fp)
1076 char buf1[128], buf2[128], buf3[128], buf4[128];
1081 fprintf(fp, "Attempt to dump current JCRs\n");
1083 for (JCR *jcr = (JCR *)jcrs->first(); jcr ; jcr = (JCR *)jcrs->next(jcr)) {
1084 if (!jcr) { /* protect us against something ? */
1088 fprintf(fp, "JCR=%p JobId=%i name=%s JobStatus=%c\n",
1089 jcr, jcr->JobId, jcr->Job, jcr->JobStatus);
1091 fprintf(fp, "\tuse_count=%i\n",
1094 /* KES -- removed non-portable code referencing pthread_t */
1095 fprintf(fp, "\tuse_count=%d\n", jcr->use_count());
1097 fprintf(fp, "\tJobType=%c JobLevel=%c\n",
1098 jcr->get_JobType(), jcr->get_JobLevel());
1099 bstrftime(buf1, sizeof(buf1), jcr->sched_time);
1100 bstrftime(buf2, sizeof(buf2), jcr->start_time);
1101 bstrftime(buf3, sizeof(buf3), jcr->end_time);
1102 bstrftime(buf4, sizeof(buf4), jcr->wait_time);
1103 fprintf(fp, "\tsched_time=%s start_time=%s\n\tend_time=%s wait_time=%s\n",
1104 buf1, buf2, buf3, buf4);
1105 fprintf(fp, "\tdequeing=%i\n", jcr->dequeuing);
1106 fprintf(fp, "\tdb=%p db_batch=%p batch_started=%i\n",
1107 jcr->db, jcr->db_batch, jcr->batch_started);
1109 for(int i=0; i < dbg_jcr_handler_count; i++) {
1110 dbg_jcr_hook_t *fct = dbg_jcr_hooks[i];