]> git.sur5r.net Git - bacula/bacula/commitdiff
Lots of cleanup for restore -- kes11Aug02
authorKern Sibbald <kern@sibbald.com>
Sun, 11 Aug 2002 16:23:41 +0000 (16:23 +0000)
committerKern Sibbald <kern@sibbald.com>
Sun, 11 Aug 2002 16:23:41 +0000 (16:23 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@87 91ce42f0-d328-0410-95d8-f526ca767f89

20 files changed:
bacula/src/cats/protos.h
bacula/src/cats/sql_get.c
bacula/src/dird/backup.c
bacula/src/dird/job.c
bacula/src/dird/restore.c
bacula/src/dird/scheduler.c
bacula/src/dird/ua_output.c
bacula/src/dird/ua_restore.c
bacula/src/dird/ua_run.c
bacula/src/dird/verify.c
bacula/src/jcr.h
bacula/src/lib/message.c
bacula/src/lib/protos.h
bacula/src/lib/util.c
bacula/src/stored/bextract.c
bacula/src/stored/bsr.h
bacula/src/stored/device.c
bacula/src/stored/fd_cmds.c
bacula/src/stored/match_bsr.c
bacula/src/stored/parse_bsr.c

index a38e5ce936bede54cc80cdde3b8942929bfce6cf..66f2c72989741919fd3ddd812238494eb163f9a2 100644 (file)
@@ -66,7 +66,7 @@ int db_find_next_volume(B_DB *mdb, int index, MEDIA_DBR *mr);
 int db_get_pool_record(B_DB *db, POOL_DBR *pdbr);
 int db_get_client_record(B_DB *mdb, CLIENT_DBR *cr);
 int db_get_job_record(B_DB *mdb, JOB_DBR *jr);
-int db_get_job_volume_names(B_DB *mdb, uint32_t JobId, char *VolumeNames);
+int db_get_job_volume_names(B_DB *mdb, uint32_t JobId, POOLMEM **VolumeNames);
 int db_get_file_attributes_record(B_DB *mdb, char *fname, FILE_DBR *fdbr);
 int db_get_fileset_record(B_DB *mdb, FILESET_DBR *fsr);
 int db_get_media_record(B_DB *mdb, MEDIA_DBR *mr);
index 938e0a8d0e60d99a6fea1c4a46312eb678b46f05..edd0840ce487aa17c441c5f106dab1159434689e 100644 (file)
@@ -353,7 +353,7 @@ FROM Job WHERE JobId=%d", jr->JobId);
  *             Volumes are concatenated in VolumeNames
  *             separated by a vertical bar (|).
  */
-int db_get_job_volume_names(B_DB *mdb, uint32_t JobId, char *VolumeNames)
+int db_get_job_volume_names(B_DB *mdb, uint32_t JobId, POOLMEM **VolumeNames)
 {
    SQL_ROW row;
    int stat = 0;
@@ -365,7 +365,7 @@ int db_get_job_volume_names(B_DB *mdb, uint32_t JobId, char *VolumeNames)
 AND JobMedia.MediaId=Media.MediaId", JobId);
 
    Dmsg1(130, "VolNam=%s\n", mdb->cmd);
-   VolumeNames[0] = 0;
+   *VolumeNames[0] = 0;
    if (QUERY_DB(mdb, mdb->cmd)) {
       mdb->num_rows = sql_num_rows(mdb);
       Dmsg1(130, "Num rows=%d\n", mdb->num_rows);
@@ -380,10 +380,10 @@ AND JobMedia.MediaId=Media.MediaId", JobId);
               stat = 0;
               break;
            } else {
-              if (VolumeNames[0] != 0) {
-                  strcat(VolumeNames, "|");
+              if (*VolumeNames[0] != 0) {
+                  pm_strcat(VolumeNames, "|");
               }
-              strcat(VolumeNames, row[0]);
+              pm_strcat(VolumeNames, row[0]);
            }
         }
       }
index d0c2abc2a57c12983696c24c68d8ece323170929..fd889b74b3a18d9c491769514de3e8b8ea9a328d 100644 (file)
@@ -342,7 +342,7 @@ static void backup_cleanup(JCR *jcr, int TermCode, char *since)
    }
    bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime);
    bstrftime(edt, sizeof(edt), jcr->jr.EndTime);
