src/dird/job.c
bool
cancel_job(UAContext *ua, JCR *jcr, int wait,  bool cancel)
{
   char ed1[50];
   int32_t old_status = jcr->JobStatus;
   int status;
   const char *reason, *cmd;

   if (!cancel) {               /* stop the job */
      if (!jcr->can_be_stopped()) {
         ua->error_msg(_("Cannot stop JobId %s, Job %s is not a regular Backup Job\n"),
                       edit_uint64(jcr->JobId, ed1), jcr->Job);
         return true;
      }
   }
   
   if (cancel) {
      status = JS_Canceled;
      reason = _("canceled");
      cmd = NT_("cancel");
   } else {
      status = JS_Incomplete;
      reason = _("stopped");
      cmd = NT_("stop");
      jcr->RescheduleIncompleteJobs = false; /* do not restart */
   }

   jcr->setJobStatus(status);

   switch (old_status) {
   case JS_Created:
   case JS_WaitJobRes:
   case JS_WaitClientRes:
   case JS_WaitStoreRes:
   case JS_WaitPriority:
   case JS_WaitMaxJobs:
   case JS_WaitStartTime:
   case JS_WaitDevice:
      ua->info_msg(_("JobId %s, Job %s marked to be %s.\n"),
              edit_uint64(jcr->JobId, ed1), jcr->Job,
              reason);
      jobq_remove(&job_queue, jcr); /* attempt to remove it from queue */
      break;

   default:

      /* Cancel File daemon */
      if (jcr->file_bsock) {
         btimer_t *tid;
         /* do not return now, we want to try to cancel the sd */
         tid = start_bsock_timer(jcr->file_bsock, 120);
         cancel_file_daemon_job(ua, cmd, jcr);
         stop_bsock_timer(tid);
      }

      /* We test file_bsock because the previous operation can take
       * several minutes
       */
      if (jcr->file_bsock && cancel) {
         jcr->file_bsock->set_terminated();
         jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
      }

      /* Cancel Storage daemon */
      if (jcr->store_bsock) {
         btimer_t *tid;
         /* do not return now, we want to try to cancel the sd socket */
         tid = start_bsock_timer(jcr->store_bsock, 120);
         cancel_sd_job(ua, cmd, jcr);
         stop_bsock_timer(tid);
      }

      /* We test file_bsock because the previous operation can take
       * several minutes
       */
      if (jcr->store_bsock && cancel) {
         jcr->store_bsock->set_timed_out();
         jcr->store_bsock->set_terminated();
         sd_msg_thread_send_signal(jcr, TIMEOUT_SIGNAL);
         jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
      }

      /* Cancel Copy/Migration Storage daemon */
      if (jcr->wjcr) {
         /* The wjcr is valid until we call free_jcr(jcr) */
         JCR *wjcr = jcr->wjcr;

         if (wjcr->store_bsock) {
             btimer_t *tid;
            /* do not return now, we want to try to cancel the sd socket */
            tid = start_bsock_timer(wjcr->store_bsock, 120);
            cancel_sd_job(ua, cmd, wjcr);
            stop_bsock_timer(tid);
         }
         /* We test store_bsock because the previous operation can take
          * several minutes
          */
         if (wjcr->store_bsock && cancel) {
            wjcr->store_bsock->set_timed_out();
            wjcr->store_bsock->set_terminated();
            sd_msg_thread_send_signal(wjcr, TIMEOUT_SIGNAL);
            wjcr->my_thread_send_signal(TIMEOUT_SIGNAL);
         }
      }
      break;
   }

   return true;
}
/*
 * Cancel a job -- typically called by the UA (Console program), but may also
 *              be called by the job watchdog.
 *
 *  Returns: true  if cancel appears to be successful
 *           false on failure. Message sent to ua->jcr.
 */
Cancel a job -- typically called by the UA (Console program), but may also
be called by the job watchdog.

