]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/jcr.c
update version
[bacula/bacula] / bacula / src / lib / jcr.c
index 445340f64f238f44e01caefd62d801373f8402fd..3f4106b9ff1c6d310d8e1a82f61bc74e68cc02c1 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -365,7 +365,6 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
    jcr->setJobType(JT_SYSTEM);           /* internal job until defined */
    jcr->setJobLevel(L_NONE);
    jcr->setJobStatus(JS_Created);        /* ready to run */
-   set_jcr_in_tsd(jcr);
    sigtimer.sa_flags = 0;
    sigtimer.sa_handler = timeout_handler;
    sigfillset(&sigtimer.sa_mask);
@@ -413,6 +412,7 @@ static void free_common_jcr(JCR *jcr)
 {
    /* Uses jcr lock/unlock */
    remove_jcr_from_tsd(jcr);
+   jcr->set_killable(false);
 
    jcr->destroy_mutex();
 
@@ -576,7 +576,6 @@ void free_jcr(JCR *jcr)
 
    free_common_jcr(jcr);
    close_msg(NULL);                   /* flush any daemon messages */
-   garbage_collect_memory_pool();
    Dmsg0(dbglvl, "Exit free_jcr\n");
 }
 
@@ -588,20 +587,29 @@ void remove_jcr_from_tsd(JCR *jcr)
 {
    JCR *tjcr = get_jcr_from_tsd();
    if (tjcr == jcr) { 
-      jcr->lock();
-      jcr->my_thread_running = false;
-      memset(&jcr->my_thread_id, 0, sizeof(jcr->my_thread_id));
-      jcr->unlock();
       set_jcr_in_tsd(INVALID_JCR);
    }
 }
 
+void JCR::set_killable(bool killable)
+{
+   JCR *jcr = this;
+   jcr->lock();
+   jcr->my_thread_killable = killable;
+   if (killable) {
+      jcr->my_thread_id = pthread_self();
+   } else {
+      memset(&jcr->my_thread_id, 0, sizeof(jcr->my_thread_id));
+   }
+   jcr->unlock();
+}
+
 /*
  * Put this jcr in the thread specifc data
  *  if update_thread_info is true and the jcr is valide,
  *  we update the my_thread_id in the JCR
  */
-void set_jcr_in_tsd(JCR *jcr, bool update_thread_info)
+void set_jcr_in_tsd(JCR *jcr)
 {
    int status = pthread_setspecific(jcr_key, (void *)jcr);
    if (status != 0) {
@@ -609,30 +617,18 @@ void set_jcr_in_tsd(JCR *jcr, bool update_thread_info)
       Jmsg1(jcr, M_ABORT, 0, _("pthread_setspecific failed: ERR=%s\n"), 
             be.bstrerror(status));
    }
-
-   /* We explicitly ask to set a jcr in tsd, we can update jcr->my_thread
-    */
-   if (update_thread_info && jcr && jcr != INVALID_JCR) {
-      Dmsg2(100, "setting my_thread_stuffs 0x%p => 0x%p\n", 
-            jcr->my_thread_id, pthread_self());
-      jcr->lock();
-      //ASSERT(jcr->my_thread_running == false);
-      jcr->my_thread_id = pthread_self();
-      jcr->my_thread_running = true;
-      jcr->unlock();
-   }
 }
 
 void JCR::my_thread_send_signal(int sig)
 {
    this->lock();
-   if (   this->my_thread_running 
-       && !pthread_equal(this->my_thread_id, pthread_self()))
+   if (this->is_killable() &&
+       !pthread_equal(this->my_thread_id, pthread_self()))
    {
       Dmsg1(800, "Send kill to jid=%d\n", this->JobId);
       pthread_kill(this->my_thread_id, sig);
 
-   } else if (!this->my_thread_running) {
+   } else if (!this->is_killable()) {
       Dmsg1(10, "Warning, can't send kill to jid=%d\n", this->JobId);
    }
    this->unlock();
@@ -849,11 +845,13 @@ static int get_status_priority(int JobStatus)
 {
    int priority = 0;
    switch (JobStatus) {
+   case JS_Incomplete:
+      priority = 10;
+      break;
    case JS_ErrorTerminated:
    case JS_FatalError:
    case JS_Canceled:
-   case JS_Incomplete:
-      priority = 10;
+      priority = 9;
       break;
    case JS_Error:
       priority = 8;
@@ -865,12 +863,6 @@ static int get_status_priority(int JobStatus)
    return priority;
 }
 
-
-void set_jcr_job_status(JCR *jcr, int JobStatus)
-{
-   jcr->setJobStatus(JobStatus);
-}
-
 void JCR::setJobStatus(int newJobStatus)
 {
    JCR *jcr = this;
@@ -904,7 +896,7 @@ void JCR::setJobStatus(int newJobStatus)
    }
 
    if (oldJobStatus != jcr->JobStatus) {
-      Dmsg2(800, "leave set_job_status old=%c new=%c\n", oldJobStatus, newJobStatus);
+      Dmsg2(800, "leave setJobStatus old=%c new=%c\n", oldJobStatus, newJobStatus);
 //    generate_plugin_event(jcr, bEventStatusChange, NULL);
    }
 }
@@ -1181,6 +1173,10 @@ void dbg_print_jcr(FILE *fp)
    for (JCR *jcr = (JCR *)jcrs->first(); jcr ; jcr = (JCR *)jcrs->next(jcr)) {
       fprintf(fp, "threadid=%p JobId=%d JobStatus=%c jcr=%p name=%s\n", 
               (void *)jcr->my_thread_id, (int)jcr->JobId, jcr->JobStatus, jcr, jcr->Job);
+      fprintf(fp, "threadid=%p killable=%d JobId=%d JobStatus=%c "
+                  "jcr=%p name=%s\n",
+              (void *)jcr->my_thread_id, jcr->is_killable(),
+              (int)jcr->JobId, jcr->JobStatus, jcr, jcr->Job);
       fprintf(fp, "\tuse_count=%i\n", jcr->use_count());
       fprintf(fp, "\tJobType=%c JobLevel=%c\n",
               jcr->getJobType(), jcr->getJobLevel());