src/stored/dircmd.c
static bool cancel_cmd(JCR *cjcr)
{
   BSOCK *dir = cjcr->dir_bsock;
   int oldStatus;
   char Job[MAX_NAME_LENGTH];
   JCR *jcr;
   int status;
   const char *reason;

   if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
      status = JS_Canceled;
      reason = "canceled";
   } else if (sscanf(dir->msg, "stop Job=%127s", Job) == 1) {
      status = JS_Incomplete;
      reason = "stopped";
   } else {
      dir->fsend(_("3903 Error scanning cancel command.\n"));
      goto bail_out;
   }
   if (!(jcr=get_jcr_by_full_name(Job))) {
      dir->fsend(_("3904 Job %s not found.\n"), Job);
   } else {
      oldStatus = jcr->JobStatus;
      jcr->setJobStatus(status);
      Dmsg2(800, "Cancel JobId=%d %p\n", jcr->JobId, jcr);
      if (!jcr->authenticated && oldStatus == JS_WaitFD) {
         pthread_cond_signal(&jcr->job_start_wait); /* wake waiting thread */
      }
      if (jcr->file_bsock) {
         jcr->file_bsock->set_terminated();
         jcr->file_bsock->set_timed_out();
         Dmsg2(800, "Term bsock jid=%d %p\n", jcr->JobId, jcr);
      } else {
         /* Still waiting for FD to connect, release it */
         pthread_cond_signal(&jcr->job_start_wait); /* wake waiting job */
         Dmsg2(800, "Signal FD connect jid=%d %p\n", jcr->JobId, jcr);
      }
      /* If thread waiting on mount, wake him */
      if (jcr->dcr && jcr->dcr->dev && jcr->dcr->dev->waiting_for_mount()) {
         pthread_cond_broadcast(&jcr->dcr->dev->wait_next_vol);
         Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)jcr->JobId);
         pthread_cond_broadcast(&wait_device_release);
      }
      if (jcr->read_dcr && jcr->read_dcr->dev && jcr->read_dcr->dev->waiting_for_mount()) {
         pthread_cond_broadcast(&jcr->read_dcr->dev->wait_next_vol);
         Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)jcr->JobId);
         pthread_cond_broadcast(&wait_device_release);
      }
      jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
      dir->fsend(_("3000 JobId=%ld Job=\"%s\" marked to be %s.\n"),
         jcr->JobId, jcr->Job, reason);
      free_jcr(jcr);
   }

bail_out:
   dir->signal(BNET_EOD);
   return 1;
}
/*
 * Cancel a Job
 *   Be careful, we switch to using the job's JCR! So, using
 *   BSOCKs on that jcr can have two threads in the same code.
 */
Cancel a Job
Be careful, we switch to using the job's JCR. So, using
BSOCKs on that jcr can have two threads in the same code.
Cancel a Job Be careful we switch to using the job ' s JCR . So using BSOCKs on that jcr can have two threads in the same code .
static bool cancel_cmd(JCR *cjcr)
{
   BSOCK *dir = cjcr->dir_bsock;
   int oldStatus;
   char Job[MAX_NAME_LENGTH];
   JCR *jcr;
   int status;
   const char *reason;
   if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
      status = JS_Canceled;
      reason = "canceled";
   } else if (sscanf(dir->msg, "stop Job=%127s", Job) == 1) {
      status = JS_Incomplete;
      reason = "stopped";
   } else {
      dir->fsend(_("3903 Error scanning cancel command.\n"));
      goto bail_out;
   }
   if (!(jcr=get_jcr_by_full_name(Job))) {
      dir->fsend(_("3904 Job %s not found.\n"), Job);
   } else {
      oldStatus = jcr->JobStatus;
      jcr->setJobStatus(status);
      Dmsg2(800, "Cancel JobId=%d %p\n", jcr->JobId, jcr);
      if (!jcr->authenticated && oldStatus == JS_WaitFD) {
         pthread_cond_signal(&jcr->job_start_wait); 
      }
      if (jcr->file_bsock) {
         jcr->file_bsock->set_terminated();
         jcr->file_bsock->set_timed_out();
         Dmsg2(800, "Term bsock jid=%d %p\n", jcr->JobId, jcr);
      } else {
         pthread_cond_signal(&jcr->job_start_wait); 
         Dmsg2(800, "Signal FD connect jid=%d %p\n", jcr->JobId, jcr);
      }
      if (jcr->dcr && jcr->dcr->dev && jcr->dcr->dev->waiting_for_mount()) {
         pthread_cond_broadcast(&jcr->dcr->dev->wait_next_vol);
         Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)jcr->JobId);
         pthread_cond_broadcast(&wait_device_release);
      }
      if (jcr->read_dcr && jcr->read_dcr->dev && jcr->read_dcr->dev->waiting_for_mount()) {
         pthread_cond_broadcast(&jcr->read_dcr->dev->wait_next_vol);
         Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)jcr->JobId);
         pthread_cond_broadcast(&wait_device_release);
      }
      jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
      dir->fsend(_("3000 JobId=%ld Job=\"%s\" marked to be %s.\n"),
         jcr->JobId, jcr->Job, reason);
      free_jcr(jcr);
   }
