]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/job.c
07Jan06
[bacula/bacula] / bacula / src / dird / job.c
index 9c6ba26e342557a8211fa1f7a688deef922c68e1..6c12e089ce8474104b64138c061bcbb65fc450a1 100644 (file)
@@ -11,7 +11,7 @@
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
-   version 2 as ammended with additional clauses defined in the
+   version 2 as amended with additional clauses defined in the
    file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
@@ -218,7 +218,7 @@ static void *job_thread(void *arg)
          admin_cleanup(jcr, JS_ErrorTerminated);
       }
       break;
-   case JT_MIGRATION:
+   case JT_MIGRATE:
    case JT_COPY:
    case JT_ARCHIVE:
       if (!do_mac_init(jcr)) {             /* migration, archive, copy */
@@ -226,7 +226,7 @@ static void *job_thread(void *arg)
       }
       break;
    default:
-      Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
+      Pmsg1(0, _("Unimplemented job type: %d\n"), jcr->JobType);
       set_jcr_job_status(jcr, JS_ErrorTerminated);
       break;
    }
@@ -294,7 +294,7 @@ static void *job_thread(void *arg)
             admin_cleanup(jcr, JS_ErrorTerminated);
          }
          break;
-      case JT_MIGRATION:
+      case JT_MIGRATE:
       case JT_COPY:
       case JT_ARCHIVE:
          if (do_mac(jcr)) {              /* migration, archive, copy */
@@ -304,7 +304,7 @@ static void *job_thread(void *arg)
          }
          break;
       default:
-         Pmsg1(0, "Unimplemented job type: %d\n", jcr->JobType);
+         Pmsg1(0, _("Unimplemented job type: %d\n"), jcr->JobType);
          break;
       }
       if ((jcr->job->RunAfterJob && jcr->JobStatus == JS_Terminated) ||
@@ -356,10 +356,10 @@ bail_out:
  * Cancel a job -- typically called by the UA (Console program), but may also
  *              be called by the job watchdog.
  *
- *  Returns: 1 if cancel appears to be successful
- *           0 on failure. Message sent to ua->jcr.
+ *  Returns: true  if cancel appears to be successful
+ *           false on failure. Message sent to ua->jcr.
  */
-int cancel_job(UAContext *ua, JCR *jcr)
+bool cancel_job(UAContext *ua, JCR *jcr)
 {
    BSOCK *sd, *fd;
 
@@ -376,7 +376,7 @@ int cancel_job(UAContext *ua, JCR *jcr)
       bsendmsg(ua, _("JobId %d, Job %s marked to be canceled.\n"),
               jcr->JobId, jcr->Job);
       jobq_remove(&job_queue, jcr); /* attempt to remove it from queue */
-      return 1;
+      return true;
 
    default:
 
@@ -407,7 +407,7 @@ int cancel_job(UAContext *ua, JCR *jcr)
          }
          if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
             bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
-            return 0;
+            return false;
          }
          Dmsg0(200, "Connected to storage daemon\n");
          sd = ua->jcr->store_bsock;
@@ -421,13 +421,13 @@ int cancel_job(UAContext *ua, JCR *jcr)
       }
    }
 
-   return 1;
+   return true;
 }
 
 
 static void job_monitor_destructor(watchdog_t *self)
 {
-   JCR *control_jcr = (JCR *) self->data;
+   JCR *control_jcr = (JCR *)self->data;
 
    free_jcr(control_jcr);
 }
@@ -446,8 +446,6 @@ static void job_monitor_watchdog(watchdog_t *self)
       if (jcr->JobId == 0) {
          Dmsg2(800, "Skipping JCR %p (%s) with JobId 0\n",
                jcr, jcr->Job);
-         /* Keep reference counts correct */
-         free_jcr(jcr);
          continue;
       }
 
@@ -466,12 +464,12 @@ static void job_monitor_watchdog(watchdog_t *self)
          cancel_job(ua, jcr);
          free_ua_context(ua);
 