true  if cancel appears to be successful
false on failure. Message sent to ua->jcr.
Cancel a job -- typically called by the UA ( Console program ) but may also be called by the job watchdog . true if cancel appears to be successful false on failure . Message sent to ua - > jcr .
bool
cancel_job(UAContext *ua, JCR *jcr, int wait,  bool cancel)
{
   char ed1[50];
   int32_t old_status = jcr->JobStatus;
   int status;
   const char *reason, *cmd;
   if (!cancel) {               
      if (!jcr->can_be_stopped()) {
         ua->error_msg(_("Cannot stop JobId %s, Job %s is not a regular Backup Job\n"),
                       edit_uint64(jcr->JobId, ed1), jcr->Job);
         return true;
      }
   }
   if (cancel) {
      status = JS_Canceled;
      reason = _("canceled");
      cmd = NT_("cancel");
   } else {
      status = JS_Incomplete;
      reason = _("stopped");
      cmd = NT_("stop");
      jcr->RescheduleIncompleteJobs = false; 
   }
   jcr->setJobStatus(status);
   switch (old_status) {
   case JS_Created:
   case JS_WaitJobRes:
   case JS_WaitClientRes:
   case JS_WaitStoreRes:
   case JS_WaitPriority:
   case JS_WaitMaxJobs:
   case JS_WaitStartTime:
   case JS_WaitDevice:
      ua->info_msg(_("JobId %s, Job %s marked to be %s.\n"),
              edit_uint64(jcr->JobId, ed1), jcr->Job,
              reason);
      jobq_remove(&job_queue, jcr); 
      break;
   default:
      if (jcr->file_bsock) {
         btimer_t *tid;
         tid = start_bsock_timer(jcr->file_bsock, 120);
         cancel_file_daemon_job(ua, cmd, jcr);
         stop_bsock_timer(tid);
      }
      if (jcr->file_bsock && cancel) {
         jcr->file_bsock->set_terminated();
         jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
      }
      if (jcr->store_bsock) {
         btimer_t *tid;
         tid = start_bsock_timer(jcr->store_bsock, 120);
         cancel_sd_job(ua, cmd, jcr);
         stop_bsock_timer(tid);
      }
      if (jcr->store_bsock && cancel) {
         jcr->store_bsock->set_timed_out();
         jcr->store_bsock->set_terminated();
         sd_msg_thread_send_signal(jcr, TIMEOUT_SIGNAL);
         jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
      }
      if (jcr->wjcr) {
         JCR *wjcr = jcr->wjcr;
         if (wjcr->store_bsock) {
             btimer_t *tid;
            tid = start_bsock_timer(wjcr->store_bsock, 120);
            cancel_sd_job(ua, cmd, wjcr);
            stop_bsock_timer(tid);
         }
         if (wjcr->store_bsock && cancel) {
            wjcr->store_bsock->set_timed_out();
            wjcr->store_bsock->set_terminated();
            sd_msg_thread_send_signal(wjcr, TIMEOUT_SIGNAL);
            wjcr->my_thread_send_signal(TIMEOUT_SIGNAL);
         }
      }
      break;
   }
   return true;
}
bool cancel_job ( UAContext * ua , JCR * jcr , int wait , bool cancel ) { char ed1 [ 50 ] ; int32_t old_status = jcr -> JobStatus ; int status ; const char * reason , * cmd ; if ( ! cancel ) { if ( ! jcr -> can_be_stopped ( ) ) { ua -> error_msg ( _ ( " \n " ) , edit_uint64 ( jcr -> JobId , ed1 ) , jcr -> Job ) ; return true ; } } if ( cancel ) { status = JS_Canceled ; reason = _ ( " " ) ; cmd = NT_ ( " " ) ; } else { status = JS_Incomplete ; reason = _ ( " " ) ; cmd = NT_ ( " " ) ; jcr -> RescheduleIncompleteJobs = false ; } jcr -> setJobStatus ( status ) ; switch ( old_status ) { case JS_Created : case JS_WaitJobRes : case JS_WaitClientRes : case JS_WaitStoreRes : case JS_WaitPriority : case JS_WaitMaxJobs : case JS_WaitStartTime : case JS_WaitDevice : ua -> info_msg ( _ ( " \n " ) , edit_uint64 ( jcr -> JobId , ed1 ) , jcr -> Job , reason ) ; jobq_remove ( & job_queue , jcr ) ; break ; default : if ( jcr -> file_bsock ) { btimer_t * tid ; tid = start_bsock_timer ( jcr -> file_bsock , 120 ) ; cancel_file_daemon_job ( ua , cmd , jcr ) ; stop_bsock_timer ( tid ) ; } if ( jcr -> file_bsock && cancel ) { jcr -> file_bsock -> set_terminated ( ) ; jcr -> my_thread_send_signal ( TIMEOUT_SIGNAL ) ; } if ( jcr -> store_bsock ) { btimer_t * tid ; tid = start_bsock_timer ( jcr -> store_bsock , 120 ) ; cancel_sd_job ( ua , cmd , jcr ) ; stop_bsock_timer ( tid ) ; } if ( jcr -> store_bsock && cancel ) { jcr -> store_bsock -> set_timed_out ( ) ; jcr -> store_bsock -> set_terminated ( ) ; sd_msg_thread_send_signal ( jcr , TIMEOUT_SIGNAL ) ; jcr -> my_thread_send_signal ( TIMEOUT_SIGNAL ) ; } if ( jcr -> wjcr ) { JCR * wjcr = jcr -> wjcr ; if ( wjcr -> store_bsock ) { btimer_t * tid ; tid = start_bsock_timer ( wjcr -> store_bsock , 120 ) ; cancel_sd_job ( ua , cmd , wjcr ) ; stop_bsock_timer ( tid ) ; } if ( wjcr -> store_bsock && cancel ) { wjcr -> store_bsock -> set_timed_out ( ) ; wjcr -> store_bsock -> set_terminated ( ) ; sd_msg_thread_send_signal ( wjcr , TIMEOUT_SIGNAL ) ; wjcr -> my_thread_send_signal ( TIMEOUT_SIGNAL ) ; } } break ; } return true ; }
Cancel a job -- typically called by the UA (Console program), but may also
              be called by the job watchdog.
Cancel a job -- typically called by the UA ( Console program ) but may also be called by the job watchdog .
/* stop the job */ /* do not restart */ /* attempt to remove it from queue */ /* Cancel File daemon */ /* do not return now, we want to try to cancel the sd */ /* We test file_bsock because the previous operation can take
       * several minutes
       */ /* Cancel Storage daemon */ /* do not return now, we want to try to cancel the sd socket */ /* We test file_bsock because the previous operation can take
       * several minutes
       */ /* Cancel Copy/Migration Storage daemon */ /* The wjcr is valid until we call free_jcr(jcr) */ /* do not return now, we want to try to cancel the sd socket */ /* We test store_bsock because the previous operation can take
          * several minutes
          */