bail_out:
   dir->signal(BNET_EOD);
   return 1;
}
static bool cancel_cmd ( JCR * cjcr ) { BSOCK * dir = cjcr -> dir_bsock ; int oldStatus ; char Job [ MAX_NAME_LENGTH ] ; JCR * jcr ; int status ; const char * reason ; if ( sscanf ( dir -> msg , " " , Job ) == 1 ) { status = JS_Canceled ; reason = " " ; } else if ( sscanf ( dir -> msg , " " , Job ) == 1 ) { status = JS_Incomplete ; reason = " " ; } else { dir -> fsend ( _ ( " \n " ) ) ; goto bail_out ; } if ( ! ( jcr = get_jcr_by_full_name ( Job ) ) ) { dir -> fsend ( _ ( " \n " ) , Job ) ; } else { oldStatus = jcr -> JobStatus ; jcr -> setJobStatus ( status ) ; Dmsg2 ( 800 , " \n " , jcr -> JobId , jcr ) ; if ( ! jcr -> authenticated && oldStatus == JS_WaitFD ) { pthread_cond_signal ( & jcr -> job_start_wait ) ; } if ( jcr -> file_bsock ) { jcr -> file_bsock -> set_terminated ( ) ; jcr -> file_bsock -> set_timed_out ( ) ; Dmsg2 ( 800 , " \n " , jcr -> JobId , jcr ) ; } else { pthread_cond_signal ( & jcr -> job_start_wait ) ; Dmsg2 ( 800 , " \n " , jcr -> JobId , jcr ) ; } if ( jcr -> dcr && jcr -> dcr -> dev && jcr -> dcr -> dev -> waiting_for_mount ( ) ) { pthread_cond_broadcast ( & jcr -> dcr -> dev -> wait_next_vol ) ; Dmsg1 ( 100 , " \n " , ( uint32_t ) jcr -> JobId ) ; pthread_cond_broadcast ( & wait_device_release ) ; } if ( jcr -> read_dcr && jcr -> read_dcr -> dev && jcr -> read_dcr -> dev -> waiting_for_mount ( ) ) { pthread_cond_broadcast ( & jcr -> read_dcr -> dev -> wait_next_vol ) ; Dmsg1 ( 100 , " \n " , ( uint32_t ) jcr -> JobId ) ; pthread_cond_broadcast ( & wait_device_release ) ; } jcr -> my_thread_send_signal ( TIMEOUT_SIGNAL ) ; dir -> fsend ( _ ( " \" \" \n " ) , jcr -> JobId , jcr -> Job , reason ) ; free_jcr ( jcr ) ; } bail_out : dir -> signal ( BNET_EOD ) ; return 1 ; }
Cancel a Job
   Be careful, we switch to using the job's JCR!
Cancel a Job Be careful we switch to using the job ' s JCR!
/* wake waiting thread */ /* Still waiting for FD to connect, release it */ /* wake waiting job */ /* If thread waiting on mount, wake him */