-         Dmsg1(800, "Have cancelled JCR %p\n", jcr);
+         Dmsg2(800, "Have cancelled JCR %p Job=%d\n", jcr, jcr->JobId);
       }
 
       /* Keep reference counts correct */
-      free_jcr(jcr);
    }
+   endeach_jcr(jcr);
 }
 
 /*
@@ -634,38 +632,34 @@ bool get_or_create_client_record(JCR *jcr)
    return true;
 }
 
-bool get_or_create_fileset_record(JCR *jcr, FILESET_DBR *fsr)
+bool get_or_create_fileset_record(JCR *jcr)
 {
+   FILESET_DBR fsr;
    /*
     * Get or Create FileSet record
     */
-   memset(fsr, 0, sizeof(FILESET_DBR));
-   bstrncpy(fsr->FileSet, jcr->fileset->hdr.name, sizeof(fsr->FileSet));
+   memset(&fsr, 0, sizeof(FILESET_DBR));
+   bstrncpy(fsr.FileSet, jcr->fileset->hdr.name, sizeof(fsr.FileSet));
    if (jcr->fileset->have_MD5) {
       struct MD5Context md5c;
-      unsigned char signature[16];
+      unsigned char digest[MD5HashSize];
       memcpy(&md5c, &jcr->fileset->md5c, sizeof(md5c));
-      MD5Final(signature, &md5c);
-      bin_to_base64(fsr->MD5, (char *)signature, 16); /* encode 16 bytes */
-      bstrncpy(jcr->fileset->MD5, fsr->MD5, sizeof(jcr->fileset->MD5));
+      MD5Final(digest, &md5c);
+      bin_to_base64(fsr.MD5, (char *)digest, MD5HashSize);
+      bstrncpy(jcr->fileset->MD5, fsr.MD5, sizeof(jcr->fileset->MD5));
    } else {
-      Jmsg(jcr, M_WARNING, 0, _("FileSet MD5 signature not found.\n"));
+      Jmsg(jcr, M_WARNING, 0, _("FileSet MD5 digest not found.\n"));
    }
    if (!jcr->fileset->ignore_fs_changes ||
-       !db_get_fileset_record(jcr, jcr->db, fsr)) {
-      if (!db_create_fileset_record(jcr, jcr->db, fsr)) {
+       !db_get_fileset_record(jcr, jcr->db, &fsr)) {
+      if (!db_create_fileset_record(jcr, jcr->db, &fsr)) {
          Jmsg(jcr, M_ERROR, 0, _("Could not create FileSet \"%s\" record. ERR=%s\n"),
-            fsr->FileSet, db_strerror(jcr->db));
+            fsr.FileSet, db_strerror(jcr->db));
          return false;
       }
    }
-   jcr->jr.FileSetId = fsr->FileSetId;
-#ifdef needed
-   if (fsr->created && jcr != NULL) {
-      Jmsg(jcr, M_INFO, 0, _("Created new FileSet record \"%s\" %s\n"),
-         fsr->FileSet, fsr->cCreateTime);
-   }
-#endif
+   jcr->jr.FileSetId = fsr.FileSetId;
+   bstrncpy(jcr->FSCreateTime, fsr.cCreateTime, sizeof(jcr->FSCreateTime));
    Dmsg2(119, "Created FileSet %s record %u\n", jcr->fileset->hdr.name,
       jcr->jr.FileSetId);
    return true;
@@ -791,6 +785,14 @@ void dird_free_jcr_pointers(JCR *jcr)
       pthread_cond_destroy(&jcr->term_wait);
       jcr->term_wait_inited = false;
    }
+   if (jcr->attr) {
+      free_pool_memory(jcr->attr);
+      jcr->attr = NULL;
+   }
+   if (jcr->ar) {
+      free(jcr->ar);
+      jcr->ar = NULL;
+   }
 }
 
 /*