src/lib/jcr.c
JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
{
   JCR *jcr;
   MQUEUE_ITEM *item = NULL;
   int status;

   Dmsg0(dbglvl, "Enter new_jcr\n");
   status = pthread_once(&key_once, create_jcr_key);
   if (status != 0) {
      berrno be;
      Jmsg1(NULL, M_ABORT, 0, _("pthread_once failed. ERR=%s\n"), be.bstrerror(status));
   }
   jcr = (JCR *)malloc(size);
   bmemzero(jcr, size);
   /* Note for the director, this value is changed in jobq.c */
   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->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->VolumeName = get_pool_memory(PM_FNAME);
   jcr->VolumeName[0] = 0;
   jcr->errmsg = get_pool_memory(PM_MESSAGE);
   jcr->errmsg[0] = 0;
   jcr->comment = get_pool_memory(PM_FNAME);
   jcr->comment[0] = 0;
   jcr->StatusErrMsg = get_pool_memory(PM_FNAME);
   jcr->StatusErrMsg[0] = 0;
   jcr->job_uid = -1;
   /* Setup some dummy values */
   bstrncpy(jcr->Job, "*System*", sizeof(jcr->Job));
   jcr->JobId = 0;
   jcr->setJobType(JT_SYSTEM);           /* internal job until defined */
   jcr->setJobLevel(L_NONE);
   jcr->setJobStatus(JS_Created);        /* ready to run */
#ifndef HAVE_WIN32
   struct sigaction sigtimer;
   sigtimer.sa_flags = 0;
   sigtimer.sa_handler = timeout_handler;
   sigfillset(&sigtimer.sa_mask);
   sigaction(TIMEOUT_SIGNAL, &sigtimer, NULL);
#endif

   /*
    * Locking jobs is a global lock that is needed
    * so that the Director can stop new jobs from being
    * added to the jcr chain while it processes a new
    * conf file and does the job_end_push().
    */
   lock_jobs();
   lock_jcr_chain();
   if (!jcrs) {
      jcrs = New(dlist(jcr, &jcr->link));
   }
   jcrs->append(jcr);
   unlock_jcr_chain();
   unlock_jobs();

   return jcr;
}
/*
 * Create a Job Control Record and link it into JCR chain
 * Returns newly allocated JCR
 * Note, since each daemon has a different JCR, he passes
 *  us the size.
 */
Create a Job Control Record and link it into JCR chain
Returns newly allocated JCR
Note, since each daemon has a different JCR, he passes
us the size.
Create a Job Control Record and link it into JCR chain Returns newly allocated JCR Note since each daemon has a different JCR he passes us the size .
JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
{
   JCR *jcr;
   MQUEUE_ITEM *item = NULL;
   int status;
   Dmsg0(dbglvl, "Enter new_jcr\n");
   status = pthread_once(&key_once, create_jcr_key);
   if (status != 0) {
      berrno be;
      Jmsg1(NULL, M_ABORT, 0, _("pthread_once failed. ERR=%s\n"), be.bstrerror(status));
   }
   jcr = (JCR *)malloc(size);
   bmemzero(jcr, 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->initial_sched_time = jcr->sched_time;
   jcr->daemon_free_jcr = daemon_free_jcr;    
   jcr->init_mutex();
   jcr->inc_use_count();
   jcr->VolumeName = get_pool_memory(PM_FNAME);
   jcr->VolumeName[0] = 0;
   jcr->errmsg = get_pool_memory(PM_MESSAGE);
   jcr->errmsg[0] = 0;
   jcr->comment = get_pool_memory(PM_FNAME);
   jcr->comment[0] = 0;
   jcr->StatusErrMsg = get_pool_memory(PM_FNAME);
   jcr->StatusErrMsg[0] = 0;
   jcr->job_uid = -1;
   bstrncpy(jcr->Job, "*System*", sizeof(jcr->Job));
   jcr->JobId = 0;
   jcr->setJobType(JT_SYSTEM);           
   jcr->setJobLevel(L_NONE);
   jcr->setJobStatus(JS_Created);        
#ifndef HAVE_WIN32
   struct sigaction sigtimer;
   sigtimer.sa_flags = 0;
   sigtimer.sa_handler = timeout_handler;
   sigfillset(&sigtimer.sa_mask);
   sigaction(TIMEOUT_SIGNAL, &sigtimer, NULL);
#endif
   lock_jobs();
   lock_jcr_chain();
   if (!jcrs) {
      jcrs = New(dlist(jcr, &jcr->link));
   }
   jcrs->append(jcr);
   unlock_jcr_chain();
   unlock_jobs();
   return jcr;
}
JCR * new_jcr ( int size , JCR_free_HANDLER * daemon_free_jcr ) { JCR * jcr ; MQUEUE_ITEM * item = NULL ; int status ; Dmsg0 ( dbglvl , " \n " ) ; status = pthread_once ( & key_once , create_jcr_key ) ; if ( status != 0 ) { berrno be ; Jmsg1 ( NULL , M_ABORT , 0 , _ ( " \n " ) , be . bstrerror ( status ) ) ; } jcr = ( JCR * ) malloc ( size ) ; bmemzero ( jcr , 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 , _ ( " \n " ) , be . bstrerror ( status ) ) ; } 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 ; jcr -> init_mutex ( ) ; jcr -> inc_use_count ( ) ; jcr -> VolumeName = get_pool_memory ( PM_FNAME ) ; jcr -> VolumeName [ 0 ] = 0 ; jcr -> errmsg = get_pool_memory ( PM_MESSAGE ) ; jcr -> errmsg [ 0 ] = 0 ; jcr -> comment = get_pool_memory ( PM_FNAME ) ; jcr -> comment [ 0 ] = 0 ; jcr -> StatusErrMsg = get_pool_memory ( PM_FNAME ) ; jcr -> StatusErrMsg [ 0 ] = 0 ; jcr -> job_uid = -1 ; bstrncpy ( jcr -> Job , " " , sizeof ( jcr -> Job ) ) ; jcr -> JobId = 0 ; jcr -> setJobType ( JT_SYSTEM ) ; jcr -> setJobLevel ( L_NONE ) ; jcr -> setJobStatus ( JS_Created ) ; #ifndef HAVE_WIN32 struct sigaction sigtimer ; sigtimer . sa_flags = 0 ; sigtimer . sa_handler = timeout_handler ; sigfillset ( & sigtimer . sa_mask ) ; sigaction ( TIMEOUT_SIGNAL , & sigtimer , NULL ) ; #endif lock_jobs ( ) ; lock_jcr_chain ( ) ; if ( ! jcrs ) { jcrs = New ( dlist ( jcr , & jcr -> link ) ) ; } jcrs -> append ( jcr ) ; unlock_jcr_chain ( ) ; unlock_jobs ( ) ; return jcr ; }
Create a Job Control Record and link it into JCR chain
 Returns newly allocated JCR
 Note, since each daemon has a different JCR, he passes
  us the size.
Create a Job Control Record and link it into JCR chain Returns newly allocated JCR Note since each daemon has a different JCR he passes us the size .
/* Note for the director, this value is changed in jobq.c */ /* plug daemon free routine */ /* Setup some dummy values */ /* internal job until defined */ /* ready to run */ /*
    * Locking jobs is a global lock that is needed
    * so that the Director can stop new jobs from being
    * added to the jcr chain while it processes a new
    * conf file and does the job_end_push().
    */