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);
314 * Create thread key for thread specific data
316 void create_jcr_key()
318 int status = pthread_key_create(&jcr_key, NULL);
321 Jmsg1(NULL, M_ABORT, 0, _("pthread key create failed: ERR=%s\n"),
322 be.bstrerror(status));
327 * Create a Job Control Record and link it into JCR chain
328 * Returns newly allocated JCR
329 * Note, since each daemon has a different JCR, he passes
332 JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
335 MQUEUE_ITEM *item = NULL;
336 struct sigaction sigtimer;
339 Dmsg0(dbglvl, "Enter new_jcr\n");
340 status = pthread_once(&key_once, create_jcr_key);
343 Jmsg1(NULL, M_ABORT, 0, _("pthread_once failed. ERR=%s\n"), be.bstrerror(status));
345 jcr = (JCR *)malloc(size);
346 memset(jcr, 0, size);
347 jcr->my_thread_id = pthread_self();
348 jcr->msg_queue = New(dlist(item, &item->link));
349 jcr->job_end_push.init(1, false);
350 jcr->sched_time = time(NULL);
351 jcr->daemon_free_jcr = daemon_free_jcr; /* plug daemon free routine */
353 jcr->inc_use_count();
354 jcr->VolumeName = get_pool_memory(PM_FNAME);
355 jcr->VolumeName[0] = 0;
356 jcr->errmsg = get_pool_memory(PM_MESSAGE);
358 /* Setup some dummy values */
359 bstrncpy(jcr->Job, "*System*", sizeof(jcr->Job));
361 jcr->setJobType(JT_SYSTEM); /* internal job until defined */
362 jcr->setJobLevel(L_NONE);
363 jcr->setJobStatus(JS_Created); /* ready to run */
365 sigtimer.sa_flags = 0;
366 sigtimer.sa_handler = timeout_handler;
367 sigfillset(&sigtimer.sa_mask);
368 sigaction(TIMEOUT_SIGNAL, &sigtimer, NULL);
371 * Locking jobs is a global lock that is needed
372 * so that the Director can stop new jobs from being
373 * added to the jcr chain while it processes a new
374 * conf file and does the job_end_push().
379 jcrs = New(dlist(jcr, &jcr->link));
390 * Remove a JCR from the chain
391 * NOTE! The chain must be locked prior to calling
394 static void remove_jcr(JCR *jcr)
396 Dmsg0(dbglvl, "Enter remove_jcr\n");
398 Emsg0(M_ABORT, 0, _("NULL jcr.\n"));
401 Dmsg0(dbglvl, "Leave remove_jcr\n");
405 * Free stuff common to all JCRs. N.B. Be careful to include only
406 * generic stuff in the common part of the jcr.
408 static void free_common_jcr(JCR *jcr)
410 jcr->destroy_mutex();
412 if (jcr->msg_queue) {
413 delete jcr->msg_queue;
414 jcr->msg_queue = NULL;
416 close_msg(jcr); /* close messages for this job */
418 /* do this after closing messages */
419 if (jcr->client_name) {
420 free_pool_memory(jcr->client_name);
421 jcr->client_name = NULL;
425 free_pool_memory(jcr->attr);
429 if (jcr->sd_auth_key) {
430 free(jcr->sd_auth_key);
431 jcr->sd_auth_key = NULL;
433 if (jcr->VolumeName) {
434 free_pool_memory(jcr->VolumeName);
435 jcr->VolumeName = NULL;
438 if (jcr->dir_bsock) {
439 bnet_close(jcr->dir_bsock);
440 jcr->dir_bsock = NULL;
443 free_pool_memory(jcr->errmsg);
450 if (jcr->RegexWhere) {
451 free(jcr->RegexWhere);
452 jcr->RegexWhere = NULL;
454 if (jcr->where_bregexp) {
455 free_bregexps(jcr->where_bregexp);
456 delete jcr->where_bregexp;
457 jcr->where_bregexp = NULL;
459 if (jcr->cached_path) {
460 free_pool_memory(jcr->cached_path);
461 jcr->cached_path = NULL;
465 free_guid_list(jcr->id_list);
468 remove_jcr_from_tsd(jcr);
473 * Global routine to free a jcr
476 void b_free_jcr(const char *file, int line, JCR *jcr)
478 struct s_last_job *je;
480 Dmsg3(dbglvl, "Enter free_jcr jid=%u from %s:%d\n", jcr->JobId, file, line);
484 void free_jcr(JCR *jcr)
486 struct s_last_job *je;
488 Dmsg3(dbglvl, "Enter free_jcr jid=%u use_count=%d Job=%s\n",
489 jcr->JobId, jcr->use_count(), jcr->Job);
494 jcr->dec_use_count(); /* decrement use count */
495 if (jcr->use_count() < 0) {
496 Jmsg2(jcr, M_ERROR, 0, _("JCR use_count=%d JobId=%d\n"),
497 jcr->use_count(), jcr->JobId);
499 if (jcr->JobId > 0) {
500 Dmsg3(dbglvl, "Dec free_jcr jid=%u use_count=%d Job=%s\n",
501 jcr->JobId, jcr->use_count(), jcr->Job);
503 if (jcr->use_count() > 0) { /* if in use */
507 if (jcr->JobId > 0) {
508 Dmsg3(dbglvl, "remove jcr jid=%u use_count=%d Job=%s\n",
509 jcr->JobId, jcr->use_count(), jcr->Job);
511 remove_jcr(jcr); /* remove Jcr from chain */
514 dequeue_messages(jcr);
515 job_end_pop(jcr); /* pop and call hooked routines */
517 Dmsg1(dbglvl, "End job=%d\n", jcr->JobId);
519 /* Keep some statistics */
520 switch (jcr->get_JobType()) {
527 /* Keep list of last jobs, but not Console where JobId==0 */
528 if (jcr->JobId > 0) {
529 lock_last_jobs_list();
531 je = (struct s_last_job *)malloc(sizeof(struct s_last_job));
532 memset(je, 0, sizeof(struct s_last_job)); /* zero in case unset fields */
533 je->Errors = jcr->JobErrors;
534 je->JobType = jcr->get_JobType();
535 je->JobId = jcr->JobId;
536 je->VolSessionId = jcr->VolSessionId;
537 je->VolSessionTime = jcr->VolSessionTime;
538 bstrncpy(je->Job, jcr->Job, sizeof(je->Job));
539 je->JobFiles = jcr->JobFiles;
540 je->JobBytes = jcr->JobBytes;
541 je->JobStatus = jcr->JobStatus;
542 je->JobLevel = jcr->get_JobLevel();
543 je->start_time = jcr->start_time;
544 je->end_time = time(NULL);
547 init_last_jobs_list();
549 last_jobs->append(je);
550 if (last_jobs->size() > max_last_jobs) {
551 je = (struct s_last_job *)last_jobs->first();
552 last_jobs->remove(je);
555 unlock_last_jobs_list();
562 if (jcr->daemon_free_jcr) {
563 jcr->daemon_free_jcr(jcr); /* call daemon free routine */
566 free_common_jcr(jcr);
567 close_msg(NULL); /* flush any daemon messages */
568 garbage_collect_memory_pool();
569 Dmsg0(dbglvl, "Exit free_jcr\n");
573 * Remove jcr from thread specific data, but
574 * but make sure it is us who are attached.
576 void remove_jcr_from_tsd(JCR *jcr)
578 JCR *tjcr = get_jcr_from_tsd();
580 set_jcr_in_tsd(INVALID_JCR);
585 * Put this jcr in the thread specifc data
587 void set_jcr_in_tsd(JCR *jcr)
589 int status = pthread_setspecific(jcr_key, (void *)jcr);
592 Jmsg1(jcr, M_ABORT, 0, _("pthread_setspecific failed: ERR=%s\n"), be.bstrerror(status));
597 * Give me the jcr that is attached to this thread
599 JCR *get_jcr_from_tsd()
601 JCR *jcr = (JCR *)pthread_getspecific(jcr_key);
602 // printf("get_jcr_from_tsd: jcr=%p\n", jcr);
603 /* set any INVALID_JCR to NULL which the rest of Bacula understands */
604 if (jcr == INVALID_JCR) {
612 * Find which JobId corresponds to the current thread
614 uint32_t get_jobid_from_tsd()
618 jcr = get_jcr_from_tsd();
619 // printf("get_jobid_from_tsr: jcr=%p\n", jcr);
621 JobId = (uint32_t)jcr->JobId;
627 * Given a JobId, find the JCR
628 * Returns: jcr on success
631 JCR *get_jcr_by_id(uint32_t JobId)
636 if (jcr->JobId == JobId) {
637 jcr->inc_use_count();
638 Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
639 jcr->JobId, jcr->use_count(), jcr->Job);
648 * Given a thread id, find the JobId
649 * Returns: JobId on success
652 uint32_t get_jobid_from_tid(pthread_t tid)
658 if (pthread_equal(jcr->my_thread_id, tid)) {
672 * Given a SessionId and SessionTime, find the JCR
673 * Returns: jcr on success
676 JCR *get_jcr_by_session(uint32_t SessionId, uint32_t SessionTime)
681 if (jcr->VolSessionId == SessionId &&
682 jcr->VolSessionTime == SessionTime) {
683 jcr->inc_use_count();
684 Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
685 jcr->JobId, jcr->use_count(), jcr->Job);
695 * Given a Job, find the JCR
696 * compares on the number of characters in Job
697 * thus allowing partial matches.
698 * Returns: jcr on success
701 JCR *get_jcr_by_partial_name(char *Job)
711 if (strncmp(Job, jcr->Job, len) == 0) {
712 jcr->inc_use_count();
713 Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
714 jcr->JobId, jcr->use_count(), jcr->Job);
724 * Given a Job, find the JCR
725 * requires an exact match of names.
726 * Returns: jcr on success
729 JCR *get_jcr_by_full_name(char *Job)
737 if (strcmp(jcr->Job, Job) == 0) {
738 jcr->inc_use_count();
739 Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
740 jcr->JobId, jcr->use_count(), jcr->Job);
748 static void update_wait_time(JCR *jcr, int newJobStatus)
750 bool enter_in_waittime;
751 int oldJobStatus = jcr->JobStatus;
753 switch (newJobStatus) {
758 case JS_WaitStoreRes:
760 case JS_WaitClientRes:
762 case JS_WaitPriority:
763 enter_in_waittime = true;
766 enter_in_waittime = false; /* not a Wait situation */
771 * If we were previously waiting and are not any more
772 * we want to update the wait_time variable, which is
773 * the start of waiting.
775 switch (oldJobStatus) {
780 case JS_WaitStoreRes:
782 case JS_WaitClientRes:
784 case JS_WaitPriority:
785 if (!enter_in_waittime) { /* we get out the wait time */
786 jcr->wait_time_sum += (time(NULL) - jcr->wait_time);
791 /* if wait state is new, we keep current time for watchdog MaxWaitTime */
793 if (enter_in_waittime) {
794 jcr->wait_time = time(NULL);
801 * Priority runs from 0 (lowest) to 10 (highest)
803 static int get_status_priority(int JobStatus)
807 case JS_ErrorTerminated:
824 void set_jcr_job_status(JCR *jcr, int JobStatus)
826 jcr->setJobStatus(JobStatus);
829 void JCR::setJobStatus(int newJobStatus)
832 int priority, old_priority;
833 int oldJobStatus = jcr->JobStatus;
834 priority = get_status_priority(newJobStatus);
835 old_priority = get_status_priority(oldJobStatus);
837 Dmsg2(800, "set_jcr_job_status(%s, %c)\n", Job, newJobStatus);
839 /* Update wait_time depending on newJobStatus and oldJobStatus */
840 update_wait_time(jcr, newJobStatus);
843 * For a set of errors, ... keep the current status
844 * so it isn't lost. For all others, set it.
846 Dmsg2(800, "OnEntry JobStatus=%c newJobstatus=%c\n", oldJobStatus, newJobStatus);
848 * If status priority is > than proposed new status, change it.
849 * If status priority == new priority and both are zero, take
851 * If it is not zero, then we keep the first non-zero "error" that
854 if (priority > old_priority || (
855 priority == 0 && old_priority == 0)) {
856 Dmsg4(800, "Set new stat. old: %c,%d new: %c,%d\n",
857 jcr->JobStatus, old_priority, newJobStatus, priority);
858 jcr->JobStatus = newJobStatus; /* replace with new status */
861 if (oldJobStatus != jcr->JobStatus) {
862 Dmsg2(800, "leave set_job_status old=%c new=%c\n", oldJobStatus, newJobStatus);
863 // generate_plugin_event(jcr, bEventStatusChange, NULL);
867 #ifdef TRACE_JCR_CHAIN
868 static int lock_count = 0;
874 #ifdef TRACE_JCR_CHAIN
875 static void b_lock_jcr_chain(const char *fname, int line)
877 static void lock_jcr_chain()
880 #ifdef TRACE_JCR_CHAIN
881 Dmsg3(dbglvl, "Lock jcr chain %d from %s:%d\n", ++lock_count, fname, line);
889 #ifdef TRACE_JCR_CHAIN
890 static void b_unlock_jcr_chain(const char *fname, int line)
892 static void unlock_jcr_chain()
895 #ifdef TRACE_JCR_CHAIN
896 Dmsg3(dbglvl, "Unlock jcr chain %d from %s:%d\n", lock_count--, fname, line);
902 * Start walk of jcr chain
903 * The proper way to walk the jcr chain is:
910 * It is possible to leave out the endeach_jcr(jcr), but
911 * in that case, the last jcr referenced must be explicitly
917 JCR *jcr_walk_start()
921 jcr = (JCR *)jcrs->first();
923 jcr->inc_use_count();
924 if (jcr->JobId > 0) {
925 Dmsg3(dbglvl, "Inc walk_start jid=%u use_count=%d Job=%s\n",
926 jcr->JobId, jcr->use_count(), jcr->Job);
934 * Get next jcr from chain, and release current one
936 JCR *jcr_walk_next(JCR *prev_jcr)
941 jcr = (JCR *)jcrs->next(prev_jcr);
943 jcr->inc_use_count();
944 if (jcr->JobId > 0) {
945 Dmsg3(dbglvl, "Inc walk_next jid=%u use_count=%d Job=%s\n",
946 jcr->JobId, jcr->use_count(), jcr->Job);
957 * Release last jcr referenced
959 void jcr_walk_end(JCR *jcr)
962 if (jcr->JobId > 0) {
963 Dmsg3(dbglvl, "Free walk_end jid=%u use_count=%d Job=%s\n",
964 jcr->JobId, jcr->use_count(), jcr->Job);
972 * Setup to call the timeout check routine every 30 seconds
973 * This routine will check any timers that have been enabled.
975 bool init_jcr_subsystem(void)
977 watchdog_t *wd = new_watchdog();
979 wd->one_shot = false;
980 wd->interval = 30; /* FIXME: should be configurable somewhere, even
981 if only with a #define */
982 wd->callback = jcr_timeout_check;
984 register_watchdog(wd);
989 static void jcr_timeout_check(watchdog_t *self)
995 Dmsg0(dbglvl, "Start JCR timeout checks\n");
997 /* Walk through all JCRs checking if any one is
998 * blocked for more than specified max time.
1001 Dmsg2(dbglvl, "jcr_timeout_check JobId=%u jcr=0x%x\n", jcr->JobId, jcr);
1002 if (jcr->JobId == 0) {
1005 bs = jcr->store_bsock;
1007 timer_start = bs->timer_start;
1008 if (timer_start && (watchdog_time - timer_start) > bs->timeout) {
1009 bs->timer_start = 0; /* turn off timer */
1010 bs->set_timed_out();
1011 Qmsg(jcr, M_ERROR, 0, _(
1012 "Watchdog sending kill after %d secs to thread stalled reading Storage daemon.\n"),
1013 watchdog_time - timer_start);
1014 pthread_kill(jcr->my_thread_id, TIMEOUT_SIGNAL);
1017 bs = jcr->file_bsock;
1019 timer_start = bs->timer_start;
1020 if (timer_start && (watchdog_time - timer_start) > bs->timeout) {
1021 bs->timer_start = 0; /* turn off timer */
1022 bs->set_timed_out();
1023 Qmsg(jcr, M_ERROR, 0, _(
1024 "Watchdog sending kill after %d secs to thread stalled reading File daemon.\n"),
1025 watchdog_time - timer_start);
1026 pthread_kill(jcr->my_thread_id, TIMEOUT_SIGNAL);
1029 bs = jcr->dir_bsock;
1031 timer_start = bs->timer_start;
1032 if (timer_start && (watchdog_time - timer_start) > bs->timeout) {
1033 bs->timer_start = 0; /* turn off timer */
1034 bs->set_timed_out();
1035 Qmsg(jcr, M_ERROR, 0, _(
1036 "Watchdog sending kill after %d secs to thread stalled reading Director.\n"),
1037 watchdog_time - timer_start);
1038 pthread_kill(jcr->my_thread_id, TIMEOUT_SIGNAL);
1044 Dmsg0(dbglvl, "Finished JCR timeout checks\n");
1048 * Return next JobId from comma separated list
1051 * 1 if next JobId returned
1052 * 0 if no more JobIds are in list
1053 * -1 there is an error
1055 int get_next_jobid_from_list(char **p, uint32_t *JobId)
1057 const int maxlen = 30;
1058 char jobid[maxlen+1];
1062 for (int i=0; i<maxlen; i++) {
1065 } else if (*q == ',') {
1072 if (jobid[0] == 0) {
1074 } else if (!is_a_number(jobid)) {
1075 return -1; /* error */
1078 *JobId = str_to_int64(jobid);
1083 * Timeout signal comes here
1085 extern "C" void timeout_handler(int sig)
1087 return; /* thus interrupting the function */
1090 /* Used to display specific daemon information after a fatal signal
1091 * (like B_DB in the director)
1093 #define MAX_DBG_HOOK 10
1094 static dbg_jcr_hook_t *dbg_jcr_hooks[MAX_DBG_HOOK];
1095 static int dbg_jcr_handler_count;
1097 void dbg_jcr_add_hook(dbg_jcr_hook_t *fct)
1099 ASSERT(dbg_jcr_handler_count < MAX_DBG_HOOK);
1100 dbg_jcr_hooks[dbg_jcr_handler_count++] = fct;
1106 * This function should be used ONLY after a fatal signal. We walk through the
1107 * JCR chain without doing any lock, bacula should not be running.
1109 void _dbg_print_jcr(FILE *fp)
1111 char buf1[128], buf2[128], buf3[128], buf4[128];
1116 fprintf(fp, "Attempt to dump current JCRs\n");
1118 for (JCR *jcr = (JCR *)jcrs->first(); jcr ; jcr = (JCR *)jcrs->next(jcr)) {
1119 if (!jcr) { /* protect us against something ? */
1123 fprintf(fp, "JCR=%p JobId=%i name=%s JobStatus=%c\n",
1124 jcr, jcr->JobId, jcr->Job, jcr->JobStatus);
1126 fprintf(fp, "\tuse_count=%i\n",
1129 /* KES -- removed non-portable code referencing pthread_t */
1130 fprintf(fp, "\tuse_count=%d\n", jcr->use_count());
1132 fprintf(fp, "\tJobType=%c JobLevel=%c\n",
1133 jcr->get_JobType(), jcr->get_JobLevel());
1134 bstrftime(buf1, sizeof(buf1), jcr->sched_time);
1135 bstrftime(buf2, sizeof(buf2), jcr->start_time);
1136 bstrftime(buf3, sizeof(buf3), jcr->end_time);
1137 bstrftime(buf4, sizeof(buf4), jcr->wait_time);
1138 fprintf(fp, "\tsched_time=%s start_time=%s\n\tend_time=%s wait_time=%s\n",
1139 buf1, buf2, buf3, buf4);
1140 fprintf(fp, "\tdequeing=%i\n", jcr->dequeuing);
1141 fprintf(fp, "\tdb=%p db_batch=%p batch_started=%i\n",
1142 jcr->db, jcr->db_batch, jcr->batch_started);
1144 for(int i=0; i < dbg_jcr_handler_count; i++) {
1145 dbg_jcr_hook_t *fct = dbg_jcr_hooks[i];