-   if (!db_get_job_volume_names(jcr->db, jcr->jr.JobId, jcr->VolumeName)) {
+   if (!db_get_job_volume_names(jcr->db, jcr->jr.JobId, &jcr->VolumeName)) {
       jcr->VolumeName[0] = 0;        /* none */
    }
 
index 75ffdcff865dea1128f0fa411877b34ce14d8ec7..3e9d35175dc9a9272c3d5cdbae2a7b693420d1a6 100644 (file)
@@ -70,7 +70,7 @@ void run_job(JCR *jcr)
 {
    int stat, errstat;
 
-   init_msg(jcr, jcr->msgs);
+   init_msg(jcr, jcr->messages);
    create_unique_job_name(jcr, jcr->job->hdr.name);
    jcr->jr.SchedTime = jcr->sched_time;
    jcr->jr.StartTime = jcr->start_time;
@@ -357,7 +357,7 @@ void set_jcr_defaults(JCR *jcr, JOB *job)
    jcr->pool = job->pool;
    jcr->catalog = job->client->catalog;
    jcr->fileset = job->fileset;
-   jcr->msgs = job->messages; 
+   jcr->messages = job->messages; 
    if (jcr->RestoreBootstrap) {
       free(jcr->RestoreBootstrap);
    }
@@ -398,20 +398,17 @@ void set_jcr_defaults(JCR *jcr, JOB *job)
  */
 static char *edit_run_codes(JCR *jcr, char *omsg, char *imsg) 
 {
-   char *p, *o;
+   char *p;
    const char *str;
    char add[20];
 
+   *omsg = 0;
    Dmsg1(200, "edit_run_codes: %s\n", imsg);
-   add[2] = 0;
-   o = omsg;
    for (p=imsg; *p; p++) {
       if (*p == '%') {
         switch (*++p) {
          case '%':
-            add[0] = '%';
-           add[1] = 0;
-           str = add;
+            str = "%";
            break;
          case 'c':
            str = jcr->client_name;
@@ -444,6 +441,7 @@ static char *edit_run_codes(JCR *jcr, char *omsg, char *imsg)
         default:
             add[0] = '%';
            add[1] = *p;
+           add[2] = 0;
            str = add;
            break;
         }
@@ -453,10 +451,8 @@ static char *edit_run_codes(JCR *jcr, char *omsg, char *imsg)
         str = add;
       }
       Dmsg1(200, "add_str %s\n", str);
-      add_str_to_pool_mem(&omsg, &o, (char *)str);
-      *o = 0;
+      pm_strcat(&omsg, (char *)str);
       Dmsg1(200, "omsg=%s\n", omsg);
    }
-   *o = 0;
    return omsg;
 }
index 5f3a49dea2b8193af34b85985548c6e8bb1db9a8..464a27363895d81af97e579f147a5261dbffaf3b 100644 (file)
@@ -115,7 +115,7 @@ int do_restore(JCR *jcr)
        * Now find the Volumes we will need for the Restore
        */
       jcr->VolumeName[0] = 0;
-      if (!db_get_job_volume_names(jcr->db, rjr.JobId, jcr->VolumeName) ||
+      if (!db_get_job_volume_names(jcr->db, rjr.JobId, &jcr->VolumeName) ||
           jcr->VolumeName[0] == 0) {
          Jmsg(jcr, M_FATAL, 0, _("Cannot find Volume Name for restore Job %d. %s"), 
            rjr.JobId, db_strerror(jcr->db));
index 4e09a5b3ca3575d0a2f6a565c03557e0efa929d1..19cb11ff91d5aaa02d7ea146ff7bc5d4cd807d57 100644 (file)
@@ -157,7 +157,7 @@ JCR *wait_for_next_job(char *job_to_run)
       jcr->store = run->storage;      /* override storage */
    }
    if (run->msgs) {
-      jcr->msgs = run->msgs;         /* override messages */
+      jcr->messages = run->msgs;      /* override messages */
    }
    Dmsg0(200, "Leave wait_for_next_job()\n");
    return jcr;
index e62295aae6f7eb5d8940ab1bbdd1ce11edac02ad..9f887cbebea781bd37b573b3701784bef76cbfd2 100644 (file)
@@ -301,9 +301,9 @@ int listcmd(UAContext *ua, char *cmd)
               continue;
            }
            VolumeName = get_pool_memory(PM_FNAME);
-           n = db_get_job_volume_names(ua->db, jobid, VolumeName);
+           n = db_get_job_volume_names(ua->db, jobid, &VolumeName);
             bsendmsg(ua, _("Jobid %d used %d Volume(s): %s\n"), jobid, n, VolumeName);
-           free_memory(VolumeName);
+           free_pool_memory(VolumeName);
            done = TRUE;
         }
         /* if no job or jobid keyword found, then we list all media */
index 37cf7443a40dd41232e166bbe381c52c2823748b..7071a0b748ecf35b404fdfc7e8e1df10569357d8 100644 (file)
@@ -197,7 +197,7 @@ int restorecmd(UAContext *ua, char *cmd)
 
    if (bsr->JobId) {
       complete_bsr(ua, bsr);         /* find Vol, SessId, SessTime from JobIds */
-      print_bsr(ua, bsr);
+//    print_bsr(ua, bsr);
       write_bsr_file(ua, bsr);
    } else {
       bsendmsg(ua, _("No files selected to restore.\n"));
@@ -575,9 +575,10 @@ static void free_bsr(RBSR *bsr)
 static int complete_bsr(UAContext *ua, RBSR *bsr)
 {
    JOB_DBR jr;
-   char VolumeNames[1000];           /* ****FIXME**** */
+   POOLMEM *VolumeNames;
 
    if (bsr) {
+      VolumeNames = get_pool_memory(PM_MESSAGE);
       memset(&jr, 0, sizeof(jr));
       jr.JobId = bsr->JobId;
       if (!db_get_job_record(ua->db, &jr)) {
@@ -586,11 +587,13 @@ static int complete_bsr(UAContext *ua, RBSR *bsr)
       }
       bsr->VolSessionId = jr.VolSessionId;
       bsr->VolSessionTime = jr.VolSessionTime;
-      if (!db_get_job_volume_names(ua->db, bsr->JobId, VolumeNames)) {
+      if (!db_get_job_volume_names(ua->db, bsr->JobId, &VolumeNames)) {
          bsendmsg(ua, _("Unable to get Job Volumes. ERR=%s\n"), db_strerror(ua->db));
+        free_pool_memory(VolumeNames);
         return 0;
       }
       bsr->VolumeName = bstrdup(VolumeNames);
+      free_pool_memory(VolumeNames);
       return complete_bsr(ua, bsr->next);
    }
    return 1;
@@ -625,7 +628,7 @@ static void write_bsr(UAContext *ua, RBSR *bsr, FILE *fd)
 {
    if (bsr) {
       if (bsr->VolumeName) {
-         fprintf(fd, "Volume=%s\n", bsr->VolumeName);
+         fprintf(fd, "Volume=\"%s\"\n", bsr->VolumeName);
       }
       fprintf(fd, "VolSessionId=%u\n", bsr->VolSessionId);
       fprintf(fd, "VolSessionTime=%u\n", bsr->VolSessionTime);
@@ -638,7 +641,7 @@ static void print_bsr(UAContext *ua, RBSR *bsr)
 {
    if (bsr) {
       if (bsr->VolumeName) {
-         bsendmsg(ua, "Volume=%s\n", bsr->VolumeName);
+         bsendmsg(ua, "Volume=\"%s\"\n", bsr->VolumeName);
       }
       bsendmsg(ua, "VolSessionId=%u\n", bsr->VolSessionId);
       bsendmsg(ua, "VolSessionTime=%u\n", bsr->VolSessionTime);
index fac2652a4caa6523798ffa59fd7a443662a4402d..a843de79666a94bf5d9f222b3c9e4c75b1382cda 100644 (file)
@@ -241,7 +241,6 @@ int runcmd(UAContext *ua, char *cmd)
    /* Create JCR to run job */
    jcr = new_jcr(sizeof(JCR), dird_free_jcr);
    set_jcr_defaults(jcr, job);
-   init_msg(jcr, jcr->msgs);         /* start message handler */
 
    jcr->store = store;
    jcr->client = client;
index 2b5195bed772434b3eb0096273955e65d96f9aa8..04642bfa91e9f800126d36b64baec6a05e4620d9 100644 (file)
@@ -140,7 +140,7 @@ int do_verify(JCR *jcr)
        * Now find the Volumes we will need for the Verify 
        */
       jcr->VolumeName[0] = 0;
-      if (!db_get_job_volume_names(jcr->db, jr.JobId, jcr->VolumeName) ||
+      if (!db_get_job_volume_names(jcr->db, jr.JobId, &jcr->VolumeName) ||
           jcr->VolumeName[0] == 0) {
          Jmsg(jcr, M_FATAL, 0, _("Cannot find Volume Name for verify JobId=%d. %s"), 
            jr.JobId, db_strerror(jcr->db));
index f746ce66e2d1e0227a82bb8789e165d0f9ca07b6..62345c095f0194508dd837bc631d3007535aee87 100644 (file)
@@ -107,7 +107,7 @@ struct s_jcr {
    POOLMEM *client_name;              /* client name */
    char *RestoreBootstrap;            /* Bootstrap file to restore */
    char *sd_auth_key;                 /* SD auth key */
-   MSGS *msgs;                        /* Message resource */
+   MSGS *jcr_msgs;                    /* Copy of message resource -- actually used */
 
    /* Daemon specific part of JCR */
    /* This should be empty in the library */
@@ -124,6 +124,7 @@ struct s_jcr {
    POOL *pool;                        /* Pool resource */
    FILESET *fileset;                  /* FileSet resource */
    CAT *catalog;                      /* Catalog resource */
+   MSGS *messages;                    /* Default message handler */
    int SDJobStatus;                   /* Storage Job Status */
    int mode;                          /* manual/auto run */
    B_DB *db;                          /* database pointer */
index 66a89eaef41a85834aeb165b809648c3aa8fa31a..3b5e59b1a69d50245dd1dbca30cdea30a65d7988 100755 (executable)
@@ -129,6 +129,8 @@ void my_name_is(int argc, char *argv[], char *name)
 
 /* 
  * Initialize message handler for a daemon or a Job
+ *   We make a copy of the MSGS resource passed, so it belows
+ *   to the job or daemon and thus can be modified.
  * 
  *   NULL for jcr -> initialize global messages for daemon
  *   non-NULL    -> initialize jcr using Message resource
@@ -174,10 +176,10 @@ init_msg(void *vjcr, MSGS *msg)
    }
 
    if (jcr) {
-      jcr->msgs = (MSGS *)malloc(sizeof(MSGS));
-      memset(jcr->msgs, 0, sizeof(MSGS));
-      jcr->msgs->dest_chain = temp_chain;
-      memcpy(jcr->msgs->send_msg, msg->send_msg, sizeof(msg->send_msg));
+      jcr->jcr_msgs = (MSGS *)malloc(sizeof(MSGS));
+      memset(jcr->jcr_msgs, 0, sizeof(MSGS));
+      jcr->jcr_msgs->dest_chain = temp_chain;
+      memcpy(jcr->jcr_msgs->send_msg, msg->send_msg, sizeof(msg->send_msg));
    } else {
       daemon_msgs = (MSGS *)malloc(sizeof(MSGS));
       memset(daemon_msgs, 0, sizeof(MSGS));
@@ -304,19 +306,16 @@ void rem_msg_dest(MSGS *msg, int dest_code, int msg_type, char *where)
  */
 static char *edit_job_codes(JCR *jcr, char *omsg, char *imsg, char *to)   
 {
-   char *p, *o, *str;
+   char *p, *str;
    char add[20];
 
+   *omsg = 0;
    Dmsg1(200, "edit_job_codes: %s\n", imsg);
-   add[2] = 0;
-   o = omsg;
    for (p=imsg; *p; p++) {
       if (*p == '%') {
         switch (*++p) {
          case '%':
-            add[0] = '%';
-           add[1] = 0;
-           str = add;
+            str = "%";
            break;
          case 'c':
            str = jcr->client_name;
@@ -349,6 +348,7 @@ static char *edit_job_codes(JCR *jcr, char *omsg, char *imsg, char *to)
         default:
             add[0] = '%';
            add[1] = *p;
+           add[2] = 0;
            str = add;
            break;
         }
@@ -358,11 +358,9 @@ static char *edit_job_codes(JCR *jcr, char *omsg, char *imsg, char *to)
         str = add;
       }
       Dmsg1(200, "add_str %s\n", str);
-      add_str_to_pool_mem(&omsg, &o, str);
-      *o = 0;
+      pm_strcat(&omsg, str);
       Dmsg1(200, "omsg=%s\n", omsg);
    }
-   *o = 0;
    return omsg;
 }
 
@@ -421,7 +419,7 @@ static void make_unique_mail_filename(JCR *jcr, POOLMEM **name, DEST *d)
 /*
  * Open a mail pipe
  */
-static FILE *open_mail_pipe(JCR *jcr, char **cmd, DEST *d)
+static FILE *open_mail_pipe(JCR *jcr, POOLMEM **cmd, DEST *d)
 {
    FILE *pfd;
 
@@ -457,8 +455,8 @@ void close_msg(void *vjcr)
       msgs = daemon_msgs;
       daemon_msgs = NULL;
    } else {
-      msgs = jcr->msgs;
-      jcr->msgs = NULL;
+      msgs = jcr->jcr_msgs;
+      jcr->jcr_msgs = NULL;
    }
    if (msgs == NULL) {
       return;
@@ -597,7 +595,7 @@ void dispatch_message(void *vjcr, int type, int level, char *msg)
     /* Now figure out where to send the message */
     msgs = NULL;
     if (jcr) {
-       msgs = jcr->msgs;
+       msgs = jcr->jcr_msgs;
     } 
     if (msgs == NULL) {
        msgs = daemon_msgs;
@@ -854,7 +852,7 @@ Jmsg(void *vjcr, int type, int level, char *fmt,...)
     msgs = NULL;
     job = NULL;
     if (jcr) {
-       msgs = jcr->msgs;
+       msgs = jcr->jcr_msgs;
        job = jcr->Job;
     } 
     if (!msgs) {
index 20f5f3095e4fab754c0684d948ab706baea43d83..ca9266cc2f0dec4b44d729e5239a559e98294b40 100644 (file)
@@ -154,7 +154,8 @@ int          is_a_number             (const char *num);
 int             string_to_btime         (char *str, btime_t *value);
 char            *edit_btime             (btime_t val, char *buf);
 void            jobstatus_to_ascii      (int JobStatus, char *msg, int maxlen);
-void            add_str_to_pool_mem     (POOLMEM **base, char **msg, char *str);
+void            pm_strcat               (POOLMEM **pm, char *str);
+void            pm_strcpy               (POOLMEM **pm, char *str);
 int             run_program             (char *prog, int wait, POOLMEM *results);
 char *          job_type_to_str         (int type);
 char *          job_status_to_str       (int stat);
index f2cf12de38a51fd549e710e8718021714573bc33..405d32e57c7d3c2ea8a60c2a063e2c5f1b13cc09 100644 (file)
@@ -323,22 +323,27 @@ char *encode_time(time_t time, char *buf)
 }
 
 /*
- * Concatenate a string (str) onto a poolmem message (msg)
- *  return new message pointer. The base of the pool memory
- *  is base.
+ * Concatenate a string (str) onto a pool memory buffer pm
  */
-void add_str_to_pool_mem(POOLMEM **base, char **msg, char *str)
+void pm_strcat(POOLMEM **pm, char *str)
 {
+   int pmlen = strlen(*pm);
    int len = strlen(str) + 1;
-   char *b, *m;
 
-   b = *base;
-   *base = check_pool_memory_size(*base, len);
-   m = *base - b + *msg;
-   while (*str) {
-      *m++ = *str++;
-   }
-   *msg = m;
+   *pm = check_pool_memory_size(*pm, pmlen + len);
+   memcpy(*pm+pmlen, str, len);
+}
+
+
+/*
+ * Copy a string (str) into a pool memory buffer pm
+ */
+void pm_strcpy(POOLMEM **pm, char *str)
+{
+   int len = strlen(str) + 1;
+
+   *pm = check_pool_memory_size(*pm, len);
+   memcpy(*pm, str, len);
 }
 
 
index 903de5ddae1adffcd2a992fa778cbaa1f5d2095c..3ea5449d26c2cf57b57cba5285c3c2e41b25b773 100644 (file)
@@ -80,7 +80,7 @@ int main (int argc, char *argv[])
       switch (ch) {
          case 'b':                    /* bootstrap file */
            bsr = parse_bsr(NULL, optarg);
-           dump_bsr(bsr);
+//         dump_bsr(bsr);
            break;
 
          case 'd':                    /* debug level */
index 6154d79851c34b74cf5c049ee8079e4d91c4e634..7b231a6c663e424e43cda0d7ccc43764928e3a7d 100644 (file)
@@ -46,13 +46,18 @@ typedef struct s_vol_list VOL_LIST;
 
 /*
  * !!!!!!!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- * !!!                                               !!!
- * !!!   All records must have a pointer to          !!!
- * !!!   the next item as the first item defined.    !!!
- * !!!                                               !!!
+ * !!!                                              !!!
+ * !!!  All records must have a pointer to          !!!
+ * !!!  the next item as the first item defined.    !!!
+ * !!!                                              !!!
  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  */
 
+typedef struct s_bsr_volume {
+   struct s_bsr_volume *next;
+   char VolumeName[MAX_NAME_LENGTH];
+} BSR_VOLUME;
+
 typedef struct s_bsr_client {
    struct s_bsr_client *next;
    char ClientName[MAX_NAME_LENGTH];
@@ -73,15 +78,15 @@ typedef struct s_bsr_sesstime {
 
 typedef struct s_bsr_volfile {
    struct s_bsr_volfile *next;
-   uint32_t sfile;                    /* start file */
-   uint32_t efile;                    /* end file */
+   uint32_t sfile;                   /* start file */
+   uint32_t efile;                   /* end file */
    int found;
 } BSR_VOLFILE;
 
 typedef struct s_bsr_findex {
    struct s_bsr_findex *next;
-   int32_t findex;                    /* start file index */
-   int32_t findex2;                   /* end file index */
+   int32_t findex;                   /* start file index */
+   int32_t findex2;                  /* end file index */
    int found;
 } BSR_FINDEX;
 
@@ -110,26 +115,26 @@ typedef struct s_bsr_job {
 
 typedef struct s_bsr_stream {
    struct s_bsr_stream *next;
-   int32_t stream;                    /* stream desired */
+   int32_t stream;                   /* stream desired */
    int found;
 } BSR_STREAM;
 
 typedef struct s_bsr {
-   struct s_bsr *next;                /* pointer to next one */
-   int           done;                /* set when everything found */
-   char         *VolumeName;
-   int32_t       Slot;                /* Slot */
-   BSR_VOLFILE  *volfile;
+   struct s_bsr *next;               /* pointer to next one */
+   int          done;                /* set when everything found */
+   BSR_VOLUME  *volume;
+   int32_t      Slot;                /* Slot */
+   BSR_VOLFILE *volfile;
    BSR_SESSTIME *sesstime;
-   BSR_SESSID   *sessid;
-   BSR_JOBID    *JobId;
-   BSR_JOB      *job;
-   BSR_CLIENT   *client;
-   BSR_FINDEX   *FileIndex;
-   BSR_JOBTYPE  *JobType;
+   BSR_SESSID  *sessid;
+   BSR_JOBID   *JobId;
+   BSR_JOB     *job;
+   BSR_CLIENT  *client;
+   BSR_FINDEX  *FileIndex;
+   BSR_JOBTYPE *JobType;
    BSR_JOBLEVEL *JobLevel;
-   BSR_STREAM   *stream;
-// FF_PKT *ff;                        /* include/exclude */
+   BSR_STREAM  *stream;
+// FF_PKT *ff;                       /* include/exclude */
 } BSR;
 
 
index 9ff3b759f44187cec20dd1db4c969877ef67f000..1bee572b4c93039b7e80a858a5f7ebee94c6d60c 100644 (file)
@@ -829,20 +829,17 @@ void unblock_device(DEVICE *dev)
  */
 static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd) 
 {
-   char *p, *o;
+   char *p;
    const char *str;
    char add[20];
 
+   *omsg = 0;
    Dmsg1(200, "edit_device_codes: %s\n", imsg);
-   add[2] = 0;
-   o = omsg;
    for (p=imsg; *p; p++) {
       if (*p == '%') {
         switch (*++p) {
          case '%':
-            add[0] = '%';
-           add[1] = 0;
-           str = add;
+            str = "%";
            break;
          case 'a':
            str = jcr->device->dev->dev_name;
@@ -865,21 +862,16 @@ static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd)
            str = jcr->Job;
            break;
          case 'v':
-           str = jcr->VolumeName;
-           if (!str) {
-               str = "";
-           }
+           str = NPRT(jcr->VolumeName);
            break;
          case 'f':
-           str = jcr->client_name;
-           if (!str) {
-               str = "";
-           }
+           str = NPRT(jcr->client_name);
            break;
 
         default:
             add[0] = '%';
            add[1] = *p;
+           add[2] = 0;
            str = add;
            break;
         }
@@ -889,10 +881,8 @@ static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd)
         str = add;
       }
       Dmsg1(200, "add_str %s\n", str);
-      add_str_to_pool_mem(&omsg, &o, (char *)str);
-      *o = 0;
+      pm_strcat(&omsg, (char *)str);
       Dmsg1(200, "omsg=%s\n", omsg);
    }
-   *o = 0;
    return omsg;
 }
index 5424b89a6f7bf62814ae899581b117a0e1d58152..93c849ce9271681f3a76897da364b68d2882d24a 100644 (file)
@@ -329,7 +329,7 @@ static int bootstrap_cmd(JCR *jcr)
       goto bail_out;
    }
    while (bnet_recv(fd) > 0) {
-       Dmsg1(000, "stored<filed: bootstrap file %s\n", fd->msg);
+       Dmsg1(400, "stored<filed: bootstrap file %s\n", fd->msg);
        fputs(fd->msg, bs);
    }
    fclose(bs);
index b7e331d7f010bdd4568d9f5995daec6aa7c6d47d..000d6a3504034d2b4e815a6bffd18d664ebbb587 100755 (executable)
@@ -33,6 +33,7 @@
 #include <fnmatch.h>
 
 /* Forward references */
+static int match_volume(BSR_VOLUME *volume, VOLUME_LABEL *volrec);
 static int match_sesstime(BSR_SESSTIME *sesstime, DEV_RECORD *rec);
 static int match_sessid(BSR_SESSID *sessid, DEV_RECORD *rec);
 static int match_client(BSR_CLIENT *client, SESSION_LABEL *sessrec);
@@ -63,7 +64,7 @@ int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *se
 
 static int match_one_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec)
 {
-   if (strcmp(bsr->VolumeName, volrec->VolName) != 0) {
+   if (!match_volume(bsr->volume, volrec)) {
       return 0;
    }
    if (!match_volfile(bsr->volfile, rec)) {
@@ -99,6 +100,20 @@ static int match_one_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSIO
    return 1;
 }
 
+static int match_volume(BSR_VOLUME *volume, VOLUME_LABEL *volrec) 
+{
+   if (!volume) {
+      return 0;                      /* Volume must match */
+   }
+   if (strcmp(volume->VolumeName, volrec->VolName) == 0) {
+      return 1;
+   }
+   if (volume->next) {
+      return match_volume(volume->next, volrec);
+   }
+   return 0;
+}
+
 static int match_client(BSR_CLIENT *client, SESSION_LABEL *sessrec)
 {
    if (!client) {
index 4cd7cba3d79d090c3744a6cbcfd1c6dbc88c06cd..7daab8c21ce39f1c5748ddc75194780f2a75a0c8 100755 (executable)
@@ -51,6 +51,9 @@ struct kw_items {
    ITEM_HANDLER *handler;
 };
 
+/*
+ * List of all keywords permitted in bsr files and their handlers
+ */
 struct kw_items items[] = {
    {"volume", store_vol},
    {"client", store_client},
@@ -70,6 +73,9 @@ struct kw_items items[] = {
 
 };
 
+/* 
+ * Create a BSR record
+ */
 static BSR *new_bsr() 
 {
    BSR *bsr = (BSR *)malloc(sizeof(BSR));
@@ -160,17 +166,35 @@ BSR *parse_bsr(JCR *jcr, char *cf)
 static BSR *store_vol(LEX *lc, BSR *bsr)
 {
    int token;
+   BSR_VOLUME *volume;
+   char *p, *n;
     
-   token = lex_get_token(lc, T_NAME);
+   token = lex_get_token(lc, T_STRING);
    if (token == T_ERROR) {
       return NULL;
    }
-   if (bsr->VolumeName) {
-      bsr->next = new_bsr();
-      bsr = bsr->next;
+   /* This may actually be more than one volume separated by a |  
+    * If so, separate them.
+    */
+   for (p=lc->str; p && *p; ) {
+      n = strchr(p, '|');
+      if (n) {
+        *n++ = 0;
+      }
+      volume = (BSR_VOLUME *)malloc(sizeof(BSR_VOLUME));
+      memset(volume, 0, sizeof(BSR_VOLUME));
+      strcpy(volume->VolumeName, p);
+      /* Add it to the end of the volume chain */
+      if (!bsr->volume) {
+        bsr->volume = volume;
+      } else {
+        BSR_VOLUME *bc = bsr->volume;
+        for ( ;bc->next; bc=bc->next)  
+           { }
+        bc->next = volume;
+      }
+      p = n;
    }
-   bsr->VolumeName = bstrdup(lc->str);
-   scan_to_eol(lc);
    return bsr;
 }
 
@@ -519,6 +543,14 @@ void dump_sessid(BSR_SESSID *sessid)
    }
 }
 
+void dump_volume(BSR_VOLUME *volume)
+{
+   if (volume) {
+      Dmsg1(-1, "VolumeName  : %s\n", volume->VolumeName);
+      dump_volume(volume->next);
+   }
+}
+
 
 void dump_client(BSR_CLIENT *client)
 {
@@ -554,11 +586,9 @@ void dump_bsr(BSR *bsr)
       Dmsg0(-1, "BSR is NULL\n");
       return;
    }
-   Dmsg2(-1,   
-"Next        : 0x%x\n"
-"VolumeName  : %s\n",
-                bsr->next,
-                 bsr->VolumeName ? bsr->VolumeName : "*None*");
+   Dmsg1(-1,   
+"Next        : 0x%x\n", bsr->next);
+   dump_volume(bsr->volume);
    dump_sessid(bsr->sessid);
    dump_sesstime(bsr->sesstime);
    dump_volfile(bsr->volfile);
@@ -592,6 +622,7 @@ void free_bsr(BSR *bsr)
    if (!bsr) {
       return;
    }
+   free_bsr_item((BSR *)bsr->volume);
    free_bsr_item((BSR *)bsr->client);
    free_bsr_item((BSR *)bsr->sessid);
    free_bsr_item((BSR *)bsr->sesstime);
@@ -601,9 +632,6 @@ void free_bsr(BSR *bsr)
    free_bsr_item((BSR *)bsr->FileIndex);
    free_bsr_item((BSR *)bsr->JobType);
    free_bsr_item((BSR *)bsr->JobLevel);
-   if (bsr->VolumeName) {
-      free(bsr->VolumeName);
-   }
    free_bsr(bsr->next);
    free(bsr);
 }
@@ -670,16 +698,19 @@ void create_vol_list(JCR *jcr)
    jcr->CurVolume = 1;
    if (jcr->bsr) {
       BSR *bsr = jcr->bsr;
-      strcpy(jcr->VolumeName, bsr->VolumeName); /* setup first volume */
+      strcpy(jcr->VolumeName, bsr->volume->VolumeName); /* setup first volume */
       for ( ; bsr; bsr=bsr->next) {
-        vol = new_vol();
-        strcpy(vol->VolumeName, bsr->VolumeName);
-        if (add_vol(jcr, vol)) {
-           jcr->NumVolumes++;
-            Dmsg1(400, "Added volume %s\n", vol->VolumeName);
-        } else {
-            Dmsg1(400, "Duplicate volume %s\n", vol->VolumeName);
-           free((char *)vol);
+        BSR_VOLUME *bsrvol = bsr->volume;
+        for ( ; bsrvol; bsrvol=bsrvol->next) {
+           vol = new_vol();
+           strcpy(vol->VolumeName, bsrvol->VolumeName);
+           if (add_vol(jcr, vol)) {
+              jcr->NumVolumes++;
+               Dmsg1(400, "Added volume %s\n", vol->VolumeName);
+           } else {
+               Dmsg1(400, "Duplicate volume %s\n", vol->VolumeName);
+              free((char *)vol);
+           }
         }
       }
    } else {