]> git.sur5r.net Git - bacula/bacula/commitdiff
- Put Dmsg() on inside if() to avoid calling subroutine.
authorKern Sibbald <kern@sibbald.com>
Wed, 25 May 2005 19:35:02 +0000 (19:35 +0000)
committerKern Sibbald <kern@sibbald.com>
Wed, 25 May 2005 19:35:02 +0000 (19:35 +0000)
- Make restore.bsr have unique name.
- Allow user to define bsr filename on restore command line
  with bootstrap=xxx.bsr
- Add limit=nnn to list jobs command.
- Remove old restore code that did not use .bsr file.
- unlink automatically generated bsr file.
- Cleanup heartbeat code so that duped fd is almost sure
  to be released. Previously under certain conditions, the
  memory was not released due to race conditions.
- Shorten copyright.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2083 91ce42f0-d328-0410-95d8-f526ca767f89

26 files changed:
bacula/kernstodo
bacula/kes-1.37
bacula/src/baconfig.h
bacula/src/cats/cats.h
bacula/src/cats/sql_list.c
bacula/src/dird/bsr.c
bacula/src/dird/msgchan.c
bacula/src/dird/protos.h
bacula/src/dird/restore.c
bacula/src/dird/ua_output.c
bacula/src/dird/ua_restore.c
bacula/src/dird/verify.c
bacula/src/filed/heartbeat.c
bacula/src/filed/job.c
bacula/src/jcr.h
bacula/src/lib/bnet.c
bacula/src/lib/bsock.h
bacula/src/lib/mem_pool.c
bacula/src/lib/message.c
bacula/src/lib/tree.c
bacula/src/stored/acquire.c
bacula/src/stored/dev.c
bacula/src/stored/match_bsr.c
bacula/src/stored/parse_bsr.c
bacula/src/stored/read.c
bacula/src/stored/spool.c

index 2e77799bb3c0e413d2f17c9e927c73fc86bca525..f64d347891b01283b6195ce1e095a31a62061b4a 100644 (file)
@@ -54,7 +54,6 @@ Document:
 - Document new CDROM directory.
 
 For 1.37:
-- Make bootstrap filename unique.
 - From Chris Hull:
    it seems to be complaining about 12:00pm which should be a valid 12
    hour time.  I changed the time to 11:59am and everything works fine.
@@ -65,8 +64,6 @@ For 1.37:
   jcr->last_runtime
   MA = (last_MA * 3 + rate) / 4
   rate = (bytes - last_bytes) / (runtime - last_runtime)
-- Add "limit=n" for "list jobs"
-- Make Dmsg look at global before calling subroutine.
 - Despool attributes simultaneously with data in a separate
   thread, rejoined at end of data spooling.
 - Implement Files/Bytes,... stats for restore job.
@@ -1284,4 +1281,6 @@ Block Position: 0
 - Add a date and time stamp at the beginning of every line in the 
   Job report (Volker Sauer).
 - Add level to estimate command.
-
+- Add "limit=n" for "list jobs"
+- Make bootstrap filename unique.
+- Make Dmsg look at global before calling subroutine.
index 252f4c7cffee22ce4627ceeb27c9ec7e6ae37dfc..655b9c40f5940f916c06a0b200a9cace15d561b4 100644 (file)
@@ -4,6 +4,18 @@
 General:
 
 Changes to 1.37.19:
+25May05
+- Put Dmsg() on inside if() to avoid calling subroutine.
+- Make restore.bsr have unique name.
+- Allow user to define bsr filename on restore command line
+  with bootstrap=xxx.bsr
+- Add limit=nnn to "list jobs" command.
+- Remove old restore code that did not use .bsr file.
+- unlink automatically generated bsr file.
+- Cleanup heartbeat code so that duped fd is almost sure
+  to be released. Previously under certain conditions, the
+  memory was not released due to race conditions.
+- Shorten copyright.
 20May05
 - Unify the reserve_device() for a single device into one subroutine.
 18May05
index ba387be910e8be9ec786f9f1c12f7ee10a4c9f03..7e665ae10a90b78932faf9bd9cd4b3c124306be0 100644 (file)
@@ -8,19 +8,14 @@
    Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -303,20 +298,20 @@ void b_memset(const char *file, int line, void *mem, int val, size_t num);
  */
 /* Debug Messages that are printed */
 #ifdef DEBUG
-#define Dmsg0(lvl, msg)             d_msg(__FILE__, __LINE__, lvl, msg)
-#define Dmsg1(lvl, msg, a1)         d_msg(__FILE__, __LINE__, lvl, msg, a1)
-#define Dmsg2(lvl, msg, a1, a2)     d_msg(__FILE__, __LINE__, lvl, msg, a1, a2)
-#define Dmsg3(lvl, msg, a1, a2, a3) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3)
-#define Dmsg4(lvl, msg, arg1, arg2, arg3, arg4) d_msg(__FILE__, __LINE__, lvl, msg, arg1, arg2, arg3, arg4)
-#define Dmsg5(lvl, msg, a1, a2, a3, a4, a5) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5)
-#define Dmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6)
-#define Dmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7)
-#define Dmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
-#define Dmsg9(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9)
-#define Dmsg10(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
-#define Dmsg11(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
-#define Dmsg12(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
-#define Dmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
+#define Dmsg0(lvl, msg)             if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg)
+#define Dmsg1(lvl, msg, a1)         if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1)
+#define Dmsg2(lvl, msg, a1, a2)     if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2)
+#define Dmsg3(lvl, msg, a1, a2, a3) if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3)
+#define Dmsg4(lvl, msg, arg1, arg2, arg3, arg4) if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, arg1, arg2, arg3, arg4)
+#define Dmsg5(lvl, msg, a1, a2, a3, a4, a5) if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5)
+#define Dmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6)
+#define Dmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7) if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7)
+#define Dmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
+#define Dmsg9(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9) if ((lvl)<=debug_level) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9)
+#define Dmsg10(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) if ((lvl)<=debug_level) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
+#define Dmsg11(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) if ((lvl)<=debug_level) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
+#define Dmsg12(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) if ((lvl)<=debug_level) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
+#define Dmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) if ((lvl)<=debug_level) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
 #else
 #define Dmsg0(lvl, msg)
 #define Dmsg1(lvl, msg, a1)
index 5319f74de1dcae67dd2ee3dd1f7f29512415d704..02b30d5f7cbdfb4b1f29a1504326bb7c6d7621e2 100644 (file)
@@ -566,6 +566,7 @@ struct JOB_DBR {
    char cStartTime[MAX_TIME_LENGTH];
    char cEndTime[MAX_TIME_LENGTH];
    /* Extra stuff not in DB */
+   int limit;                         /* limit records to display */
    faddr_t rec_addr;
 };
 
index 0abc749d5ec6add8bdfc1af5d035928abc0ae856..cb229b72c20bdeff1e006bce3578b195507ea0b4 100644 (file)
@@ -29,7 +29,7 @@
 /* The following is necessary so that we do not include
  * the dummy external definition of DB.
  */
-#define __SQL_C                       /* indicate that this is sql.c */
+#define __SQL_C                      /* indicate that this is sql.c */
 
 #include "bacula.h"
 #include "cats.h"
@@ -52,13 +52,13 @@ extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_
  * Submit general SQL query
  */
 int db_list_sql_query(JCR *jcr, B_DB *mdb, char *query, DB_LIST_HANDLER *sendit,
-                      void *ctx, int verbose, e_list_type type)
+                     void *ctx, int verbose, e_list_type type)
 {
    db_lock(mdb);
    if (sql_query(mdb, query) != 0) {
       Mmsg(mdb->errmsg, _("Query failed: %s\n"), sql_strerror(mdb));
       if (verbose) {
-         sendit(ctx, mdb->errmsg);
+        sendit(ctx, mdb->errmsg);
       }
       db_unlock(mdb);
       return 0;
@@ -131,7 +131,7 @@ db_list_client_records(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *sendit, void *ctx,
  */
 void
 db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
-                      DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
+                     DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
 {
    char ed1[50];
    db_lock(mdb);
@@ -152,7 +152,7 @@ db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
             "VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,"
             "EndFile,EndBlock,VolParts,LabelType,StorageId"
             " FROM Media WHERE Media.PoolId=%s ORDER BY MediaId", 
-            edit_int64(mdbr->PoolId, ed1));
+           edit_int64(mdbr->PoolId, ed1));
       }
    } else {
       if (mdbr->VolumeName[0] != 0) {
@@ -163,7 +163,7 @@ db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
          Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolStatus,"
             "VolBytes,VolFiles,VolRetention,Recycle,Slot,InChanger,MediaType,LastWritten "
             "FROM Media WHERE Media.PoolId=%s ORDER BY MediaId", 
-            edit_int64(mdbr->PoolId, ed1));
+           edit_int64(mdbr->PoolId, ed1));
       }
    }
 
@@ -179,12 +179,12 @@ db_list_media_records(JCR *jcr, B_DB *mdb, MEDIA_DBR *mdbr,
 }
 
 void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
-                              DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
+                             DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
 {
    char ed1[50];
    db_lock(mdb);
    if (type == VERT_LIST) {
-      if (JobId > 0) {                   /* do by JobId */
+      if (JobId > 0) {                  /* do by JobId */
          Mmsg(mdb->cmd, "SELECT JobMediaId,JobId,Media.MediaId,Media.VolumeName,"
             "FirstIndex,LastIndex,StartFile,JobMedia.EndFile,StartBlock,"
             "JobMedia.EndBlock,Copy,Stripe "
@@ -198,7 +198,7 @@ void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
       }
 
    } else {
-      if (JobId > 0) {                   /* do by JobId */
+      if (JobId > 0) {                  /* do by JobId */
          Mmsg(mdb->cmd, "SELECT JobId,Media.VolumeName,FirstIndex,LastIndex "
             "FROM JobMedia,Media WHERE Media.MediaId=JobMedia.MediaId "
             "AND JobMedia.JobId=%s", edit_int64(JobId, ed1));
@@ -228,13 +228,19 @@ void db_list_jobmedia_records(JCR *jcr, B_DB *mdb, uint32_t JobId,
  */
 void
 db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
-                    void *ctx, e_list_type type)
+                   void *ctx, e_list_type type)
 {
    char ed1[50];
+   char limit[100];
    db_lock(mdb);
+   if (jr->limit > 0) {
+      snprintf(limit, sizeof(limit), " LIMIT %d", jr->limit);
+   } else {
+      limit[0] = 0;
+   }
    if (type == VERT_LIST) {
       if (jr->JobId == 0 && jr->Job[0] == 0) {
-         Mmsg(mdb->cmd,
+        Mmsg(mdb->cmd,
             "SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level,"
             "Job.ClientId,Client.Name,JobStatus,SchedTime,"
             "StartTime,EndTime,JobTDate,"
@@ -242,9 +248,9 @@ db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
             "JobMissingFiles,Job.PoolId,Pool.Name,Job.FileSetId,FileSet.FileSet "
             "FROM Job,Client,Pool,FileSet WHERE "
             "Client.ClientId=Job.ClientId AND Pool.PoolId=Job.PoolId "
-            "AND FileSet.FileSetId=Job.FileSetId  ORDER BY StartTime");
-      } else {                           /* single record */
-         Mmsg(mdb->cmd,
+            "AND FileSet.FileSetId=Job.FileSetId  ORDER BY StartTime%s", limit);
+      } else {                          /* single record */
+        Mmsg(mdb->cmd,
             "SELECT JobId,Job,Job.Name,PurgedFiles,Type,Level,"
             "Job.ClientId,Client.Name,JobStatus,SchedTime,"
             "StartTime,EndTime,JobTDate,"
@@ -253,17 +259,17 @@ db_list_job_records(JCR *jcr, B_DB *mdb, JOB_DBR *jr, DB_LIST_HANDLER *sendit,
             "FROM Job,Client,Pool,FileSet WHERE Job.JobId=%s AND "
             "Client.ClientId=Job.ClientId AND Pool.PoolId=Job.PoolId "
             "AND FileSet.FileSetId=Job.FileSetId", 
-            edit_int64(jr->JobId, ed1));
+           edit_int64(jr->JobId, ed1));
       }
    } else {
       if (jr->JobId == 0 && jr->Job[0] == 0) {
-         Mmsg(mdb->cmd,
+        Mmsg(mdb->cmd,
            "SELECT JobId,Name,StartTime,Type,Level,JobFiles,JobBytes,JobStatus "
-           "FROM Job ORDER BY StartTime");
-      } else {                           /* single record */
+           "FROM Job ORDER BY StartTime%s", limit);
+      } else {                          /* single record */
          Mmsg(mdb->cmd, "SELECT JobId,Name,StartTime,Type,Level,"
             "JobFiles,JobBytes,JobStatus FROM Job WHERE JobId=%s", 
-            edit_int64(jr->JobId, ed1));
+           edit_int64(jr->JobId, ed1));
       }
    }
    if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
index 01de4416d3386e2915806268e55be22f45519e01..c21937899e12be8dede958816792fae2daab7fb6 100644 (file)
@@ -2,8 +2,8 @@
  *
  *   Bacula Director -- Bootstrap Record routines.
  *
- *      BSR (bootstrap record) handling routines split from
- *        ua_restore.c July MMIII
+ *     BSR (bootstrap record) handling routines split from
+ *       ua_restore.c July MMIII
  *
  *     Kern Sibbald, July MMII
  *
    Copyright (C) 2002-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -69,23 +64,23 @@ static void free_findex(RBSR_FINDEX *fi)
  *  for each Volume.
  */
 static uint32_t write_findex(UAContext *ua, RBSR_FINDEX *fi,
-              int32_t FirstIndex, int32_t LastIndex, FILE *fd)
+             int32_t FirstIndex, int32_t LastIndex, FILE *fd)
 {
    uint32_t count = 0;
    for ( ; fi; fi=fi->next) {
       int32_t findex, findex2;
       if ((fi->findex >= FirstIndex && fi->findex <= LastIndex) ||
-          (fi->findex2 >= FirstIndex && fi->findex2 <= LastIndex) ||
-          (fi->findex < FirstIndex && fi->findex2 > LastIndex)) {
-         findex = fi->findex < FirstIndex ? FirstIndex : fi->findex;
-         findex2 = fi->findex2 > LastIndex ? LastIndex : fi->findex2;
-         if (findex == findex2) {
+         (fi->findex2 >= FirstIndex && fi->findex2 <= LastIndex) ||
+         (fi->findex < FirstIndex && fi->findex2 > LastIndex)) {
+        findex = fi->findex < FirstIndex ? FirstIndex : fi->findex;
+        findex2 = fi->findex2 > LastIndex ? LastIndex : fi->findex2;
+        if (findex == findex2) {
             fprintf(fd, "FileIndex=%d\n", findex);
-            count++;
-         } else {
+           count++;
+        } else {
             fprintf(fd, "FileIndex=%d-%d\n", findex, findex2);
-            count += findex2 - findex + 1;
-         }
+           count += findex2 - findex + 1;
+        }
       }
    }
    return count;
@@ -96,13 +91,13 @@ static uint32_t write_findex(UAContext *ua, RBSR_FINDEX *fi,
  *   falls within the range of selected files in the bsr.
  */
 static bool is_volume_selected(RBSR_FINDEX *fi,
-              int32_t FirstIndex, int32_t LastIndex)
+             int32_t FirstIndex, int32_t LastIndex)
 {
    for ( ; fi; fi=fi->next) {
       if ((fi->findex >= FirstIndex && fi->findex <= LastIndex) ||
-          (fi->findex2 >= FirstIndex && fi->findex2 <= LastIndex) ||
-          (fi->findex < FirstIndex && fi->findex2 > LastIndex)) {
-         return true;
+         (fi->findex2 >= FirstIndex && fi->findex2 <= LastIndex) ||
+         (fi->findex < FirstIndex && fi->findex2 > LastIndex)) {
+        return true;
       }
    }
    return false;
@@ -139,7 +134,7 @@ void free_bsr(RBSR *bsr)
    for ( ; bsr; bsr=next) {
       free_findex(bsr->fi);
       if (bsr->VolParams) {
-         free(bsr->VolParams);
+        free(bsr->VolParams);
       }
       next = bsr->next;
       free(bsr);
@@ -158,23 +153,37 @@ bool complete_bsr(UAContext *ua, RBSR *bsr)
       jr.JobId = bsr->JobId;
       if (!db_get_job_record(ua->jcr, ua->db, &jr)) {
          bsendmsg(ua, _("Unable to get Job record. ERR=%s\n"), db_strerror(ua->db));
-         return false;
+        return false;
       }
       bsr->VolSessionId = jr.VolSessionId;
       bsr->VolSessionTime = jr.VolSessionTime;
       if ((bsr->VolCount=db_get_job_volume_parameters(ua->jcr, ua->db, bsr->JobId,
-           &(bsr->VolParams))) == 0) {
+          &(bsr->VolParams))) == 0) {
          bsendmsg(ua, _("Unable to get Job Volume Parameters. ERR=%s\n"), db_strerror(ua->db));
-         if (bsr->VolParams) {
-            free(bsr->VolParams);
-            bsr->VolParams = NULL;
-         }
-         return false;
+        if (bsr->VolParams) {
+           free(bsr->VolParams);
+           bsr->VolParams = NULL;
+        }
+        return false;
       }
    }
    return true;
 }
 
+void make_unique_restore_filename(UAContext *ua, POOLMEM **fname)
+{
+   JCR *jcr = ua->jcr;
+   int i = find_arg_with_value(ua, "bootstrap");
+   if (i >= 0) {
+      Mmsg(fname, "%s", ua->argv[i]);              
+      jcr->unlink_bsr = false;
+   } else {
+      Mmsg(fname, "%s/%s.restore.%s.bsr", working_directory, my_name, 
+        jcr->Job);
+      jcr->unlink_bsr = true;
+   }
+}
+
 /*
  * Write the bootstrap records to file
  */
@@ -185,12 +194,12 @@ uint32_t write_bsr_file(UAContext *ua, RBSR *bsr)
    uint32_t count = 0;;
    bool err;
 
-   Mmsg(fname, "%s/restore.bsr", working_directory);
+   make_unique_restore_filename(ua, &fname);
    fd = fopen(fname, "w+");
    if (!fd) {
       berrno be;
       bsendmsg(ua, _("Unable to create bootstrap file %s. ERR=%s\n"),
-         fname, be.strerror());
+        fname, be.strerror());
       goto bail_out;
    }
    /* Write them to file */
@@ -213,9 +222,9 @@ uint32_t write_bsr_file(UAContext *ua, RBSR *bsr)
    start_prompt(ua, "");
    for (RBSR *nbsr=bsr; nbsr; nbsr=nbsr->next) {
       for (int i=0; i < nbsr->VolCount; i++) {
-         if (nbsr->VolParams[i].VolumeName[0]) {
-            add_prompt(ua, nbsr->VolParams[i].VolumeName);
-         }
+        if (nbsr->VolParams[i].VolumeName[0]) {
+           add_prompt(ua, nbsr->VolParams[i].VolumeName);
+        }
       }
    }
    for (int i=0; i < ua->num_prompts; i++) {
@@ -246,45 +255,45 @@ static uint32_t write_bsr(UAContext *ua, RBSR *bsr, FILE *fd)
        *   VolCount is the number of JobMedia records.
        */
       for (int i=0; i < bsr->VolCount; i++) {
-         if (!is_volume_selected(bsr->fi, bsr->VolParams[i].FirstIndex,
-              bsr->VolParams[i].LastIndex)) {
-            bsr->VolParams[i].VolumeName[0] = 0;  /* zap VolumeName */
-            continue;
-         }
+        if (!is_volume_selected(bsr->fi, bsr->VolParams[i].FirstIndex,
+             bsr->VolParams[i].LastIndex)) {
+           bsr->VolParams[i].VolumeName[0] = 0;  /* zap VolumeName */
+           continue;
+        }
          fprintf(fd, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName);
          fprintf(fd, "MediaType=\"%s\"\n", bsr->VolParams[i].MediaType);
          fprintf(fd, "VolSessionId=%u\n", bsr->VolSessionId);
          fprintf(fd, "VolSessionTime=%u\n", bsr->VolSessionTime);
-         if (bsr->VolParams[i].StartFile == bsr->VolParams[i].EndFile) {
+        if (bsr->VolParams[i].StartFile == bsr->VolParams[i].EndFile) {
             fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartFile);
-         } else {
+        } else {
             fprintf(fd, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile,
-                    bsr->VolParams[i].EndFile);
-         }
-         if (bsr->VolParams[i].StartBlock == bsr->VolParams[i].EndBlock) {
+                   bsr->VolParams[i].EndFile);
+        }
+        if (bsr->VolParams[i].StartBlock == bsr->VolParams[i].EndBlock) {
             fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartBlock);
-         } else {
+        } else {
             fprintf(fd, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock,
-                    bsr->VolParams[i].EndBlock);
-         }
+                   bsr->VolParams[i].EndBlock);
+        }
 //       Dmsg2(100, "bsr VolParam FI=%u LI=%u\n",
-//          bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex);
+//         bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex);
 
-         count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex,
-                              bsr->VolParams[i].LastIndex, fd);
-         if (count) {
+        count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex,
+                             bsr->VolParams[i].LastIndex, fd);
+        if (count) {
             fprintf(fd, "Count=%u\n", count);
-         }
-         total_count += count;
-         /* If the same file is present on two tapes or in two files
-          *   on a tape, it is a continuation, and should not be treated
-          *   twice in the totals.
-          */
-         if (!first && LastIndex == bsr->VolParams[i].FirstIndex) {
-            total_count--;
-         }
-         first = false;
-         LastIndex = bsr->VolParams[i].LastIndex;
+        }
+        total_count += count;
+        /* If the same file is present on two tapes or in two files
+         *   on a tape, it is a continuation, and should not be treated
+         *   twice in the totals.
+         */
+        if (!first && LastIndex == bsr->VolParams[i].FirstIndex) {
+           total_count--;
+        }
+        first = false;
+        LastIndex = bsr->VolParams[i].LastIndex;
       }
    }
    return total_count;
@@ -299,10 +308,10 @@ void print_bsr(UAContext *ua, RBSR *bsr)
          bsendmsg(ua, "VolSessionId=%u\n", bsr->VolSessionId);
          bsendmsg(ua, "VolSessionTime=%u\n", bsr->VolSessionTime);
          bsendmsg(ua, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile,
-                  bsr->VolParams[i].EndFile);
+                 bsr->VolParams[i].EndFile);
          bsendmsg(ua, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock,
-                  bsr->VolParams[i].EndBlock);
-         print_findex(ua, bsr->fi);
+                 bsr->VolParams[i].EndBlock);
+        print_findex(ua, bsr->fi);
       }
       print_bsr(ua, bsr->next);
    }
@@ -322,10 +331,10 @@ void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex)
    RBSR_FINDEX *fi, *lfi;
 
    if (findex == 0) {
-      return;                         /* probably a dummy directory */
+      return;                        /* probably a dummy directory */
    }
 
-   if (bsr->fi == NULL) {             /* if no FI add one */
+   if (bsr->fi == NULL) {            /* if no FI add one */
       /* This is the first FileIndex item in the chain */
       bsr->fi = new_findex();
       bsr->JobId = JobId;
@@ -336,22 +345,22 @@ void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex)
    /* Walk down list of bsrs until we find the JobId */
    if (bsr->JobId != JobId) {
       for (nbsr=bsr->next; nbsr; nbsr=nbsr->next) {
-         if (nbsr->JobId == JobId) {
-            bsr = nbsr;
-            break;
-         }
+        if (nbsr->JobId == JobId) {
+           bsr = nbsr;
+           break;
+        }
       }
 
-      if (!nbsr) {                    /* Must add new JobId */
-         /* Add new JobId at end of chain */
-         for (nbsr=bsr; nbsr->next; nbsr=nbsr->next)
-            {  }
-         nbsr->next = new_bsr();
-         nbsr->next->JobId = JobId;
-         nbsr->next->fi = new_findex();
-         nbsr->next->fi->findex = findex;
-         nbsr->next->fi->findex2 = findex;
-         return;
+      if (!nbsr) {                   /* Must add new JobId */
+        /* Add new JobId at end of chain */
+        for (nbsr=bsr; nbsr->next; nbsr=nbsr->next)
+           {  }
+        nbsr->next = new_bsr();
+        nbsr->next->JobId = JobId;
+        nbsr->next->fi = new_findex();
+        nbsr->next->fi->findex = findex;
+        nbsr->next->fi->findex2 = findex;
+        return;
       }
    }
 
@@ -363,10 +372,10 @@ void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex)
    /* Check if this findex is smaller than first item */
    if (findex < fi->findex) {
       if ((findex+1) == fi->findex) {
-         fi->findex = findex;         /* extend down */
-         return;
+        fi->findex = findex;         /* extend down */
+        return;
       }
-      fi = new_findex();              /* yes, insert before first item */
+      fi = new_findex();             /* yes, insert before first item */
       fi->findex = findex;
       fi->findex2 = findex;
       fi->next = lfi;
@@ -376,26 +385,26 @@ void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex)
    /* Walk down fi chain and find where to insert insert new FileIndex */
    for ( ; fi; fi=fi->next) {
       if (findex == (fi->findex2 + 1)) {  /* extend up */
-         RBSR_FINDEX *nfi;
-         fi->findex2 = findex;
-         /*
-          * If the following record contains one higher, merge its
-          *   file index by extending it up.
-          */
-         if (fi->next && ((findex+1) == fi->next->findex)) {
-            nfi = fi->next;
-            fi->findex2 = nfi->findex2;
-            fi->next = nfi->next;
-            free(nfi);
-         }
-         return;
+        RBSR_FINDEX *nfi;
+        fi->findex2 = findex;
+        /*
+         * If the following record contains one higher, merge its
+         *   file index by extending it up.
+         */
+        if (fi->next && ((findex+1) == fi->next->findex)) {
+           nfi = fi->next;
+           fi->findex2 = nfi->findex2;
+           fi->next = nfi->next;
+           free(nfi);
+        }
+        return;
       }
       if (findex < fi->findex) {      /* add before */
-         if ((findex+1) == fi->findex) {
-            fi->findex = findex;
-            return;
-         }
-         break;
+        if ((findex+1) == fi->findex) {
+           fi->findex = findex;
+           return;
+        }
+        break;
       }
       lfi = fi;
    }
@@ -418,7 +427,7 @@ void add_findex_all(RBSR *bsr, uint32_t JobId)
    RBSR *nbsr;
    RBSR_FINDEX *fi;
 
-   if (bsr->fi == NULL) {             /* if no FI add one */
+   if (bsr->fi == NULL) {            /* if no FI add one */
       /* This is the first FileIndex item in the chain */
       bsr->fi = new_findex();
       bsr->JobId = JobId;
@@ -429,22 +438,22 @@ void add_findex_all(RBSR *bsr, uint32_t JobId)
    /* Walk down list of bsrs until we find the JobId */
    if (bsr->JobId != JobId) {
       for (nbsr=bsr->next; nbsr; nbsr=nbsr->next) {
-         if (nbsr->JobId == JobId) {
-            bsr = nbsr;
-            break;
-         }
+        if (nbsr->JobId == JobId) {
+           bsr = nbsr;
+           break;
+        }
       }
 
-      if (!nbsr) {                    /* Must add new JobId */
-         /* Add new JobId at end of chain */
-         for (nbsr=bsr; nbsr->next; nbsr=nbsr->next)
-            {  }
-         nbsr->next = new_bsr();
-         nbsr->next->JobId = JobId;
-         nbsr->next->fi = new_findex();
-         nbsr->next->fi->findex = 1;
-         nbsr->next->fi->findex2 = INT32_MAX;
-         return;
+      if (!nbsr) {                   /* Must add new JobId */
+        /* Add new JobId at end of chain */
+        for (nbsr=bsr; nbsr->next; nbsr=nbsr->next)
+           {  }
+        nbsr->next = new_bsr();
+        nbsr->next->JobId = JobId;
+        nbsr->next->fi = new_findex();
+        nbsr->next->fi->findex = 1;
+        nbsr->next->fi->findex2 = INT32_MAX;
+        return;
       }
    }
 
index e35a5a46fc3e64dc26d1e1b1c81d070fd7cadeba..117543028ea024671d63398c7cf6024d0230bb29 100644 (file)
@@ -9,9 +9,9 @@
  *
  *  Basic tasks done here:
  *    Open a message channel with the Storage daemon
- *      to authenticate ourself and to pass the JobId.
+ *     to authenticate ourself and to pass the JobId.
  *    Create a thread to interact with the Storage daemon
- *      who returns a job status and requests Catalog services, etc.
+ *     who returns a job status and requests Catalog services, etc.
  *
  *   Version $Id$
  */
@@ -53,7 +53,7 @@ static char OK_device[]  = "3000 OK use device device=%s\n";
 
 /* Storage Daemon requests */
 static char Job_start[]  = "3010 Job %127s start\n";
-static char Job_end[]    =
+static char Job_end[]   =
    "3099 Job %127s end JobStatus=%d JobFiles=%d JobBytes=%" lld "\n";
 
 /* Forward referenced functions */
@@ -64,13 +64,13 @@ extern "C" void *msg_thread(void *arg);
  * and perform authentication.
  */
 bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
-                              int max_retry_time, int verbose)
+                             int max_retry_time, int verbose)
 {
    BSOCK *sd;
    STORE *store;
 
    if (jcr->store_bsock) {
-      return true;                    /* already connected */
+      return true;                   /* already connected */
    }
    store = (STORE *)jcr->storage->first();
 
@@ -81,11 +81,11 @@ bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
       store->SDport);
    sd = bnet_connect(jcr, retry_interval, max_retry_time,
           _("Storage daemon"), store->address,
-          NULL, store->SDport, verbose);
+         NULL, store->SDport, verbose);
    if (sd == NULL) {
       return false;
    }
-   sd->res = (RES *)store;        /* save pointer to other end */
+   sd->res = (RES *)store;       /* save pointer to other end */
    jcr->store_bsock = sd;
 
    if (!authenticate_storage_daemon(jcr, store)) {
@@ -146,10 +146,10 @@ int start_storage_daemon_job(JCR *jcr, alist *store, int append)
       bstrncpy(jcr->fileset->MD5, "**Dummy**", sizeof(jcr->fileset->MD5));
    }
    bnet_fsend(sd, jobcmd, jcr->JobId, jcr->Job, jcr->job->hdr.name,
-              jcr->client->hdr.name, jcr->JobType, jcr->JobLevel,
-              jcr->fileset->hdr.name, !jcr->pool->catalog_files,
-              jcr->job->SpoolAttributes, jcr->fileset->MD5, jcr->spool_data, 
-              jcr->write_part_after_job, jcr->job->NewVolEachJob);
+             jcr->client->hdr.name, jcr->JobType, jcr->JobLevel,
+             jcr->fileset->hdr.name, !jcr->pool->catalog_files,
+             jcr->job->SpoolAttributes, jcr->fileset->MD5, jcr->spool_data, 
+             jcr->write_part_after_job, jcr->job->NewVolEachJob);
    Dmsg1(100, ">stored: %s\n", sd->msg);
    unbash_spaces(jcr->job->hdr.name);
    unbash_spaces(jcr->client->hdr.name);
@@ -157,17 +157,17 @@ int start_storage_daemon_job(JCR *jcr, alist *store, int append)
    if (bget_dirmsg(sd) > 0) {
        Dmsg1(100, "<stored: %s", sd->msg);
        if (sscanf(sd->msg, OKjob, &jcr->VolSessionId,
-                  &jcr->VolSessionTime, &auth_key) != 3) {
+                 &jcr->VolSessionTime, &auth_key) != 3) {
           Dmsg1(100, "BadJob=%s\n", sd->msg);
           Jmsg(jcr, M_FATAL, 0, _("Storage daemon rejected Job command: %s\n"), sd->msg);
-          return 0;
+         return 0;
        } else {
-          jcr->sd_auth_key = bstrdup(auth_key);
+         jcr->sd_auth_key = bstrdup(auth_key);
           Dmsg1(150, "sd_auth_key=%s\n", jcr->sd_auth_key);
        }
    } else {
       Jmsg(jcr, M_FATAL, 0, _("<stored: bad response to Job command: %s\n"),
-         bnet_strerror(sd));
+        bnet_strerror(sd));
       return 0;
    }
 
@@ -194,31 +194,31 @@ int start_storage_daemon_job(JCR *jcr, alist *store, int append)
       pm_strcpy(media_type, storage->media_type);
       bash_spaces(media_type);
       bnet_fsend(sd, use_storage, store_name.c_str(), media_type.c_str(), 
-                 pool_name.c_str(), pool_type.c_str(), append, copy, stripe);
+                pool_name.c_str(), pool_type.c_str(), append, copy, stripe);
 
       DEVICE *dev;
       /* Loop over alternative storage Devices until one is OK */
       foreach_alist(dev, storage->device) {
-         pm_strcpy(device_name, dev->hdr.name);
-         bash_spaces(device_name);
-         bnet_fsend(sd, use_device, device_name.c_str());
+        pm_strcpy(device_name, dev->hdr.name);
+        bash_spaces(device_name);
+        bnet_fsend(sd, use_device, device_name.c_str());
          Dmsg1(100, ">stored: %s", sd->msg);
       }
-      bnet_sig(sd, BNET_EOD);            /* end of Devices */
-      bnet_sig(sd, BNET_EOD);            /* end of Storages */
+      bnet_sig(sd, BNET_EOD);           /* end of Devices */
+      bnet_sig(sd, BNET_EOD);           /* end of Storages */
       if (bget_dirmsg(sd) > 0) {
          Dmsg1(100, "<stored: %s", sd->msg);
-         /* ****FIXME**** save actual device name */
-         ok = sscanf(sd->msg, OK_device, device_name.c_str()) == 1;
+        /* ****FIXME**** save actual device name */
+        ok = sscanf(sd->msg, OK_device, device_name.c_str()) == 1;
       } else {
-         POOL_MEM err_msg;
-         pm_strcpy(err_msg, sd->msg); /* save message */
+        POOL_MEM err_msg;
+        pm_strcpy(err_msg, sd->msg); /* save message */
          Jmsg(jcr, M_WARNING, 0, _("\n"
             "     Storage daemon didn't accept Device \"%s\" because:\n     %s"),
-            device_name.c_str(), err_msg.c_str()/* sd->msg */);
+           device_name.c_str(), err_msg.c_str()/* sd->msg */);
       }
 //    if (!ok) {
-//       break;
+//      break;
 //    }
 // }
    if (ok) {
@@ -238,7 +238,7 @@ int start_storage_daemon_message_thread(JCR *jcr)
    pthread_t thid;
 
    P(jcr->mutex);
-   jcr->use_count++;                  /* mark in use by msg thread */
+   jcr->use_count++;                 /* mark in use by msg thread */
    jcr->sd_msg_thread_done = false;
    jcr->SD_msg_chan = 0;
    V(jcr->mutex);
@@ -259,13 +259,13 @@ extern "C" void msg_thread_cleanup(void *arg)
 {
    JCR *jcr = (JCR *)arg;
    Dmsg0(200, "End msg_thread\n");
-   db_end_transaction(jcr, jcr->db);       /* terminate any open transaction */
+   db_end_transaction(jcr, jcr->db);      /* terminate any open transaction */
    P(jcr->mutex);
    jcr->sd_msg_thread_done = true;
    pthread_cond_broadcast(&jcr->term_wait); /* wakeup any waiting threads */
    jcr->SD_msg_chan = 0;
    V(jcr->mutex);
-   free_jcr(jcr);                     /* release jcr */
+   free_jcr(jcr);                    /* release jcr */
 }
 
 /*
@@ -294,20 +294,20 @@ extern "C" void *msg_thread(void *arg)
    while ((stat=bget_dirmsg(sd)) >= 0) {
       Dmsg1(200, "<stored: %s", sd->msg);
       if (sscanf(sd->msg, Job_start, &Job) == 1) {
-         continue;
+        continue;
       }
       if (sscanf(sd->msg, Job_end, &Job, &JobStatus, &JobFiles,
-                 &JobBytes) == 4) {
-         jcr->SDJobStatus = JobStatus; /* termination status */
-         jcr->SDJobFiles = JobFiles;
-         jcr->SDJobBytes = JobBytes;
-         break;
+                &JobBytes) == 4) {
+        jcr->SDJobStatus = JobStatus; /* termination status */
+        jcr->SDJobFiles = JobFiles;
+        jcr->SDJobBytes = JobBytes;
+        break;
       }
    }
    if (is_bnet_error(sd)) {
       jcr->SDJobStatus = JS_ErrorTerminated;
    }
-   pthread_cleanup_pop(1);
+   pthread_cleanup_pop(1);           /* remove and execute the handler */
    return NULL;
 }
 
@@ -328,11 +328,11 @@ void wait_for_storage_daemon_termination(JCR *jcr)
       Dmsg0(300, "I'm waiting for message thread termination.\n");
       pthread_cond_timedwait(&jcr->term_wait, &jcr->mutex, &timeout);
       if (job_canceled(jcr)) {
-         cancel_count++;
+        cancel_count++;
       }
       /* Give SD 30 seconds to clean up after cancel */
       if (cancel_count == 3) {
-         break;
+        break;
       }
    }
    V(jcr->mutex);
@@ -354,15 +354,15 @@ extern "C" void *device_thread(void *arg)
    for (i=0; i < MAX_TRIES; i++) {
       if (!connect_to_storage_daemon(jcr, 10, 30, 1)) {
          Dmsg0(000, "Failed connecting to SD.\n");
-         continue;
+        continue;
       }
       LockRes();
       foreach_res(dev, R_DEVICE) {
-         if (!update_device_res(jcr, dev)) {
+        if (!update_device_res(jcr, dev)) {
             Dmsg1(900, "Error updating device=%s\n", dev->hdr.name);
-         } else {
+        } else {
             Dmsg1(900, "Updated Device=%s\n", dev->hdr.name);
-         }
+        }
       }
       UnlockRes();
       bnet_close(jcr->store_bsock);
index 402d4561468055c8cb435543a0cbb804bfd6b926..012f52147240ddb0611a24a0af03d448ba24ff6a 100644 (file)
@@ -7,19 +7,14 @@
    Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -57,6 +52,7 @@ uint32_t write_bsr_file(UAContext *ua, RBSR *bsr);
 void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex);
 void add_findex_all(RBSR *bsr, uint32_t JobId);
 RBSR_FINDEX *new_findex();
+void make_unique_restore_filename(UAContext *ua, POOLMEM **fname);
 
 
 /* catreq.c */
@@ -72,7 +68,7 @@ int variable_expansion(JCR *jcr, char *inp, POOLMEM **exp);
 
 /* fd_cmds.c */
 extern int connect_to_file_daemon(JCR *jcr, int retry_interval,
-                                  int max_retry_time, int verbose);
+                                 int max_retry_time, int verbose);
 extern bool send_include_list(JCR *jcr);
 extern bool send_exclude_list(JCR *jcr);
 extern bool send_bootstrap_file(JCR *jcr);
@@ -80,7 +76,7 @@ extern bool send_level_command(JCR *jcr);
 extern int get_attributes_and_put_in_catalog(JCR *jcr);
 extern int get_attributes_and_compare_to_catalog(JCR *jcr, JobId_t JobId);
 extern int put_file_into_catalog(JCR *jcr, long file_index, char *fname,
-                          char *link, char *attr, int stream);
+                         char *link, char *attr, int stream);
 extern void get_level_since_time(JCR *jcr, char *since, int since_len);
 extern int send_run_before_and_after_commands(JCR *jcr);
 
@@ -114,7 +110,7 @@ extern void mount_request(JCR *jcr, BSOCK *bs, char *buf);
 
 /* msgchan.c */
 extern bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
-                              int max_retry_time, int verbose);
+                             int max_retry_time, int verbose);
 extern int start_storage_daemon_job(JCR *jcr, alist *store, int append);
 extern int start_storage_daemon_message_thread(JCR *jcr);
 extern int bget_dirmsg(BSOCK *bs);
@@ -176,28 +172,28 @@ JCR *new_control_jcr(const char *base_name, int job_type);
 void free_ua_context(UAContext *ua);
 
 /* ua_select.c */
-STORE   *select_storage_resource(UAContext *ua);
-JOB     *select_job_resource(UAContext *ua);
-JOB     *select_restore_job_resource(UAContext *ua);
-CLIENT  *select_client_resource(UAContext *ua);
+STORE  *select_storage_resource(UAContext *ua);
+JOB    *select_job_resource(UAContext *ua);
+JOB    *select_restore_job_resource(UAContext *ua);
+CLIENT *select_client_resource(UAContext *ua);
 FILESET *select_fileset_resource(UAContext *ua);
-int     select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr);
-int     select_media_dbr(UAContext *ua, MEDIA_DBR *mr);
-bool    select_pool_dbr(UAContext *ua, POOL_DBR *pr);
-int     select_client_dbr(UAContext *ua, CLIENT_DBR *cr);
-
-void    start_prompt(UAContext *ua, const char *msg);
-void    add_prompt(UAContext *ua, const char *prompt);
-int     do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt);
+int    select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr);
+int    select_media_dbr(UAContext *ua, MEDIA_DBR *mr);
+bool   select_pool_dbr(UAContext *ua, POOL_DBR *pr);
+int    select_client_dbr(UAContext *ua, CLIENT_DBR *cr);
+
+void   start_prompt(UAContext *ua, const char *msg);
+void   add_prompt(UAContext *ua, const char *prompt);
+int    do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt);
 CAT    *get_catalog_resource(UAContext *ua);
 STORE  *get_storage_resource(UAContext *ua, int use_default);
-int     get_media_type(UAContext *ua, char *MediaType, int max_media);
-bool    get_pool_dbr(UAContext *ua, POOL_DBR *pr);
-int     get_client_dbr(UAContext *ua, CLIENT_DBR *cr);
+int    get_media_type(UAContext *ua, char *MediaType, int max_media);
+bool   get_pool_dbr(UAContext *ua, POOL_DBR *pr);
+int    get_client_dbr(UAContext *ua, CLIENT_DBR *cr);
 POOL   *get_pool_resource(UAContext *ua);
 POOL   *select_pool_resource(UAContext *ua);
 CLIENT *get_client_resource(UAContext *ua);
-int     get_job_dbr(UAContext *ua, JOB_DBR *jr);
+int    get_job_dbr(UAContext *ua, JOB_DBR *jr);
 
 int find_arg_keyword(UAContext *ua, const char **list);
 int find_arg(UAContext *ua, const char *keyword);
index e9c4047400671a05ab127b7f390abe36ae276e12..c55b90e3b261824ab8767da8d2b3a7091e810b37 100644 (file)
  *
  *   Version $Id$
  */
-
 /*
    Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
+
 #include "bacula.h"
 #include "dird.h"
 
 /* Commands sent to File daemon */
 static char restorecmd[]   = "restore replace=%c prelinks=%d where=%s\n";
 static char storaddr[]     = "storage address=%s port=%d ssl=0\n";
-static char sessioncmd[]   = "session %s %ld %ld %ld %ld %ld %ld\n";
 
 /* Responses received from File daemon */
 static char OKrestore[]   = "2000 OK restore\n";
 static char OKstore[]     = "2000 OK storage\n";
-static char OKsession[]   = "2000 OK session\n";
 
 /*
  * Do a restore of the specified files
@@ -73,39 +66,10 @@ bool do_restore(JCR *jcr)
 
    Dmsg1(20, "RestoreJobId=%d\n", jcr->job->RestoreJobId);
 
-   /*
-    * The following code is kept temporarily for compatibility.
-    * It is the predecessor to the Bootstrap file.
-    *  DEPRECATED
-    */
    if (!jcr->RestoreBootstrap) {
-      /*
-       * Find Job Record for Files to be restored
-       */
-      if (jcr->RestoreJobId != 0) {
-        rjr.JobId = jcr->RestoreJobId;     /* specified by UA */
-      } else {
-        rjr.JobId = jcr->job->RestoreJobId; /* specified by Job Resource */
-      }
-      if (!db_get_job_record(jcr, jcr->db, &rjr)) {
-         Jmsg2(jcr, M_FATAL, 0, _("Cannot get job record id=%d %s"), rjr.JobId,
-           db_strerror(jcr->db));
-        restore_cleanup(jcr, JS_ErrorTerminated);
-        return false;
-      }
-
-      /*
-       * Now find the Volumes we will need for the Restore
-       */
-      jcr->VolumeName[0] = 0;
-      if (!db_get_job_volume_names(jcr, jcr->db, rjr.JobId, &jcr->VolumeName) ||
-          jcr->VolumeName[0] == 0) {
-         Jmsg(jcr, M_FATAL, 0, _("Cannot find Volume names for restore Job %d. %s"),
-           rjr.JobId, db_strerror(jcr->db));
-        restore_cleanup(jcr, JS_ErrorTerminated);
-        return false;
-      }
-      Dmsg1(20, "Got job Volume Names: %s\n", jcr->VolumeName);
+      Jmsg0(jcr, M_FATAL, 0, _("Cannot restore without bootstrap file.\n"));
+      restore_cleanup(jcr, JS_ErrorTerminated);
+      return false;
    }
 
 
@@ -188,24 +152,6 @@ bool do_restore(JCR *jcr)
       return false;
    }
 
-   /*
-    * The following code is deprecated
-    */
-   if (!jcr->RestoreBootstrap) {
-      /*
-       * Pass the VolSessionId, VolSessionTime, Start and
-       * end File and Blocks on the session command.
-       */
-      bnet_fsend(fd, sessioncmd,
-               jcr->VolumeName,
-               rjr.VolSessionId, rjr.VolSessionTime,
-               rjr.StartFile, rjr.EndFile, rjr.StartBlock,
-               rjr.EndBlock);
-      if (!response(jcr, fd, OKsession, "Session", DISPLAY_ERROR)) {
-        restore_cleanup(jcr, JS_ErrorTerminated);
-        return false;
-      }
-   }
 
    if (!send_run_before_and_after_commands(jcr)) {
       restore_cleanup(jcr, JS_ErrorTerminated);
@@ -269,6 +215,11 @@ void restore_cleanup(JCR *jcr, int TermCode)
    dequeue_messages(jcr);            /* display any queued messages */
    set_jcr_job_status(jcr, TermCode);
 
+   if (jcr->unlink_bsr && jcr->RestoreBootstrap) {
+      unlink(jcr->RestoreBootstrap);
+      jcr->unlink_bsr = false;
+   }
+
    update_job_end_record(jcr);
 
    msg_type = M_INFO;                /* by default INFO message */
index 3d889fe340347d0a4b023a244b7a290008172281..09190e1e2381d1471e5073c390dcfc63fa61642a 100644 (file)
@@ -9,22 +9,17 @@
  */
 
 /*
-   Copyright (C) 2000-2004 Kern Sibbald and John Walker
+   Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -262,6 +257,11 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
    for (i=1; i<ua->argc; i++) {
       /* List JOBS */
       if (strcasecmp(ua->argk[i], _("jobs")) == 0) {
+        /* Apply any limit */
+         j = find_arg_with_value(ua, _("limit"));
+        if (j >= 0) {
+           jr.limit = atoi(ua->argv[j]);
+        }
         db_list_job_records(ua->jcr, ua->db, &jr, prtit, ua, llist);
 
         /* List JOBTOTALS */
@@ -403,6 +403,8 @@ static int do_list_cmd(UAContext *ua, const char *cmd, e_list_type llist)
       } else if (strcasecmp(ua->argk[i], _("nextvol")) == 0 ||
                  strcasecmp(ua->argk[i], _("nextvolume")) == 0) {
         list_nextvol(ua);
+      } else if (strcasecmp(ua->argk[i], _("limit")) == 0) {
+        /* Ignore it */
       } else {
          bsendmsg(ua, _("Unknown list keyword: %s\n"), NPRT(ua->argk[i]));
       }
index 25438c3e1a00db20ba3092512cd78e7a9199fde5..2615ad2d2e53f259bae76fe279c2aa6d0672c361 100644 (file)
@@ -1,38 +1,33 @@
 /*
  *
  *   Bacula Director -- User Agent Database restore Command
- *      Creates a bootstrap file for restoring files and
- *      starts the restore job.
+ *     Creates a bootstrap file for restoring files and
+ *     starts the restore job.
  *
- *      Tree handling routines split into ua_tree.c July MMIII.
- *      BSR (bootstrap record) handling routines split into
- *        bsr.c July MMIII
+ *     Tree handling routines split into ua_tree.c July MMIII.
+ *     BSR (bootstrap record) handling routines split into
+ *       bsr.c July MMIII
  *
  *     Kern Sibbald, July MMII
  *
  *   Version $Id$
  */
-
 /*
    Copyright (C) 2002-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
+
 #include "bacula.h"
 #include "dird.h"
 
 extern void print_bsr(UAContext *ua, RBSR *bsr);
 
 /* Imported variables */
-extern char *uar_list_jobs,      *uar_file,        *uar_sel_files;
-extern char *uar_del_temp,       *uar_del_temp1,   *uar_create_temp;
-extern char *uar_create_temp1,   *uar_last_full,   *uar_full;
-extern char *uar_inc,            *uar_list_temp,   *uar_sel_jobid_temp;
+extern char *uar_list_jobs,     *uar_file,        *uar_sel_files;
+extern char *uar_del_temp,      *uar_del_temp1,   *uar_create_temp;
+extern char *uar_create_temp1,  *uar_last_full,   *uar_full;
+extern char *uar_inc,           *uar_list_temp,   *uar_sel_jobid_temp;
 extern char *uar_sel_all_temp1,  *uar_sel_fileset, *uar_mediatype;
-extern char *uar_jobid_fileindex, *uar_dif,        *uar_sel_all_temp;
-extern char *uar_count_files,     *uar_jobids_fileindex;
+extern char *uar_jobid_fileindex, *uar_dif,       *uar_sel_all_temp;
+extern char *uar_count_files,    *uar_jobids_fileindex;
 extern char *uar_jobid_fileindex_from_dir;
 
 
 struct NAME_LIST {
-   char **name;                       /* list of names */
-   int num_ids;                       /* ids stored */
-   int max_ids;                       /* size of array */
-   int num_del;                       /* number deleted */
-   int tot_ids;                       /* total to process */
+   char **name;                      /* list of names */
+   int num_ids;                      /* ids stored */
+   int max_ids;                      /* size of array */
+   int num_del;                      /* number deleted */
+   int tot_ids;                      /* total to process */
 };
 
 
@@ -67,7 +62,7 @@ struct RESTORE_CTX {
    uint32_t JobId;
    char ClientName[MAX_NAME_LENGTH];
    char last_jobid[20];
-   POOLMEM *JobIds;                   /* User entered string of JobIds */
+   POOLMEM *JobIds;                  /* User entered string of JobIds */
    STORE  *store;
    JOB *restore_job;
    POOL *pool;
@@ -75,13 +70,13 @@ struct RESTORE_CTX {
    uint32_t selected_files;
    char *where;
    RBSR *bsr;
-   POOLMEM *fname;                    /* filename only */
-   POOLMEM *path;                     /* path only */
+   POOLMEM *fname;                   /* filename only */
+   POOLMEM *path;                    /* path only */
    POOLMEM *query;
-   int fnl;                           /* filename length */
-   int pnl;                           /* path length */
+   int fnl;                          /* filename length */
+   int pnl;                          /* path length */
    bool found;
-   bool all;                          /* mark all as default */
+   bool all;                         /* mark all as default */
    NAME_LIST name_list;
 };
 
@@ -105,9 +100,9 @@ static void free_rx(RESTORE_CTX *rx);
 static void split_path_and_filename(RESTORE_CTX *rx, char *fname);
 static int jobid_fileindex_handler(void *ctx, int num_fields, char **row);
 static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *file,
-                                         char *date);
+                                        char *date);
 static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *dir,
-                                        char *date);
+                                       char *date);
 static void insert_one_file_or_dir(UAContext *ua, RESTORE_CTX *rx, char *date, bool dir);
 static int get_client_name(UAContext *ua, RESTORE_CTX *rx);
 static int get_date(UAContext *ua, char *date, int date_len);
@@ -119,7 +114,7 @@ static int count_handler(void *ctx, int num_fields, char **row);
  */
 int restore_cmd(UAContext *ua, const char *cmd)
 {
-   RESTORE_CTX rx;                    /* restore context */
+   RESTORE_CTX rx;                   /* restore context */
    JOB *job;
    int i;
 
@@ -143,10 +138,10 @@ int restore_cmd(UAContext *ua, const char *cmd)
    LockRes();
    foreach_res(job, R_JOB) {
       if (job->JobType == JT_RESTORE) {
-         if (!rx.restore_job) {
-            rx.restore_job = job;
-         }
-         rx.restore_jobs++;
+        if (!rx.restore_job) {
+           rx.restore_job = job;
+        }
+        rx.restore_jobs++;
       }
    }
    UnlockRes();
@@ -164,26 +159,26 @@ int restore_cmd(UAContext *ua, const char *cmd)
     *  add_findex()
     */
    switch (user_select_jobids_or_files(ua, &rx)) {
-   case 0:                            /* error */
+   case 0:                           /* error */
       goto bail_out;
-   case 1:                            /* selected by jobid */
+   case 1:                           /* selected by jobid */
       if (!build_directory_tree(ua, &rx)) {
          bsendmsg(ua, _("Restore not done.\n"));
-         goto bail_out;
+        goto bail_out;
       }
       break;
-   case 2:                            /* selected by filename, no tree needed */
+   case 2:                           /* selected by filename, no tree needed */
       break;
    }
 
    if (rx.bsr->JobId) {
-      if (!complete_bsr(ua, rx.bsr)) {   /* find Vol, SessId, SessTime from JobIds */
+      if (!complete_bsr(ua, rx.bsr)) {  /* find Vol, SessId, SessTime from JobIds */
          bsendmsg(ua, _("Unable to construct a valid BSR. Cannot continue.\n"));
-         goto bail_out;
+        goto bail_out;
       }
       if (!(rx.selected_files = write_bsr_file(ua, rx.bsr))) {
          bsendmsg(ua, _("No files selected to be restored.\n"));
-         goto bail_out;
+        goto bail_out;
       }
       bsendmsg(ua, _("\n%u file%s selected to be restored.\n\n"), rx.selected_files,
          rx.selected_files==1?"":"s");
@@ -208,19 +203,22 @@ int restore_cmd(UAContext *ua, const char *cmd)
    }
 
    /* Build run command */
+   POOLMEM *fname = get_pool_memory(PM_MESSAGE);
+   make_unique_restore_filename(ua, &fname);
    if (rx.where) {
       Mmsg(ua->cmd,
-          "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s/restore.bsr\""
+          "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s\""
           " where=\"%s\" files=%d catalog=\"%s\"",
           job->hdr.name, rx.ClientName, rx.store?rx.store->hdr.name:"",
-          working_directory, rx.where, rx.selected_files, ua->catalog->hdr.name);
+         fname, rx.where, rx.selected_files, ua->catalog->hdr.name);
    } else {
       Mmsg(ua->cmd,
-          "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s/restore.bsr\""
+          "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s\""
           " files=%d catalog=\"%s\"",
           job->hdr.name, rx.ClientName, rx.store?rx.store->hdr.name:"",
-          working_directory, rx.selected_files, ua->catalog->hdr.name);
+         fname, rx.selected_files, ua->catalog->hdr.name);
    }
+   free_pool_memory(fname);
    if (find_arg(ua, _("yes")) > 0) {
       pm_strcat(ua->cmd, " yes");    /* pass it on to the run command */
    }
@@ -267,12 +265,12 @@ static int get_client_name(UAContext *ua, RESTORE_CTX *rx)
       /* try command line argument */
       int i = find_arg_with_value(ua, _("client"));
       if (i >= 0) {
-         bstrncpy(rx->ClientName, ua->argv[i], sizeof(rx->ClientName));
-         return 1;
+        bstrncpy(rx->ClientName, ua->argv[i], sizeof(rx->ClientName));
+        return 1;
       }
       memset(&cr, 0, sizeof(cr));
       if (!get_client_dbr(ua, &cr)) {
-         return 0;
+        return 0;
       }
       bstrncpy(rx->ClientName, cr.Name, sizeof(rx->ClientName));
    }
@@ -285,8 +283,8 @@ static int get_client_name(UAContext *ua, RESTORE_CTX *rx)
  *  select which files are to be restored.
  *
  *  Returns:  2  if filename list made
- *            1  if jobid list made
- *            0  on error
+ *           1  if jobid list made
+ *           0  on error
  */
 static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
 {
@@ -329,7 +327,8 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
       "fileset",   /* 10 */
       "where",     /* 11 */
       "yes",       /* 12 */
-      "done",      /* 13 */
+      "bootstrap", /* 13 */
+      "done",      /* 14 */
       NULL
    };
 
@@ -337,86 +336,86 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
 
    for (i=1; i<ua->argc; i++) {       /* loop through arguments */
       bool found_kw = false;
-      for (j=0; kw[j]; j++) {         /* loop through keywords */
-         if (strcasecmp(kw[j], ua->argk[i]) == 0) {
-            found_kw = true;
-            break;
-         }
+      for (j=0; kw[j]; j++) {        /* loop through keywords */
+        if (strcasecmp(kw[j], ua->argk[i]) == 0) {
+           found_kw = true;
+           break;
+        }
       }
       if (!found_kw) {
          bsendmsg(ua, _("Unknown keyword: %s\n"), ua->argk[i]);
-         return 0;
+        return 0;
       }
       /* Found keyword in kw[] list, process it */
       switch (j) {
-      case 0:                            /* jobid */
-         if (*rx->JobIds != 0) {
+      case 0:                           /* jobid */
+        if (*rx->JobIds != 0) {
             pm_strcat(rx->JobIds, ",");
-         }
-         pm_strcat(rx->JobIds, ua->argv[i]);
-         done = true;
-         break;
-      case 1:                            /* current */
-         bstrutime(date, sizeof(date), time(NULL));
-         have_date = true;
-         break;
-      case 2:                            /* before */
-         if (str_to_utime(ua->argv[i]) == 0) {
+        }
+        pm_strcat(rx->JobIds, ua->argv[i]);
+        done = true;
+        break;
+      case 1:                           /* current */
+        bstrutime(date, sizeof(date), time(NULL));
+        have_date = true;
+        break;
+      case 2:                           /* before */
+        if (str_to_utime(ua->argv[i]) == 0) {
             bsendmsg(ua, _("Improper date format: %s\n"), ua->argv[i]);
-            return 0;
-         }
-         bstrncpy(date, ua->argv[i], sizeof(date));
-         have_date = true;
-         break;
-      case 3:                            /* file */
-      case 4:                            /* dir */
-         if (!have_date) {
-            bstrutime(date, sizeof(date), time(NULL));
-         }
-         if (!get_client_name(ua, rx)) {
-            return 0;
-         }
-         pm_strcpy(ua->cmd, ua->argv[i]);
-         insert_one_file_or_dir(ua, rx, date, j==4);
-         if (rx->name_list.num_ids) {
-            /* Check MediaType and select storage that corresponds */
-            get_storage_from_mediatype(ua, &rx->name_list, rx);
-            done = true;
-         }
-         break;
-      case 5:                            /* select */
-         if (!have_date) {
-            bstrutime(date, sizeof(date), time(NULL));
-         }
-         if (!select_backups_before_date(ua, rx, date)) {
-            return 0;
-         }
-         done = true;
-         break;
-      case 6:                            /* pool specified */
-         rx->pool = (POOL *)GetResWithName(R_POOL, ua->argv[i]);
-         if (!rx->pool) {
+           return 0;
+        }
+        bstrncpy(date, ua->argv[i], sizeof(date));
+        have_date = true;
+        break;
+      case 3:                           /* file */
+      case 4:                           /* dir */
+        if (!have_date) {
+           bstrutime(date, sizeof(date), time(NULL));
+        }
+        if (!get_client_name(ua, rx)) {
+           return 0;
+        }
+        pm_strcpy(ua->cmd, ua->argv[i]);
+        insert_one_file_or_dir(ua, rx, date, j==4);
+        if (rx->name_list.num_ids) {
+           /* Check MediaType and select storage that corresponds */
+           get_storage_from_mediatype(ua, &rx->name_list, rx);
+           done = true;
+        }
+        break;
+      case 5:                           /* select */
+        if (!have_date) {
+           bstrutime(date, sizeof(date), time(NULL));
+        }
+        if (!select_backups_before_date(ua, rx, date)) {
+           return 0;
+        }
+        done = true;
+        break;
+      case 6:                           /* pool specified */
+        rx->pool = (POOL *)GetResWithName(R_POOL, ua->argv[i]);
+        if (!rx->pool) {
             bsendmsg(ua, _("Error: Pool resource \"%s\" does not exist.\n"), ua->argv[i]);
-            return 0;
-         }
-         if (!acl_access_ok(ua, Pool_ACL, ua->argv[i])) {
-            rx->pool = NULL;
+           return 0;
+        }
+        if (!acl_access_ok(ua, Pool_ACL, ua->argv[i])) {
+           rx->pool = NULL;
             bsendmsg(ua, _("Error: Pool resource \"%s\" access not allowed.\n"), ua->argv[i]);
-            return 0;
-         }
-         break;
-      case 7:                         /* all specified */
-         rx->all = true;
-         break;
+           return 0;
+        }
+        break;
+      case 7:                        /* all specified */
+        rx->all = true;
+        break;
       /*
        * All keywords 7 or greater are ignored or handled by a select prompt
        */
       default:
-         break;
+        break;
       }
    }
    if (rx->name_list.num_ids) {
-      return 2;                       /* filename list made */
+      return 2;                      /* filename list made */
    }
 
    if (!done) {
@@ -434,175 +433,175 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
 
       start_prompt(ua, _("To select the JobIds, you have the following choices:\n"));
       for (int i=0; list[i]; i++) {
-         add_prompt(ua, list[i]);
+        add_prompt(ua, list[i]);
       }
       done = true;
       switch (do_prompt(ua, "", _("Select item: "), NULL, 0)) {
-      case -1:                        /* error */
-         return 0;
-      case 0:                         /* list last 20 Jobs run */
-         gui_save = ua->jcr->gui;
-         ua->jcr->gui = true;
-         db_list_sql_query(ua->jcr, ua->db, uar_list_jobs, prtit, ua, 1, HORZ_LIST);
-         ua->jcr->gui = gui_save;
-         done = false;
-         break;
-      case 1:                         /* list where a file is saved */
-         if (!get_client_name(ua, rx)) {
-            return 0;
-         }
+      case -1:                       /* error */
+        return 0;
+      case 0:                        /* list last 20 Jobs run */
+        gui_save = ua->jcr->gui;
+        ua->jcr->gui = true;
+        db_list_sql_query(ua->jcr, ua->db, uar_list_jobs, prtit, ua, 1, HORZ_LIST);
+        ua->jcr->gui = gui_save;
+        done = false;
+        break;
+      case 1:                        /* list where a file is saved */
+        if (!get_client_name(ua, rx)) {
+           return 0;
+        }
          if (!get_cmd(ua, _("Enter Filename (no path):"))) {
-            return 0;
-         }
-         len = strlen(ua->cmd);
-         fname = (char *)malloc(len * 2 + 1);
-         db_escape_string(fname, ua->cmd, len);
-         Mmsg(rx->query, uar_file, rx->ClientName, fname);
-         free(fname);
-         gui_save = ua->jcr->gui;
-         ua->jcr->gui = true;
-         db_list_sql_query(ua->jcr, ua->db, rx->query, prtit, ua, 1, HORZ_LIST);
-         ua->jcr->gui = gui_save;
-         done = false;
-         break;
-      case 2:                         /* enter a list of JobIds */
+           return 0;
+        }
+        len = strlen(ua->cmd);
+        fname = (char *)malloc(len * 2 + 1);
+        db_escape_string(fname, ua->cmd, len);
+        Mmsg(rx->query, uar_file, rx->ClientName, fname);
+        free(fname);
+        gui_save = ua->jcr->gui;
+        ua->jcr->gui = true;
+        db_list_sql_query(ua->jcr, ua->db, rx->query, prtit, ua, 1, HORZ_LIST);
+        ua->jcr->gui = gui_save;
+        done = false;
+        break;
+      case 2:                        /* enter a list of JobIds */
          if (!get_cmd(ua, _("Enter JobId(s), comma separated, to restore: "))) {
-            return 0;
-         }
-         pm_strcpy(rx->JobIds, ua->cmd);
-         break;
-      case 3:                         /* Enter an SQL list command */
+           return 0;
+        }
+        pm_strcpy(rx->JobIds, ua->cmd);
+        break;
+      case 3:                        /* Enter an SQL list command */
          if (!get_cmd(ua, _("Enter SQL list command: "))) {
-            return 0;
-         }
-         gui_save = ua->jcr->gui;
-         ua->jcr->gui = true;
-         db_list_sql_query(ua->jcr, ua->db, ua->cmd, prtit, ua, 1, HORZ_LIST);
-         ua->jcr->gui = gui_save;
-         done = false;
-         break;
-      case 4:                         /* Select the most recent backups */
-         bstrutime(date, sizeof(date), time(NULL));
-         if (!select_backups_before_date(ua, rx, date)) {
-            return 0;
-         }
-         break;
-      case 5:                         /* select backup at specified time */
-         if (!get_date(ua, date, sizeof(date))) {
-            return 0;
-         }
-         if (!select_backups_before_date(ua, rx, date)) {
-            return 0;
-         }
-         break;
-      case 6:                         /* Enter files */
-         bstrutime(date, sizeof(date), time(NULL));
-         if (!get_client_name(ua, rx)) {
-            return 0;
-         }
+           return 0;
+        }
+        gui_save = ua->jcr->gui;
+        ua->jcr->gui = true;
+        db_list_sql_query(ua->jcr, ua->db, ua->cmd, prtit, ua, 1, HORZ_LIST);
+        ua->jcr->gui = gui_save;
+        done = false;
+        break;
+      case 4:                        /* Select the most recent backups */
+        bstrutime(date, sizeof(date), time(NULL));
+        if (!select_backups_before_date(ua, rx, date)) {
+           return 0;
+        }
+        break;
+      case 5:                        /* select backup at specified time */
+        if (!get_date(ua, date, sizeof(date))) {
+           return 0;
+        }
+        if (!select_backups_before_date(ua, rx, date)) {
+           return 0;
+        }
+        break;
+      case 6:                        /* Enter files */
+        bstrutime(date, sizeof(date), time(NULL));
+        if (!get_client_name(ua, rx)) {
+           return 0;
+        }
          bsendmsg(ua, _("Enter file names with paths, or < to enter a filename\n"
                         "containg a list of file names with paths, and terminate\n"
                         "them with a blank line.\n"));
-         for ( ;; ) {
+        for ( ;; ) {
             if (!get_cmd(ua, _("Enter full filename: "))) {
-               return 0;
-            }
-            len = strlen(ua->cmd);
-            if (len == 0) {
-               break;
-            }
-            insert_one_file_or_dir(ua, rx, date, false);
-         }
-         /* Check MediaType and select storage that corresponds */
-         if (rx->name_list.num_ids) {
-            get_storage_from_mediatype(ua, &rx->name_list, rx);
-         }
-         return 2;
-       case 7:                        /* enter files backed up before specified time */
-         if (!get_date(ua, date, sizeof(date))) {
-            return 0;
-         }
-         if (!get_client_name(ua, rx)) {
-            return 0;
-         }
+              return 0;
+           }
+           len = strlen(ua->cmd);
+           if (len == 0) {
+              break;
+           }
+           insert_one_file_or_dir(ua, rx, date, false);
+        }
+        /* Check MediaType and select storage that corresponds */
+        if (rx->name_list.num_ids) {
+           get_storage_from_mediatype(ua, &rx->name_list, rx);
+        }
+        return 2;
+       case 7:                       /* enter files backed up before specified time */
+        if (!get_date(ua, date, sizeof(date))) {
+           return 0;
+        }
+        if (!get_client_name(ua, rx)) {
+           return 0;
+        }
          bsendmsg(ua, _("Enter file names with paths, or < to enter a filename\n"
                         "containg a list of file names with paths, and terminate\n"
                         "them with a blank line.\n"));
-         for ( ;; ) {
+        for ( ;; ) {
             if (!get_cmd(ua, _("Enter full filename: "))) {
-               return 0;
-            }
-            len = strlen(ua->cmd);
-            if (len == 0) {
-               break;
-            }
-            insert_one_file_or_dir(ua, rx, date, false);
-         }
-         /* Check MediaType and select storage that corresponds */
-         if (rx->name_list.num_ids) {
-            get_storage_from_mediatype(ua, &rx->name_list, rx);
-         }
-         return 2;
-
-      case 8:                         /* Find JobIds for current backup */
-         bstrutime(date, sizeof(date), time(NULL));
-         if (!select_backups_before_date(ua, rx, date)) {
-            return 0;
-         }
-         done = false;
-         break;
-
-      case 9:                         /* Find JobIds for give date */
-         if (!get_date(ua, date, sizeof(date))) {
-            return 0;
-         }
-         if (!select_backups_before_date(ua, rx, date)) {
-            return 0;
-         }
-         done = false;
-         break;
-
-      case 10:                        /* Enter directories */
-         if (*rx->JobIds != 0) {
+              return 0;
+           }
+           len = strlen(ua->cmd);
+           if (len == 0) {
+              break;
+           }
+           insert_one_file_or_dir(ua, rx, date, false);
+        }
+        /* Check MediaType and select storage that corresponds */
+        if (rx->name_list.num_ids) {
+           get_storage_from_mediatype(ua, &rx->name_list, rx);
+        }
+        return 2;
+
+      case 8:                        /* Find JobIds for current backup */
+        bstrutime(date, sizeof(date), time(NULL));
+        if (!select_backups_before_date(ua, rx, date)) {
+           return 0;
+        }
+        done = false;
+        break;
+
+      case 9:                        /* Find JobIds for give date */
+        if (!get_date(ua, date, sizeof(date))) {
+           return 0;
+        }
+        if (!select_backups_before_date(ua, rx, date)) {
+           return 0;
+        }
+        done = false;
+        break;
+
+      case 10:                       /* Enter directories */
+        if (*rx->JobIds != 0) {
             bsendmsg(ua, _("You have already seleted the following JobIds: %s\n"),
-               rx->JobIds);
+              rx->JobIds);
          } else if (get_cmd(ua, _("Enter JobId(s), comma separated, to restore: "))) {
-            if (*rx->JobIds != 0 && *ua->cmd) {
+           if (*rx->JobIds != 0 && *ua->cmd) {
                pm_strcat(rx->JobIds, ",");
-            }
-            pm_strcat(rx->JobIds, ua->cmd);
-         }
+           }
+           pm_strcat(rx->JobIds, ua->cmd);
+        }
          if (*rx->JobIds == 0 || *rx->JobIds == '.') {
-            return 0;                 /* nothing entered, return */
-         }
-         bstrutime(date, sizeof(date), time(NULL));
-         if (!get_client_name(ua, rx)) {
-            return 0;
-         }
+           return 0;                 /* nothing entered, return */
+        }
+        bstrutime(date, sizeof(date), time(NULL));
+        if (!get_client_name(ua, rx)) {
+           return 0;
+        }
          bsendmsg(ua, _("Enter directory names with a trailing /, or < to enter a filename\n"
                         "containg a list of directories and terminate\n"
                         "them with a blank line.\n"));
-         for ( ;; ) {
+        for ( ;; ) {
             if (!get_cmd(ua, _("Enter directory name: "))) {
-               return 0;
-            }
-            len = strlen(ua->cmd);
-            if (len == 0) {
-               break;
-            }
+              return 0;
+           }
+           len = strlen(ua->cmd);
+           if (len == 0) {
+              break;
+           }
             if (ua->cmd[len-1] != '/') {
                strcat(ua->cmd, "/");
-            }
-            insert_one_file_or_dir(ua, rx, date, true);
-         }
-         /* Check MediaType and select storage that corresponds */
-         if (rx->name_list.num_ids) {
-            get_storage_from_mediatype(ua, &rx->name_list, rx);
-         }
-         return 2;
-
-      case 11:                        /* Cancel or quit */
-         return 0;
+           }
+           insert_one_file_or_dir(ua, rx, date, true);
+        }
+        /* Check MediaType and select storage that corresponds */
+        if (rx->name_list.num_ids) {
+           get_storage_from_mediatype(ua, &rx->name_list, rx);
+        }
+        return 2;
+
+      case 11:                       /* Cancel or quit */
+        return 0;
       }
    }
 
@@ -620,25 +619,25 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
       int stat = get_next_jobid_from_list(&p, &JobId);
       if (stat < 0) {
          bsendmsg(ua, _("Invalid JobId in list.\n"));
-         return 0;
+        return 0;
       }
       if (stat == 0) {
-         break;
+        break;
       }
       if (jr.JobId == JobId) {
-         continue;                    /* duplicate of last JobId */
+        continue;                    /* duplicate of last JobId */
       }
       jr.JobId = JobId;
       if (!db_get_job_record(ua->jcr, ua->db, &jr)) {
-         char ed1[50];
+        char ed1[50];
          bsendmsg(ua, _("Unable to get Job record for JobId=%s: ERR=%s\n"),
-            edit_int64(JobId, ed1), db_strerror(ua->db));
-         return 0;
+           edit_int64(JobId, ed1), db_strerror(ua->db));
+        return 0;
       }
       if (!acl_access_ok(ua, Job_ACL, jr.Name)) {
          bsendmsg(ua, _("No authorization. Job \"%s\" not selected.\n"),
-            jr.Name);
-         continue;
+           jr.Name);
+        continue;
       }
       rx->TotalFiles += jr.JobFiles;
    }
@@ -654,10 +653,10 @@ static int get_date(UAContext *ua, char *date, int date_len)
                   "BEFORE the date you specify below.\n\n"));
    for ( ;; ) {
       if (!get_cmd(ua, _("Enter date as YYYY-MM-DD HH:MM:SS :"))) {
-         return 0;
+        return 0;
       }
       if (str_to_utime(ua->cmd) != 0) {
-         break;
+        break;
       }
       bsendmsg(ua, _("Improper date format.\n"));
    }
@@ -679,30 +678,30 @@ static void insert_one_file_or_dir(UAContext *ua, RESTORE_CTX *rx, char *date, b
    case '<':
       p++;
       if ((ffd = fopen(p, "r")) == NULL) {
-         berrno be;
+        berrno be;
          bsendmsg(ua, _("Cannot open file %s: ERR=%s\n"),
-            p, be.strerror());
-         break;
+           p, be.strerror());
+        break;
       }
       while (fgets(file, sizeof(file), ffd)) {
-         line++;
-         if (dir) {
-            if (!insert_dir_into_findex_list(ua, rx, file, date)) {
+        line++;
+        if (dir) {
+           if (!insert_dir_into_findex_list(ua, rx, file, date)) {
                bsendmsg(ua, _("Error occurred on line %d of %s\n"), line, p);
-            }
-         } else {
-            if (!insert_file_into_findex_list(ua, rx, file, date)) {
+           }
+        } else {
+           if (!insert_file_into_findex_list(ua, rx, file, date)) {
                bsendmsg(ua, _("Error occurred on line %d of %s\n"), line, p);
-            }
-         }
+           }
+        }
       }
       fclose(ffd);
       break;
    default:
       if (dir) {
-         insert_dir_into_findex_list(ua, rx, ua->cmd, date);
+        insert_dir_into_findex_list(ua, rx, ua->cmd, date);
       } else {
-         insert_file_into_findex_list(ua, rx, ua->cmd, date);
+        insert_file_into_findex_list(ua, rx, ua->cmd, date);
       }
       break;
    }
@@ -714,7 +713,7 @@ static void insert_one_file_or_dir(UAContext *ua, RESTORE_CTX *rx, char *date, b
  *   and FileIndex, then insert them into the findex list.
  */
 static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *file,
-                                        char *date)
+                                       char *date)
 {
    char ed1[50];
 
@@ -722,16 +721,16 @@ static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *f
    split_path_and_filename(rx, file);
    if (*rx->JobIds == 0) {
       Mmsg(rx->query, uar_jobid_fileindex, date, rx->path, rx->fname, 
-           rx->ClientName);
+          rx->ClientName);
    } else {
       Mmsg(rx->query, uar_jobids_fileindex, rx->JobIds, date,
-           rx->path, rx->fname, rx->ClientName);
+          rx->path, rx->fname, rx->ClientName);
    }
    rx->found = false;
    /* Find and insert jobid and File Index */
    if (!db_sql_query(ua->db, rx->query, jobid_fileindex_handler, (void *)rx)) {
       bsendmsg(ua, _("Query failed: %s. ERR=%s\n"),
-         rx->query, db_strerror(ua->db));
+        rx->query, db_strerror(ua->db));
    }
    if (!rx->found) {
       bsendmsg(ua, _("No database record found for: %s\n"), file);
@@ -753,7 +752,7 @@ static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *f
  * to get the JobId and FileIndexes of all files in that directory.
  */
 static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *dir,
-                                        char *date)
+                                       char *date)
 {
    char ed1[50];
 
@@ -763,13 +762,13 @@ static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *di
       return false;
    } else {
       Mmsg(rx->query, uar_jobid_fileindex_from_dir, rx->JobIds, 
-           dir, rx->ClientName);
+          dir, rx->ClientName);
    }
    rx->found = false;
    /* Find and insert jobid and File Index */
    if (!db_sql_query(ua->db, rx->query, jobid_fileindex_handler, (void *)rx)) {
       bsendmsg(ua, _("Query failed: %s. ERR=%s\n"),
-         rx->query, db_strerror(ua->db));
+        rx->query, db_strerror(ua->db));
    }
    if (!rx->found) {
       bsendmsg(ua, _("No database record found for: %s\n"), dir);
@@ -799,12 +798,12 @@ static void split_path_and_filename(RESTORE_CTX *rx, char *name)
     */
    for (p=f=name; *p; p++) {
       if (*p == '/') {
-         f = p;                       /* set pos of last slash */
+        f = p;                       /* set pos of last slash */
       }
    }
    if (*f == '/') {                   /* did we find a slash? */
-      f++;                            /* yes, point to filename */
-   } else {                           /* no, whole thing must be path name */
+      f++;                           /* yes, point to filename */
+   } else {                          /* no, whole thing must be path name */
       f = p;
    }
 
@@ -816,7 +815,7 @@ static void split_path_and_filename(RESTORE_CTX *rx, char *name)
    rx->fnl = p - f;
    if (rx->fnl > 0) {
       rx->fname = check_pool_memory_size(rx->fname, rx->fnl+1);
-      memcpy(rx->fname, f, rx->fnl);    /* copy filename */
+      memcpy(rx->fname, f, rx->fnl);   /* copy filename */
       rx->fname[rx->fnl] = 0;
    } else {
       rx->fname[0] = 0;
@@ -866,20 +865,20 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx)
          bsendmsg(ua, "%s\n", db_strerror(ua->db));
       }
       if (rx->found) {
-         /* Add about 25% more than this job for over estimate */
-         tree.FileEstimate = rx->JobId + (rx->JobId >> 2);
-         tree.DeltaCount = rx->JobId/50; /* print 50 ticks */
+        /* Add about 25% more than this job for over estimate */
+        tree.FileEstimate = rx->JobId + (rx->JobId >> 2);
+        tree.DeltaCount = rx->JobId/50; /* print 50 ticks */
       }
    }
    for (p=rx->JobIds; get_next_jobid_from_list(&p, &JobId) > 0; ) {
       char ed1[50];
 
       if (JobId == last_JobId) {
-         continue;                    /* eliminate duplicate JobIds */
+        continue;                    /* eliminate duplicate JobIds */
       }
       last_JobId = JobId;
       bsendmsg(ua, _("\nBuilding directory tree for JobId %s ...  "), 
-         edit_int64(JobId, ed1));
+        edit_int64(JobId, ed1));
       items++;
       /*
        * Find files for this JobId and insert them in the tree
@@ -900,16 +899,16 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx)
       bsendmsg(ua, "\nThere were no files inserted into the tree, so file selection\n"
          "is not possible.Most likely your retention policy pruned the files\n");
       if (!get_yesno(ua, _("\nDo you want to restore all the files? (yes|no): "))) {
-         OK = false;
+        OK = false;
       } else {
-         last_JobId = 0;
-         for (p=rx->JobIds; get_next_jobid_from_list(&p, &JobId) > 0; ) {
-             if (JobId == last_JobId) {
-                continue;                    /* eliminate duplicate JobIds */
-             }
-             add_findex_all(rx->bsr, JobId);
-          }
-          OK = true;
+        last_JobId = 0;
+        for (p=rx->JobIds; get_next_jobid_from_list(&p, &JobId) > 0; ) {
+            if (JobId == last_JobId) {
+               continue;                    /* eliminate duplicate JobIds */
+            }
+            add_findex_all(rx->bsr, JobId);
+         }
+         OK = true;
       }
    } else {
       char ec1[50];
@@ -921,8 +920,8 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx)
       get_storage_from_mediatype(ua, &rx->name_list, rx);
 
       if (find_arg(ua, _("done")) < 0) {
-         /* Let the user interact in selecting which files to restore */
-         OK = user_select_files_from_tree(&tree);
+        /* Let the user interact in selecting which files to restore */
+        OK = user_select_files_from_tree(&tree);
       }
 
       /*
@@ -930,20 +929,20 @@ static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx)
        *  extracted making a bootstrap file.
        */
       if (OK) {
-         for (TREE_NODE *node=first_tree_node(tree.root); node; node=next_tree_node(node)) {
+        for (TREE_NODE *node=first_tree_node(tree.root); node; node=next_tree_node(node)) {
             Dmsg2(400, "FI=%d node=0x%x\n", node->FileIndex, node);
-            if (node->extract || node->extract_dir) {
+           if (node->extract || node->extract_dir) {
                Dmsg2(400, "type=%d FI=%d\n", node->type, node->FileIndex);
-               add_findex(rx->bsr, node->JobId, node->FileIndex);
-               if (node->extract && node->type != TN_NEWDIR) {
-                  rx->selected_files++;  /* count only saved files */
-               }
-            }
-         }
+              add_findex(rx->bsr, node->JobId, node->FileIndex);
+              if (node->extract && node->type != TN_NEWDIR) {
+                 rx->selected_files++;  /* count only saved files */
+              }
+           }
+        }
       }
    }
 
-   free_tree(tree.root);              /* free the directory tree */
+   free_tree(tree.root);             /* free the directory tree */
    return OK;
 }
 
@@ -990,11 +989,11 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
       bstrncpy(fsr.FileSet, ua->argv[i], sizeof(fsr.FileSet));
       if (!db_get_fileset_record(ua->jcr, ua->db, &fsr)) {
          bsendmsg(ua, _("Error getting FileSet \"%s\": ERR=%s\n"), fsr.FileSet,
-            db_strerror(ua->db));
-         i = -1;
+           db_strerror(ua->db));
+        i = -1;
       }
    }
-   if (i < 0) {                       /* fileset not found */
+   if (i < 0) {                      /* fileset not found */
       edit_int64(cr.ClientId, ed1);
       Mmsg(rx->query, uar_sel_fileset, ed1, ed1);
       start_prompt(ua, _("The defined FileSet resources are:\n"));
@@ -1002,8 +1001,8 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
          bsendmsg(ua, "%s\n", db_strerror(ua->db));
       }
       if (do_prompt(ua, _("FileSet"), _("Select FileSet resource"),
-                 fileset_name, sizeof(fileset_name)) < 0) {
-         goto bail_out;
+                fileset_name, sizeof(fileset_name)) < 0) {
+        goto bail_out;
       }
 
       bstrncpy(fsr.FileSet, fileset_name, sizeof(fsr.FileSet));
@@ -1022,7 +1021,7 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
       bstrncpy(pr.Name, rx->pool->hdr.name, sizeof(pr.Name));
       if (db_get_pool_record(ua->jcr, ua->db, &pr)) {
          bsnprintf(pool_select, sizeof(pool_select), "AND Media.PoolId=%s ", 
-            edit_int64(pr.PoolId, ed1));
+           edit_int64(pr.PoolId, ed1));
       } else {
          bsendmsg(ua, _("Pool \"%s\" not found, using any pool.\n"), pr.Name);
       }
@@ -1031,7 +1030,7 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
    /* Find JobId of last Full backup for this client, fileset */
    edit_int64(cr.ClientId, ed1);
    Mmsg(rx->query, uar_last_full, ed1, ed1, date, fsr.FileSet,
-         pool_select);
+        pool_select);
    if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
       bsendmsg(ua, "%s\n", db_strerror(ua->db));
       goto bail_out;
@@ -1056,7 +1055,7 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
 
    /* Now find most recent Differental Job after Full save, if any */
    Mmsg(rx->query, uar_dif, edit_uint64(rx->JobTDate, ed1), date,
-        edit_int64(cr.ClientId, ed2), fsr.FileSet, pool_select);
+       edit_int64(cr.ClientId, ed2), fsr.FileSet, pool_select);
    if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
       bsendmsg(ua, "%s\n", db_strerror(ua->db));
    }
@@ -1072,7 +1071,7 @@ static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *dat
 
    /* Now find all Incremental Jobs after Full/dif save */
    Mmsg(rx->query, uar_inc, edit_uint64(rx->JobTDate, ed1), date,
-        edit_int64(cr.ClientId, ed2), fsr.FileSet, pool_select);
+       edit_int64(cr.ClientId, ed2), fsr.FileSet, pool_select);
    if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
       bsendmsg(ua, "%s\n", db_strerror(ua->db));
    }
@@ -1108,10 +1107,10 @@ static int get_next_jobid_from_list(char **p, uint32_t *JobId)
    jobid[0] = 0;
    for (int i=0; i<(int)sizeof(jobid); i++) {
       if (*q == 0) {
-         break;
+        break;
       } else if (*q == ',') {
-         q++;
-         break;
+        q++;
+        break;
       }
       jobid[i] = *q++;
       jobid[i+1] = 0;
@@ -1119,7 +1118,7 @@ static int get_next_jobid_from_list(char **p, uint32_t *JobId)
    if (jobid[0] == 0) {
       return 0;
    } else if (!is_a_number(jobid)) {
-      return -1;                      /* error */
+      return -1;                     /* error */
    }
    *p = q;
    *JobId = str_to_int64(jobid);
@@ -1156,7 +1155,7 @@ static int jobid_handler(void *ctx, int num_fields, char **row)
    RESTORE_CTX *rx = (RESTORE_CTX *)ctx;
 
    if (strcmp(rx->last_jobid, row[0]) == 0) {
-      return 0;                       /* duplicate id */
+      return 0;                      /* duplicate id */
    }
    bstrncpy(rx->last_jobid, row[0], sizeof(rx->last_jobid));
    if (rx->JobIds[0] != 0) {
@@ -1205,16 +1204,16 @@ static int unique_name_list_handler(void *ctx, int num_fields, char **row)
    }
    if (name->num_ids == name->max_ids) {
       if (name->max_ids == 0) {
-         name->max_ids = 1000;
-         name->name = (char **)bmalloc(sizeof(char *) * name->max_ids);
+        name->max_ids = 1000;
+        name->name = (char **)bmalloc(sizeof(char *) * name->max_ids);
       } else {
-         name->max_ids = (name->max_ids * 3) / 2;
-         name->name = (char **)brealloc(name->name, sizeof(char *) * name->max_ids);
+        name->max_ids = (name->max_ids * 3) / 2;
+        name->name = (char **)brealloc(name->name, sizeof(char *) * name->max_ids);
       }
    }
    for (int i=0; i<name->num_ids; i++) {
       if (strcmp(name->name[i], row[0]) == 0) {
-         return 0;                    /* already in list, return */
+        return 0;                    /* already in list, return */
       }
    }
    /* Add new name to list */
@@ -1276,10 +1275,10 @@ static void get_storage_from_mediatype(UAContext *ua, NAME_LIST *name_list, REST
    LockRes();
    foreach_res(store, R_STORAGE) {
       if (strcmp(name_list->name[0], store->media_type) == 0) {
-         if (acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
-            rx->store = store;
-         }
-         break;
+        if (acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+           rx->store = store;
+        }
+        break;
       }
    }
    UnlockRes();
@@ -1289,15 +1288,15 @@ static void get_storage_from_mediatype(UAContext *ua, NAME_LIST *name_list, REST
       store = NULL;
       int i = find_arg_with_value(ua, "storage");
       if (i > 0) {
-         store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]);
-         if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
-            store = NULL;
-         }
+        store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]);
+        if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+           store = NULL;
+        }
       }
       if (store && (store != rx->store)) {
          bsendmsg(ua, _("Warning default storage overridden by %s on command line.\n"),
-            store->hdr.name);
-         rx->store = store;
+           store->hdr.name);
+        rx->store = store;
       }
       return;
    }
@@ -1309,6 +1308,6 @@ static void get_storage_from_mediatype(UAContext *ua, NAME_LIST *name_list, REST
       bsendmsg(ua, _("\nWarning. Unable to find Storage resource for\n"
          "MediaType \"%s\", needed by the Jobs you selected.\n"
          "You will be allowed to select a Storage device later.\n"),
-         name_list->name[0]);
+        name_list->name[0]);
    }
 }
index 7fa3084aa6ae785cbd6e52f9fd29d7916264184c..bae78c22105efbc36fd78ae530a1eb6deb4425d6 100644 (file)
  *
  *   Version $Id$
  */
-
 /*
    Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
+
 #include "bacula.h"
 #include "dird.h"
 #include "findlib/find.h"
@@ -144,14 +139,14 @@ bool do_verify_init(JCR *jcr)
         free_bsr(bsr);
         return false;
       }
-      free_ua_context(ua);
-      free_bsr(bsr);
       if (jcr->RestoreBootstrap) {
         free(jcr->RestoreBootstrap);
       }
       POOLMEM *fname = get_pool_memory(PM_MESSAGE);
-      Mmsg(fname, "%s/restore.bsr", working_directory);
+      make_unique_restore_filename(ua, &fname);
       jcr->RestoreBootstrap = bstrdup(fname);
+      free_ua_context(ua);
+      free_bsr(bsr);
       free_pool_memory(fname);
       jcr->needs_sd = true;
 
@@ -370,6 +365,10 @@ void verify_cleanup(JCR *jcr, int TermCode)
    set_jcr_job_status(jcr, TermCode);
 
    update_job_end_record(jcr);
+   if (jcr->unlink_bsr && jcr->RestoreBootstrap) {
+      unlink(jcr->RestoreBootstrap);
+      jcr->unlink_bsr = false;
+   }
 
    msg_type = M_INFO;                /* by default INFO message */
    switch (TermCode) {
index c13a6feff126abe4708ae922f74148b382f029d1..15c755b4fd18641633b9c1196397ecada4a362a3 100644 (file)
@@ -9,38 +9,25 @@
  *
  */
 /*
-   Copyright (C) 2003-2004 Kern Sibbald and John Walker
+   Copyright (C) 2003-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
 #include "bacula.h"
 #include "filed.h"
 
-#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
-/* pthread_kill() dies on Cygwin, so disable it */
-#define pthread_kill(x, y)
-/* Use shorter wait interval on Cygwin because no kill */
 #define WAIT_INTERVAL 10
 
-#else  /* Unix systems */
-#define WAIT_INTERVAL 60
-#endif
-
 extern "C" void *sd_heartbeat_thread(void *arg);
 extern "C" void *dir_heartbeat_thread(void *arg);
 extern bool no_signals;
@@ -57,14 +44,19 @@ extern "C" void *sd_heartbeat_thread(void *arg)
    BSOCK *sd, *dir;
    time_t last_heartbeat = time(NULL);
    time_t now;
+   int oflags;
 
    pthread_detach(pthread_self());
 
    /* Get our own local copy */
    sd = dup_bsock(jcr->store_bsock);
+   if ((oflags = fcntl(sd->fd, F_GETFL, 0)) != -1) {
+      fcntl(sd->fd, F_SETFL, oflags|O_NONBLOCK);
+   }
    dir = dup_bsock(jcr->dir_bsock);
 
    jcr->hb_bsock = sd;
+   jcr->hb_dir_bsock = dir;
 
    /* Hang reading the socket to the SD, and every time we get
     *  a heartbeat or we get a wait timeout (1 minute), we
@@ -80,18 +72,22 @@ extern "C" void *sd_heartbeat_thread(void *arg)
            last_heartbeat = now;
         }
       }
+      if (is_bnet_stop(sd)) {
+        break;
+      }
       if (n == 1) {                  /* input waiting */
         bnet_recv(sd);               /* read it -- probably heartbeat from sd */
         if (sd->msglen <= 0) {
-           Dmsg1(100, "Got BNET_SIG %d from SD\n", sd->msglen);
+            Dmsg1(100, "Got BNET_SIG %d from SD\n", sd->msglen);
         } else {
-           Dmsg2(100, "Got %d bytes from SD. MSG=%s\n", sd->msglen, sd->msg);
+            Dmsg2(100, "Got %d bytes from SD. MSG=%s\n", sd->msglen, sd->msg);
         }
       }
    }
    bnet_close(sd);
    bnet_close(dir);
    jcr->hb_bsock = NULL;
+   jcr->hb_dir_bsock = NULL;
    return NULL;
 }
 
@@ -105,6 +101,7 @@ void start_heartbeat_monitor(JCR *jcr)
     */
    if (!no_signals) {
       jcr->hb_bsock = NULL;
+      jcr->hb_dir_bsock = NULL;
       pthread_create(&jcr->heartbeat_id, NULL, sd_heartbeat_thread, (void *)jcr);
    }
 }
@@ -118,19 +115,28 @@ void stop_heartbeat_monitor(JCR *jcr)
    }
    /* Wait max 10 secs for heartbeat thread to start */
    while (jcr->hb_bsock == NULL && cnt++ < 200) {
-      bmicrosleep(0, 50);            /* avoid race */
+      bmicrosleep(0, 50000);        /* wait for start */
+   }
+   if (!jcr->hb_bsock) {
    }
 
    if (jcr->hb_bsock) {
       jcr->hb_bsock->timed_out = 1;   /* set timed_out to terminate read */
       jcr->hb_bsock->terminated = 1;  /* set to terminate read */
    }
+   if (jcr->hb_dir_bsock) {
+      jcr->hb_dir_bsock->timed_out = 1;   /* set timed_out to terminate read */
+      jcr->hb_dir_bsock->terminated = 1;  /* set to terminate read */
+   }
+   pthread_kill(jcr->heartbeat_id, TIMEOUT_SIGNAL);  /* make heartbeat thread go away */
+   bmicrosleep(0, 50000);
    cnt = 0;
    /* Wait max 100 secs for heartbeat thread to stop */
    while (jcr->hb_bsock && cnt++ < 200) {
-      /* Naturally, Cygwin 1.3.20 craps out on the following */
       pthread_kill(jcr->heartbeat_id, TIMEOUT_SIGNAL); /* make heartbeat thread go away */
-      bmicrosleep(0, 500);
+      bmicrosleep(0, 500000);
+   }
+   if (jcr->hb_bsock) {
    }
 }
 
index 7d3edd1b8b3284671c44c732fea3731d2319bd6e..72f0a1bc28e49abdbbd6e5e6c633ae0c17be7242 100644 (file)
    Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -34,7 +29,7 @@
 #endif
 
 extern char my_name[];
-extern CLIENT *me;                    /* our client resource */
+extern CLIENT *me;                   /* our client resource */
 
 /* Imported functions */
 extern int status_cmd(JCR *jcr);
@@ -93,7 +88,7 @@ static struct s_cmds cmds[] = {
    {"bootstrap",    bootstrap_cmd, 0},
    {"RunBeforeJob", runbefore_cmd, 0},
    {"RunAfterJob",  runafter_cmd,  0},
-   {NULL,       NULL}                  /* list terminator */
+   {NULL,      NULL}                  /* list terminator */
 };
 
 /* Commands received from director that need scanning */
@@ -186,37 +181,37 @@ void *handle_client_request(void *dirp)
 
       /* Read command */
       if (bnet_recv(dir) < 0) {
-         break;               /* connection terminated */
+        break;               /* connection terminated */
       }
       dir->msg[dir->msglen] = 0;
       Dmsg1(100, "<dird: %s", dir->msg);
       found = false;
       for (i=0; cmds[i].cmd; i++) {
-         if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) {
-            found = true;         /* indicate command found */
-            if (!jcr->authenticated && cmds[i].func != hello_cmd) {
-               bnet_fsend(dir, no_auth);
-               bnet_sig(dir, BNET_EOD);
-               break;
-            }
-            if ((jcr->authenticated) && (!cmds[i].monitoraccess) && (jcr->director->monitor)) {
+        if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) {
+           found = true;         /* indicate command found */
+           if (!jcr->authenticated && cmds[i].func != hello_cmd) {
+              bnet_fsend(dir, no_auth);
+              bnet_sig(dir, BNET_EOD);
+              break;
+           }
+           if ((jcr->authenticated) && (!cmds[i].monitoraccess) && (jcr->director->monitor)) {
                Dmsg1(100, "Command %s illegal.\n", cmds[i].cmd);
-               bnet_fsend(dir, illegal_cmd);
-               bnet_sig(dir, BNET_EOD);
-               break;
-            }
+              bnet_fsend(dir, illegal_cmd);
+              bnet_sig(dir, BNET_EOD);
+              break;
+           }
             Dmsg1(100, "Executing %s command.\n", cmds[i].cmd);
-            if (!cmds[i].func(jcr)) {         /* do command */
-               quit = true;         /* error or fully terminated, get out */
+           if (!cmds[i].func(jcr)) {         /* do command */
+              quit = true;         /* error or fully terminated, get out */
                Dmsg1(20, "Quit command loop. Canceled=%d\n", job_canceled(jcr));
-            }
-            break;
-         }
+           }
+           break;
+        }
       }
-      if (!found) {              /* command not found */
-         bnet_fsend(dir, errmsg);
-         quit = true;
-         break;
+      if (!found) {             /* command not found */
+        bnet_fsend(dir, errmsg);
+        quit = true;
+        break;
       }
    }
 
@@ -230,7 +225,7 @@ void *handle_client_request(void *dirp)
    }
    generate_daemon_event(jcr, "JobEnd");
 
-   dequeue_messages(jcr);             /* send any queued messages */
+   dequeue_messages(jcr);            /* send any queued messages */
 
    /* Inform Director that we are done */
    bnet_sig(dir, BNET_TERMINATE);
@@ -242,48 +237,48 @@ void *handle_client_request(void *dirp)
       int i, j, k;
       /* Delete FileSet Include lists */
       for (i=0; i<fileset->include_list.size(); i++) {
-         findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
-         for (j=0; j<incexe->opts_list.size(); j++) {
-            findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
-            for (k=0; k<fo->regex.size(); k++) {
-               regfree((regex_t *)fo->regex.get(k));
-            }
-            fo->regex.destroy();
-            fo->regexdir.destroy();
-            fo->regexfile.destroy();
-            fo->wild.destroy();
-            fo->wilddir.destroy();
-            fo->wildfile.destroy();
-            fo->base.destroy();
-            fo->fstype.destroy();
-            if (fo->reader) {
-               free(fo->reader);
-            }
-            if (fo->writer) {
-               free(fo->writer);
-            }
-         }
-         incexe->opts_list.destroy();
-         incexe->name_list.destroy();
+        findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
+        for (j=0; j<incexe->opts_list.size(); j++) {
+           findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+           for (k=0; k<fo->regex.size(); k++) {
+              regfree((regex_t *)fo->regex.get(k));
+           }
+           fo->regex.destroy();
+           fo->regexdir.destroy();
+           fo->regexfile.destroy();
+           fo->wild.destroy();
+           fo->wilddir.destroy();
+           fo->wildfile.destroy();
+           fo->base.destroy();
+           fo->fstype.destroy();
+           if (fo->reader) {
+              free(fo->reader);
+           }
+           if (fo->writer) {
+              free(fo->writer);
+           }
+        }
+        incexe->opts_list.destroy();
+        incexe->name_list.destroy();
       }
       fileset->include_list.destroy();
 
       /* Delete FileSet Exclude lists */
       for (i=0; i<fileset->exclude_list.size(); i++) {
-         findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
-         for (j=0; j<incexe->opts_list.size(); j++) {
-            findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
-            fo->regex.destroy();
-            fo->regexdir.destroy();
-            fo->regexfile.destroy();
-            fo->wild.destroy();
-            fo->wilddir.destroy();
-            fo->wildfile.destroy();
-            fo->base.destroy();
-            fo->fstype.destroy();
-         }
-         incexe->opts_list.destroy();
-         incexe->name_list.destroy();
+        findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
+        for (j=0; j<incexe->opts_list.size(); j++) {
+           findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+           fo->regex.destroy();
+           fo->regexdir.destroy();
+           fo->regexfile.destroy();
+           fo->wild.destroy();
+           fo->wilddir.destroy();
+           fo->wildfile.destroy();
+           fo->base.destroy();
+           fo->fstype.destroy();
+        }
+        incexe->opts_list.destroy();
+        incexe->name_list.destroy();
       }
       fileset->exclude_list.destroy();
       free(fileset);
@@ -293,7 +288,7 @@ void *handle_client_request(void *dirp)
    term_find_files((FF_PKT *)jcr->ff);
    jcr->ff = NULL;
    Dmsg0(100, "Done with term_find_files\n");
-   free_jcr(jcr);                     /* destroy JCR record */
+   free_jcr(jcr);                    /* destroy JCR record */
    Dmsg0(100, "Done with free_jcr\n");
    return NULL;
 }
@@ -326,20 +321,20 @@ static int cancel_cmd(JCR *jcr)
       if (!(cjcr=get_jcr_by_full_name(Job))) {
          bnet_fsend(dir, "2901 Job %s not found.\n", Job);
       } else {
-         if (cjcr->store_bsock) {
-            P(cjcr->mutex);
-            cjcr->store_bsock->timed_out = 1;
-            cjcr->store_bsock->terminated = 1;
+        if (cjcr->store_bsock) {
+           P(cjcr->mutex);
+           cjcr->store_bsock->timed_out = 1;
+           cjcr->store_bsock->terminated = 1;
 /*
  * #if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
  */
 #if !defined(HAVE_CYGWIN)
-            pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL);
+           pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL);
 #endif
-            V(cjcr->mutex);
-         }
-         set_jcr_job_status(cjcr, JS_Canceled);
-         free_jcr(cjcr);
+           V(cjcr->mutex);
+        }
+        set_jcr_job_status(cjcr, JS_Canceled);
+        free_jcr(cjcr);
          bnet_fsend(dir, _("2001 Job %s marked to be canceled.\n"), Job);
       }
    } else {
@@ -399,8 +394,8 @@ static int job_cmd(JCR *jcr)
 
    sd_auth_key = get_memory(dir->msglen);
    if (sscanf(dir->msg, jobcmd,  &jcr->JobId, jcr->Job,
-              &jcr->VolSessionId, &jcr->VolSessionTime,
-              sd_auth_key) != 5) {
+             &jcr->VolSessionId, &jcr->VolSessionTime,
+             sd_auth_key) != 5) {
       pm_strcpy(jcr->errmsg, dir->msg);
       Jmsg(jcr, M_FATAL, 0, _("Bad Job Command: %s"), jcr->errmsg);
       bnet_fsend(dir, BADjob);
@@ -477,13 +472,13 @@ static bool run_cmd(JCR *jcr, char *cmd, const char *name)
    if (bpipe == NULL) {
       berrno be;
       Jmsg(jcr, M_FATAL, 0, _("%s could not execute. ERR=%s\n"), name,
-         be.strerror());
+        be.strerror());
       return false;
    }
    while (fgets(line, sizeof(line), bpipe->rfd)) {
       int len = strlen(line);
       if (len > 0 && line[len-1] == '\n') {
-         line[len-1] = 0;
+        line[len-1] = 0;
       }
       Jmsg(jcr, M_INFO, 0, _("%s: %s\n"), name, line);
    }
@@ -491,7 +486,7 @@ static bool run_cmd(JCR *jcr, char *cmd, const char *name)
    if (status != 0) {
       berrno be;
       Jmsg(jcr, M_FATAL, 0, _("%s returned non-zero status=%d. ERR=%s\n"), name,
-         status, be.strerror(status));
+        status, be.strerror(status));
       return false;
    }
    return true;
@@ -560,39 +555,39 @@ static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *filese
    ch = (uint8_t)*p;
    switch (ch) {
    case '|':
-      p++;                            /* skip over | */
+      p++;                           /* skip over | */
       fn = get_pool_memory(PM_FNAME);
       fn = edit_job_codes(jcr, fn, p, "");
       bpipe = open_bpipe(fn, 0, "r");
       free_pool_memory(fn);
       if (!bpipe) {
          Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
-            p, strerror(errno));
-         return;
+           p, strerror(errno));
+        return;
       }
       while (fgets(buf, sizeof(buf), bpipe->rfd)) {
-         strip_trailing_junk(buf);
-         fileset->incexe->name_list.append(bstrdup(buf));
+        strip_trailing_junk(buf);
+        fileset->incexe->name_list.append(bstrdup(buf));
       }
       if ((stat=close_bpipe(bpipe)) != 0) {
          Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
-            p, stat, strerror(errno));
-         return;
+           p, stat, strerror(errno));
+        return;
       }
       break;
    case '<':
       Dmsg0(100, "Doing < include on client.\n");
-      p++;                      /* skip over < */
+      p++;                     /* skip over < */
       if ((ffd = fopen(p, "r")) == NULL) {
-         berrno be;
+        berrno be;
          Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
-            p, be.strerror());
-         return;
+           p, be.strerror());
+        return;
       }
       while (fgets(buf, sizeof(buf), ffd)) {
-         strip_trailing_junk(buf);
+        strip_trailing_junk(buf);
          Dmsg1(100, "%s\n", buf);
-         fileset->incexe->name_list.append(bstrdup(buf));
+        fileset->incexe->name_list.append(bstrdup(buf));
       }
       fclose(ffd);
       break;
@@ -671,27 +666,27 @@ static void add_fileset(JCR *jcr, const char *item)
       char prbuf[500];
       preg = (regex_t *)malloc(sizeof(regex_t));
       if (current_opts->flags & FO_IGNORECASE) {
-         rc = regcomp(preg, item, REG_EXTENDED|REG_ICASE);
+        rc = regcomp(preg, item, REG_EXTENDED|REG_ICASE);
       } else {
-         rc = regcomp(preg, item, REG_EXTENDED);
+        rc = regcomp(preg, item, REG_EXTENDED);
       }
       if (rc != 0) {
-         regerror(rc, preg, prbuf, sizeof(prbuf));
-         regfree(preg);
-         free(preg);
+        regerror(rc, preg, prbuf, sizeof(prbuf));
+        regfree(preg);
+        free(preg);
          Jmsg(jcr, M_FATAL, 0, "REGEX %s compile error. ERR=%s\n", item, prbuf);
-         state = state_error;
-         break;
+        state = state_error;
+        break;
       }
       state = state_options;
       if (subcode == ' ') {
-         current_opts->regex.append(preg);
+        current_opts->regex.append(preg);
       } else if (subcode == 'D') {
-         current_opts->regexdir.append(preg);
+        current_opts->regexdir.append(preg);
       } else if (subcode == 'F') {
-         current_opts->regexfile.append(preg);
+        current_opts->regexfile.append(preg);
       } else {
-         state = state_error;
+        state = state_error;
       }
       break;
    case 'B':
@@ -708,13 +703,13 @@ static void add_fileset(JCR *jcr, const char *item)
       current_opts = start_options(ff);
       state = state_options;
       if (subcode == ' ') {
-         current_opts->wild.append(bstrdup(item));
+        current_opts->wild.append(bstrdup(item));
       } else if (subcode == 'D') {
-         current_opts->wilddir.append(bstrdup(item));
+        current_opts->wilddir.append(bstrdup(item));
       } else if (subcode == 'F') {
-         current_opts->wildfile.append(bstrdup(item));
+        current_opts->wildfile.append(bstrdup(item));
       } else {
-         state = state_error;
+        state = state_error;
       }
       break;
    case 'O':
@@ -750,37 +745,37 @@ static bool term_fileset(JCR *jcr)
       findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
       Dmsg0(400, "I\n");
       for (j=0; j<incexe->opts_list.size(); j++) {
-         findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
-         for (k=0; k<fo->regex.size(); k++) {
+        findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+        for (k=0; k<fo->regex.size(); k++) {
             Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
-         }
-         for (k=0; k<fo->regexdir.size(); k++) {
+        }
+        for (k=0; k<fo->regexdir.size(); k++) {
             Dmsg1(400, "RD %s\n", (char *)fo->regexdir.get(k));
-         }
-         for (k=0; k<fo->regexfile.size(); k++) {
+        }
+        for (k=0; k<fo->regexfile.size(); k++) {
             Dmsg1(400, "RF %s\n", (char *)fo->regexfile.get(k));
-         }
-         for (k=0; k<fo->wild.size(); k++) {
+        }
+        for (k=0; k<fo->wild.size(); k++) {
             Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
-         }
-         for (k=0; k<fo->wilddir.size(); k++) {
+        }
+        for (k=0; k<fo->wilddir.size(); k++) {
             Dmsg1(400, "WD %s\n", (char *)fo->wilddir.get(k));
-         }
-         for (k=0; k<fo->wildfile.size(); k++) {
+        }
+        for (k=0; k<fo->wildfile.size(); k++) {
             Dmsg1(400, "WF %s\n", (char *)fo->wildfile.get(k));
-         }
-         for (k=0; k<fo->base.size(); k++) {
+        }
+        for (k=0; k<fo->base.size(); k++) {
             Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
-         }
-         for (k=0; k<fo->fstype.size(); k++) {
+        }
+        for (k=0; k<fo->fstype.size(); k++) {
             Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
-         }
-         if (fo->reader) {
+        }
+        if (fo->reader) {
             Dmsg1(400, "D %s\n", fo->reader);
-         }
-         if (fo->writer) {
+        }
+        if (fo->writer) {
             Dmsg1(400, "T %s\n", fo->writer);
-         }
+        }
       }
       for (j=0; j<incexe->name_list.size(); j++) {
          Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
@@ -790,31 +785,31 @@ static bool term_fileset(JCR *jcr)
       findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
       Dmsg0(400, "E\n");
       for (j=0; j<incexe->opts_list.size(); j++) {
-         findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
-         for (k=0; k<fo->regex.size(); k++) {
+        findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+        for (k=0; k<fo->regex.size(); k++) {
             Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
-         }
-         for (k=0; k<fo->regexdir.size(); k++) {
+        }
+        for (k=0; k<fo->regexdir.size(); k++) {
             Dmsg1(400, "RD %s\n", (char *)fo->regexdir.get(k));
-         }
-         for (k=0; k<fo->regexfile.size(); k++) {
+        }
+        for (k=0; k<fo->regexfile.size(); k++) {
             Dmsg1(400, "RF %s\n", (char *)fo->regexfile.get(k));
-         }
-         for (k=0; k<fo->wild.size(); k++) {
+        }
+        for (k=0; k<fo->wild.size(); k++) {
             Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
-         }
-         for (k=0; k<fo->wilddir.size(); k++) {
+        }
+        for (k=0; k<fo->wilddir.size(); k++) {
             Dmsg1(400, "WD %s\n", (char *)fo->wilddir.get(k));
-         }
-         for (k=0; k<fo->wildfile.size(); k++) {
+        }
+        for (k=0; k<fo->wildfile.size(); k++) {
             Dmsg1(400, "WF %s\n", (char *)fo->wildfile.get(k));
-         }
-         for (k=0; k<fo->base.size(); k++) {
+        }
+        for (k=0; k<fo->base.size(); k++) {
             Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
-         }
-         for (k=0; k<fo->fstype.size(); k++) {
+        }
+        for (k=0; k<fo->fstype.size(); k++) {
             Dmsg1(400, "X %s\n", (char *)fo->fstype.get(k));
-         }
+        }
       }
       for (j=0; j<incexe->name_list.size(); j++) {
          Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
@@ -838,72 +833,72 @@ static void set_options(findFOPTS *fo, const char *opts)
       switch (*p) {
       case 'a':                 /* alway replace */
       case '0':                 /* no option */
-         break;
+        break;
       case 'e':
-         fo->flags |= FO_EXCLUDE;
-         break;
+        fo->flags |= FO_EXCLUDE;
+        break;
       case 'f':
-         fo->flags |= FO_MULTIFS;
-         break;
+        fo->flags |= FO_MULTIFS;
+        break;
       case 'h':                 /* no recursion */
-         fo->flags |= FO_NO_RECURSION;
-         break;
+        fo->flags |= FO_NO_RECURSION;
+        break;
       case 'H':                 /* no hard link handling */
-         fo->flags |= FO_NO_HARDLINK;
-         break;
+        fo->flags |= FO_NO_HARDLINK;
+        break;
       case 'i':
-         fo->flags |= FO_IGNORECASE;
-         break;
+        fo->flags |= FO_IGNORECASE;
+        break;
       case 'M':                 /* MD5 */
-         fo->flags |= FO_MD5;
-         break;
+        fo->flags |= FO_MD5;
+        break;
       case 'n':
-         fo->flags |= FO_NOREPLACE;
-         break;
+        fo->flags |= FO_NOREPLACE;
+        break;
       case 'p':                 /* use portable data format */
-         fo->flags |= FO_PORTABLE;
-         break;
+        fo->flags |= FO_PORTABLE;
+        break;
       case 'R':                 /* Resource forks and Finder Info */
-         fo->flags |= FO_HFSPLUS;
+        fo->flags |= FO_HFSPLUS;
       case 'r':                 /* read fifo */
-         fo->flags |= FO_READFIFO;
-         break;
+        fo->flags |= FO_READFIFO;
+        break;
       case 'S':
-         fo->flags |= FO_SHA1;
-         break;
+        fo->flags |= FO_SHA1;
+        break;
       case 's':
-         fo->flags |= FO_SPARSE;
-         break;
+        fo->flags |= FO_SPARSE;
+        break;
       case 'm':
-         fo->flags |= FO_MTIMEONLY;
-         break;
+        fo->flags |= FO_MTIMEONLY;
+        break;
       case 'k':
-         fo->flags |= FO_KEEPATIME;
-         break;
+        fo->flags |= FO_KEEPATIME;
+        break;
       case 'A':
-         fo->flags |= FO_ACL;
-         break;
+        fo->flags |= FO_ACL;
+        break;
       case 'V':                  /* verify options */
-         /* Copy Verify Options */
+        /* Copy Verify Options */
          for (j=0; *p && *p != ':'; p++) {
-            fo->VerifyOpts[j] = *p;
-            if (j < (int)sizeof(fo->VerifyOpts) - 1) {
-               j++;
-            }
-         }
-         fo->VerifyOpts[j] = 0;
-         break;
+           fo->VerifyOpts[j] = *p;
+           if (j < (int)sizeof(fo->VerifyOpts) - 1) {
+              j++;
+           }
+        }
+        fo->VerifyOpts[j] = 0;
+        break;
       case 'w':
-         fo->flags |= FO_IF_NEWER;
-         break;
+        fo->flags |= FO_IF_NEWER;
+        break;
       case 'Z':                 /* gzip compression */
-         fo->flags |= FO_GZIP;
+        fo->flags |= FO_GZIP;
          fo->GZIP_level = *++p - '0';
          Dmsg1(200, "Compression level=%d\n", fo->GZIP_level);
-         break;
+        break;
       default:
          Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *p);
-         break;
+        break;
       }
    }
 }
@@ -957,10 +952,10 @@ static int bootstrap_cmd(JCR *jcr)
        *   read our error message.
        */
       while (bnet_recv(dir) >= 0)
-        {  }
+       {  }
 
       Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
-         jcr->RestoreBootstrap, be.strerror());
+        jcr->RestoreBootstrap, be.strerror());
       free_pool_memory(jcr->RestoreBootstrap);
       jcr->RestoreBootstrap = NULL;
       set_jcr_job_status(jcr, JS_ErrorTerminated);
@@ -1008,54 +1003,54 @@ static int level_cmd(JCR *jcr)
       return 1;   
    /*
     * We get his UTC since time, then sync the clocks and correct it
-    *   to agree with our clock.
+    *  to agree with our clock.
     */
    } else if (strcmp(level, "since_utime") == 0) {
       buf = get_memory(dir->msglen+1);
       utime_t since_time, adj;
       btime_t his_time, bt_start, rt=0, bt_adj=0;
       if (jcr->JobLevel == L_NONE) {
-         jcr->JobLevel = L_SINCE;     /* if no other job level set, do it now */
+        jcr->JobLevel = L_SINCE;     /* if no other job level set, do it now */
       }
       if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
-                 buf, &mtime_only) != 2) {
-         goto bail_out;
+                buf, &mtime_only) != 2) {
+        goto bail_out;
       }
-      since_time = str_to_uint64(buf);  /* this is the since time */
+      since_time = str_to_uint64(buf); /* this is the since time */
       char ed1[50], ed2[50];
       /*
        * Sync clocks by polling him for the time. We take
        *   10 samples of his time throwing out the first two.
        */
       for (int i=0; i<10; i++) {
-         bt_start = get_current_btime();
-         bnet_sig(dir, BNET_BTIME);   /* poll for time */
-         if (bnet_recv(dir) <= 0) {   /* get response */
-            goto bail_out;
-         }
+        bt_start = get_current_btime();
+        bnet_sig(dir, BNET_BTIME);   /* poll for time */
+        if (bnet_recv(dir) <= 0) {   /* get response */
+           goto bail_out;
+        }
          if (sscanf(dir->msg, "btime %s", buf) != 1) {
-            goto bail_out;
-         }
-         if (i < 2) {                 /* toss first two results */
-            continue;
-         }
-         his_time = str_to_uint64(buf);
-         rt = get_current_btime() - bt_start; /* compute round trip time */
-         bt_adj -= his_time - bt_start - rt/2;
+           goto bail_out;
+        }
+        if (i < 2) {                 /* toss first two results */
+           continue;
+        }
+        his_time = str_to_uint64(buf);
+        rt = get_current_btime() - bt_start; /* compute round trip time */
+        bt_adj -= his_time - bt_start - rt/2;
          Dmsg2(200, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
       }
 
-      bt_adj = bt_adj / 8;            /* compute average time */
+      bt_adj = bt_adj / 8;           /* compute average time */
       Dmsg2(100, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
       adj = btime_to_utime(bt_adj);
-      since_time += adj;              /* adjust for clock difference */
+      since_time += adj;             /* adjust for clock difference */
       if (adj != 0) {
          Jmsg(jcr, M_INFO, 0, _("DIR and FD clocks differ by %d seconds, FD automatically adjusting.\n"), adj);
       }
       bnet_sig(dir, BNET_EOD);
 
       Dmsg2(100, "adj = %d since_time=%d\n", (int)adj, (int)since_time);
-      jcr->incremental = 1;           /* set incremental or decremental backup */
+      jcr->incremental = 1;          /* set incremental or decremental backup */
       jcr->mtime = (time_t)since_time; /* set since time */
    } else {
       Jmsg1(jcr, M_FATAL, 0, "Unknown backup level: %s\n", level);
@@ -1087,9 +1082,9 @@ static int session_cmd(JCR *jcr)
 
    Dmsg1(100, "SessionCmd: %s", dir->msg);
    if (sscanf(dir->msg, sessioncmd, jcr->VolumeName,
-              &jcr->VolSessionId, &jcr->VolSessionTime,
-              &jcr->StartFile, &jcr->EndFile,
-              &jcr->StartBlock, &jcr->EndBlock) != 7) {
+             &jcr->VolSessionId, &jcr->VolSessionTime,
+             &jcr->StartFile, &jcr->EndFile,
+             &jcr->StartBlock, &jcr->EndBlock) != 7) {
       pm_strcpy(jcr->errmsg, dir->msg);
       Jmsg(jcr, M_FATAL, 0, "Bad session command: %s", jcr->errmsg);
       return 0;
@@ -1104,10 +1099,10 @@ static int session_cmd(JCR *jcr)
  */
 static int storage_cmd(JCR *jcr)
 {
-   int stored_port;                /* storage daemon port */
-   int enable_ssl;                 /* enable ssl to sd */
+   int stored_port;               /* storage daemon port */
+   int enable_ssl;                /* enable ssl to sd */
    BSOCK *dir = jcr->dir_bsock;
-   BSOCK *sd;                         /* storage daemon bsock */
+   BSOCK *sd;                        /* storage daemon bsock */
 
    Dmsg1(100, "StorageCmd: %s", dir->msg);
    if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port, &enable_ssl) != 3) {
@@ -1119,12 +1114,12 @@ static int storage_cmd(JCR *jcr)
    /* Open command communications with Storage daemon */
    /* Try to connect for 1 hour at 10 second intervals */
    sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"),
-                     jcr->stored_addr, NULL, stored_port, 1);
+                    jcr->stored_addr, NULL, stored_port, 1);
    if (sd == NULL) {
       Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
-          jcr->stored_addr, stored_port);
+         jcr->stored_addr, stored_port);
       Dmsg2(100, "Failed to connect to Storage daemon: %s:%d\n",
-          jcr->stored_addr, stored_port);
+         jcr->stored_addr, stored_port);
       return 0;
    }
    Dmsg0(110, "Connection OK to SD.\n");
@@ -1178,7 +1173,7 @@ static int backup_cmd(JCR *jcr)
       Dmsg1(110, "<stored: %s", sd->msg);
       if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
          Jmsg(jcr, M_FATAL, 0, _("Bad response to append open: %s\n"), sd->msg);
-         goto cleanup;
+        goto cleanup;
       }
       Dmsg1(110, "Got Ticket=%d\n", jcr->Ticket);
    } else {
@@ -1206,25 +1201,24 @@ static int backup_cmd(JCR *jcr)
    /* START VSS ON WIN 32 */
    if (g_pVSSClient) {
       if (g_pVSSClient->InitializeForBackup()) {
-         /* tell vss which drives to snapshot */   
-         char szWinDriveLetters[27];   
-         if (get_win32_driveletters((FF_PKT *)jcr->ff, szWinDriveLetters)) {
+        /* tell vss which drives to snapshot */   
+        char szWinDriveLetters[27];   
+        if (get_win32_driveletters((FF_PKT *)jcr->ff, szWinDriveLetters)) {
             Jmsg(jcr, M_INFO, 0, _("Generate VSS snapshots. Driver=%s, Drive(s)=%s\n"), g_pVSSClient->GetDriverName(), szWinDriveLetters);
 
-            if (!g_pVSSClient->CreateSnapshots(szWinDriveLetters)) {
+           if (!g_pVSSClient->CreateSnapshots(szWinDriveLetters)) {
                   Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshots failed\n"));
-            }
-            else {
-               for (int i=0; i<strlen (szWinDriveLetters); i++) {
-                  if (islower(szWinDriveLetters[i]))
+           }
+           else {
+              for (int i=0; i<strlen (szWinDriveLetters); i++) {
+                 if (islower(szWinDriveLetters[i]))
                      Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshot of drive %c: failed\n"), szWinDriveLetters[i]);
-               }
-            }
-         }
+              }
+           }
+        }
       } else {
          Jmsg(jcr, M_WARNING, 0, _("VSS was not initialized properly. VSS support is disabled."));
       }
-
    }
 #endif
 
@@ -1235,20 +1229,20 @@ static int backup_cmd(JCR *jcr)
    if (!blast_data_to_storage_daemon(jcr, NULL)) {
       set_jcr_job_status(jcr, JS_ErrorTerminated);
       bnet_suppress_error_messages(sd, 1);
-      bget_msg(sd);                   /* Read final response from append_data */
+      bget_msg(sd);                  /* Read final response from append_data */
       Dmsg0(110, "Error in blast_data.\n");
    } else {
       set_jcr_job_status(jcr, JS_Terminated);
       if (jcr->JobStatus != JS_Terminated) {
-         bnet_suppress_error_messages(sd, 1);
-         goto cleanup;                /* bail out now */
+        bnet_suppress_error_messages(sd, 1);
+        goto cleanup;                /* bail out now */
       }
       /*
        * Expect to get response to append_data from Storage daemon
        */
       if (!response(jcr, sd, OK_append, "Append Data")) {
-         set_jcr_job_status(jcr, JS_ErrorTerminated);
-         goto cleanup;
+        set_jcr_job_status(jcr, JS_ErrorTerminated);
+        goto cleanup;
       }
 
       /*
@@ -1257,8 +1251,8 @@ static int backup_cmd(JCR *jcr)
       bnet_fsend(sd, append_end, jcr->Ticket);
       /* Get end OK */
       if (!response(jcr, sd, OK_end, "Append End")) {
-         set_jcr_job_status(jcr, JS_ErrorTerminated);
-         goto cleanup;
+        set_jcr_job_status(jcr, JS_ErrorTerminated);
+        goto cleanup;
       }
 
       /*
@@ -1266,18 +1260,18 @@ static int backup_cmd(JCR *jcr)
        */
       bnet_fsend(sd, append_close, jcr->Ticket);
       while (bget_msg(sd) >= 0) {    /* stop on signal or error */
-         if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) {
-            ok = 1;
+        if (sscanf(sd->msg, OK_close, &SDJobStatus) == 1) {
+           ok = 1;
             Dmsg2(200, "SDJobStatus = %d %c\n", SDJobStatus, (char)SDJobStatus);
-         }
+        }
       }
       if (!ok) {
          Jmsg(jcr, M_FATAL, 0, _("Append Close with SD failed.\n"));
-         goto cleanup;
+        goto cleanup;
       }
       if (SDJobStatus != JS_Terminated) {
          Jmsg(jcr, M_FATAL, 0, _("Bad status %d returned from Storage Daemon.\n"),
-            SDJobStatus);
+           SDJobStatus);
       }
    }
 
@@ -1294,7 +1288,7 @@ cleanup:
    Dmsg1(110, "End FD msg: %s\n", dir->msg);
 
    /* STOP VSS ON WIN 32 */
-   return 0;                          /* return and stop command loop */
+   return 0;                         /* return and stop command loop */
 }
 
 /*
@@ -1341,7 +1335,7 @@ static int verify_cmd(JCR *jcr)
       break;
    case L_VERIFY_VOLUME_TO_CATALOG:
       if (!open_sd_read_session(jcr)) {
-         return 0;
+        return 0;
       }
       start_dir_heartbeat(jcr);
       do_verify_volume(jcr);
@@ -1353,7 +1347,7 @@ static int verify_cmd(JCR *jcr)
       Dmsg1(130, "bfiled>stored: %s", sd->msg);
 
       /* ****FIXME**** check response */
-      bget_msg(sd);                      /* get OK */
+      bget_msg(sd);                     /* get OK */
 
       /* Inform Storage daemon that we are done */
       bnet_sig(sd, BNET_TERMINATE);
@@ -1376,7 +1370,7 @@ static int verify_cmd(JCR *jcr)
 
    /* Inform Director that we are done */
    bnet_sig(dir, BNET_TERMINATE);
-   return 0;                          /* return and terminate command loop */
+   return 0;                         /* return and terminate command loop */
 }
 
 /*
@@ -1402,9 +1396,9 @@ static int restore_cmd(JCR *jcr)
 
    if (sscanf(dir->msg, restorecmd, &replace, &prefix_links, where) != 3) {
       if (sscanf(dir->msg, restorecmd1, &replace, &prefix_links) != 2) {
-         pm_strcpy(jcr->errmsg, dir->msg);
+        pm_strcpy(jcr->errmsg, dir->msg);
          Jmsg(jcr, M_FATAL, 0, _("Bad replace command. CMD=%s\n"), jcr->errmsg);
-         return 0;
+        return 0;
       }
       *where = 0;
    }
@@ -1453,7 +1447,7 @@ static int restore_cmd(JCR *jcr)
    bnet_fsend(sd, read_close, jcr->Ticket);
    Dmsg1(130, "bfiled>stored: %s", sd->msg);
 
-   bget_msg(sd);                      /* get OK */
+   bget_msg(sd);                     /* get OK */
 
    /* Inform Storage daemon that we are done */
    bnet_sig(sd, BNET_TERMINATE);
@@ -1472,7 +1466,7 @@ bail_out:
    bnet_sig(dir, BNET_TERMINATE);
 
    Dmsg0(130, "Done in job.c\n");
-   return 0;                          /* return and terminate command loop */
+   return 0;                         /* return and terminate command loop */
 }
 
 static int open_sd_read_session(JCR *jcr)
@@ -1501,7 +1495,7 @@ static int open_sd_read_session(JCR *jcr)
       Dmsg1(110, "bfiled<stored: %s", sd->msg);
       if (sscanf(sd->msg, OK_open, &jcr->Ticket) != 1) {
          Jmsg(jcr, M_FATAL, 0, _("Bad response to SD read open: %s\n"), sd->msg);
-         return 0;
+        return 0;
       }
       Dmsg1(110, "bfiled: got Ticket=%d\n", jcr->Ticket);
    } else {
@@ -1558,7 +1552,7 @@ static void filed_free_jcr(JCR *jcr)
  * sent. Check that the response is OK.
  *
  *  Returns: 0 on failure
- *           1 on success
+ *          1 on success
  */
 int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd)
 {
@@ -1568,18 +1562,18 @@ int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd)
    if (bget_msg(sd) > 0) {
       Dmsg0(110, sd->msg);
       if (strcmp(sd->msg, resp) == 0) {
-         return 1;
+        return 1;
       }
    }
    if (job_canceled(jcr)) {
-      return 0;                       /* if canceled avoid useless error messages */
+      return 0;                      /* if canceled avoid useless error messages */
    }
    if (is_bnet_error(sd)) {
       Jmsg2(jcr, M_FATAL, 0, _("Comm error with SD. bad response to %s. ERR=%s\n"),
-         cmd, bnet_strerror(sd));
+        cmd, bnet_strerror(sd));
    } else {
       Jmsg3(jcr, M_FATAL, 0, _("Bad response to %s command. Wanted %s, got %s\n"),
-         cmd, resp, sd->msg);
+        cmd, resp, sd->msg);
    }
    return 0;
 }
@@ -1600,7 +1594,7 @@ static int send_bootstrap_file(JCR *jcr)
    if (!bs) {
       berrno be;
       Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
-         jcr->RestoreBootstrap, be.strerror());
+        jcr->RestoreBootstrap, be.strerror());
       set_jcr_job_status(jcr, JS_ErrorTerminated);
       goto bail_out;
    }
index 0ef096e29bbf027043023cb94ee8e4f6ab74ab69..9fc06e81d56d0175ecd6932b28f0d9733d170019 100644 (file)
@@ -8,27 +8,22 @@
  *
  *   Version $Id$
  */
-
 /*
    Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
+
 #ifndef __JCR_H_
 #define __JCR_H_ 1
 
@@ -199,6 +194,7 @@ struct JCR {
    bool write_part_after_job;         /* Write part after job in SD */
    bool needs_sd;                     /* set if SD needed by Job */
    bool cloned;                       /* set if cloned */
+   bool unlink_bsr;                   /* Unlink bsr file created */
    ATTR_DBR ar;                       /* DB attribute record */
 #endif /* DIRECTOR_DAEMON */
 
@@ -226,6 +222,7 @@ struct JCR {
    uint32_t EndBlock;
    pthread_t heartbeat_id;            /* id of heartbeat thread */
    volatile BSOCK *hb_bsock;          /* duped SD socket */
+   volatile BSOCK *hb_dir_bsock;      /* duped DIR socket */
    POOLMEM *RunAfterJob;              /* Command to run after job */
    DIRRES* director;                  /* Director resource */
 #endif /* FILE_DAEMON */
index 204fbe755cc1fd89a712a1a5e7e4185c55cdda57..b07838db2aec72a9aa07e0efce6547e773b2da17 100644 (file)
@@ -9,22 +9,17 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000-2004 Kern Sibbald
+   Copyright (C) 2000-2005 Kern Sibbald
 
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
+   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
+   file LICENSE in the main source directory.
 
-   This library is distributed in the hope that it will be useful,
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
 extern time_t watchdog_time;
 
 #ifndef   INADDR_NONE
-#define   INADDR_NONE    -1
+#define   INADDR_NONE   -1
 #endif
 
-#ifndef ENODATA                    /* not defined on BSD systems */
+#ifndef ENODATA                   /* not defined on BSD systems */
 #define ENODATA EPIPE
 #endif
 
 #ifdef HAVE_WIN32
 #define socketRead(fd, buf, len)  recv(fd, buf, len, 0)
 #define socketWrite(fd, buf, len) send(fd, buf, len, 0)
-#define socketClose(fd)           closesocket(fd)
+#define socketClose(fd)          closesocket(fd)
 #else
 #define socketRead(fd, buf, len)  read(fd, buf, len)
 #define socketWrite(fd, buf, len) write(fd, buf, len)
-#define socketClose(fd)           close(fd)
+#define socketClose(fd)          close(fd)
 #endif
 
 static pthread_mutex_t ip_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -75,19 +70,19 @@ static int32_t read_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes)
    nleft = nbytes;
    while (nleft > 0) {
       do {
-         errno = 0;
-         nread = socketRead(bsock->fd, ptr, nleft);
-         if (bsock->timed_out || bsock->terminated) {
-            return nread;
-         }
+        errno = 0;
+        nread = socketRead(bsock->fd, ptr, nleft);
+        if (bsock->timed_out || bsock->terminated) {
+           return nread;
+        }
       } while (nread == -1 && (errno == EINTR || errno == EAGAIN));
       if (nread <= 0) {
-         return nread;             /* error, or EOF */
+        return nread;             /* error, or EOF */
       }
       nleft -= nread;
       ptr += nread;
    }
-   return nbytes - nleft;          /* return >= 0 */
+   return nbytes - nleft;         /* return >= 0 */
 }
 
 /*
@@ -102,13 +97,13 @@ static int32_t write_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes)
    if (bsock->spool) {
       nwritten = fwrite(ptr, 1, nbytes, bsock->spool_fd);
       if (nwritten != nbytes) {
-         berrno be;
-         bsock->b_errno = errno;
+        berrno be;
+        bsock->b_errno = errno;
          Qmsg1(bsock->jcr, M_FATAL, 0, _("Attr spool write error. ERR=%s\n"),
-               be.strerror());
+              be.strerror());
          Dmsg2(400, "nwritten=%d nbytes=%d.\n", nwritten, nbytes);
-         errno = bsock->b_errno;
-         return -1;
+        errno = bsock->b_errno;
+        return -1;
       }
       return nbytes;
    }
@@ -123,11 +118,11 @@ static int32_t write_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes)
    nleft = nbytes;
    while (nleft > 0) {
       do {
-         errno = 0;
-         nwritten = socketWrite(bsock->fd, ptr, nleft);
-         if (bsock->timed_out || bsock->terminated) {
-            return nwritten;
-         }
+        errno = 0;
+        nwritten = socketWrite(bsock->fd, ptr, nleft);
+        if (bsock->timed_out || bsock->terminated) {
+           return nwritten;
+        }
       } while (nwritten == -1 && errno == EINTR);
       /*
        * If connection is non-blocking, we will get EAGAIN, so
@@ -135,18 +130,18 @@ static int32_t write_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes)
        * and try again.
        */
       if (nwritten == -1 && errno == EAGAIN) {
-         fd_set fdset;
-         struct timeval tv;
-
-         FD_ZERO(&fdset);
-         FD_SET((unsigned)bsock->fd, &fdset);
-         tv.tv_sec = 10;
-         tv.tv_usec = 0;
-         select(bsock->fd + 1, NULL, &fdset, NULL, &tv);
-         continue;
+        fd_set fdset;
+        struct timeval tv;
+
+        FD_ZERO(&fdset);
+        FD_SET((unsigned)bsock->fd, &fdset);
+        tv.tv_sec = 10;
+        tv.tv_usec = 0;
+        select(bsock->fd + 1, NULL, &fdset, NULL, &tv);
+        continue;
       }
       if (nwritten <= 0) {
-         return nwritten;          /* error */
+        return nwritten;          /* error */
       }
       nleft -= nwritten;
       ptr += nwritten;
@@ -161,7 +156,7 @@ static int32_t write_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes)
  * Returns number of bytes read (may return zero)
  * Returns -1 on signal (BNET_SIGNAL)
  * Returns -2 on hard end of file (BNET_HARDEOF)
- * Returns -3 on error  (BNET_ERROR)
+ * Returns -3 on error (BNET_ERROR)
  *
  *  Unfortunately, it is a bit complicated because we have these
  *    four return types:
@@ -183,54 +178,54 @@ int32_t bnet_recv(BSOCK * bsock)
       return BNET_HARDEOF;
    }
 
-   bsock->read_seqno++;            /* bump sequence number */
-   bsock->timer_start = watchdog_time;  /* set start wait time */
+   bsock->read_seqno++;           /* bump sequence number */
+   bsock->timer_start = watchdog_time; /* set start wait time */
    bsock->timed_out = 0;
    /* get data size -- in int32_t */
    if ((nbytes = read_nbytes(bsock, (char *)&pktsiz, sizeof(int32_t))) <= 0) {
-      bsock->timer_start = 0;      /* clear timer */
+      bsock->timer_start = 0;     /* clear timer */
       /* probably pipe broken because client died */
       if (errno == 0) {
-         bsock->b_errno = ENODATA;
+        bsock->b_errno = ENODATA;
       } else {
-         bsock->b_errno = errno;
+        bsock->b_errno = errno;
       }
       bsock->errors++;
-      return BNET_HARDEOF;         /* assume hard EOF received */
+      return BNET_HARDEOF;        /* assume hard EOF received */
    }
-   bsock->timer_start = 0;         /* clear timer */
+   bsock->timer_start = 0;        /* clear timer */
    if (nbytes != sizeof(int32_t)) {
       bsock->errors++;
       bsock->b_errno = EIO;
       Qmsg5(bsock->jcr, M_ERROR, 0, _("Read expected %d got %d from %s:%s:%d\n"),
-            sizeof(int32_t), nbytes, bsock->who, bsock->host, bsock->port);
+           sizeof(int32_t), nbytes, bsock->who, bsock->host, bsock->port);
       return BNET_ERROR;
    }
 
-   pktsiz = ntohl(pktsiz);         /* decode no. of bytes that follow */
+   pktsiz = ntohl(pktsiz);        /* decode no. of bytes that follow */
 
-   if (pktsiz == 0) {              /* No data transferred */
-      bsock->timer_start = 0;      /* clear timer */
+   if (pktsiz == 0) {             /* No data transferred */
+      bsock->timer_start = 0;     /* clear timer */
       bsock->in_msg_no++;
       bsock->msglen = 0;
-      return 0;                    /* zero bytes read */
+      return 0;                   /* zero bytes read */
    }
 
    /* If signal or packet size too big */
    if (pktsiz < 0 || pktsiz > 1000000) {
-      if (pktsiz > 0) {            /* if packet too big */
-         Qmsg3(bsock->jcr, M_FATAL, 0,
+      if (pktsiz > 0) {           /* if packet too big */
+        Qmsg3(bsock->jcr, M_FATAL, 0,
                _("Packet size too big from \"%s:%s:%d. Terminating connection.\n"),
-               bsock->who, bsock->host, bsock->port);
-         pktsiz = BNET_TERMINATE;  /* hang up */
+              bsock->who, bsock->host, bsock->port);
+        pktsiz = BNET_TERMINATE;  /* hang up */
       }
       if (pktsiz == BNET_TERMINATE) {
-         bsock->terminated = 1;
+        bsock->terminated = 1;
       }
-      bsock->timer_start = 0;      /* clear timer */
+      bsock->timer_start = 0;     /* clear timer */
       bsock->b_errno = ENODATA;
-      bsock->msglen = pktsiz;      /* signal code */
-      return BNET_SIGNAL;          /* signal */
+      bsock->msglen = pktsiz;     /* signal code */
+      return BNET_SIGNAL;         /* signal */
    }
 
    /* Make sure the buffer is big enough + one byte for EOS */
@@ -238,29 +233,29 @@ int32_t bnet_recv(BSOCK * bsock)
       bsock->msg = realloc_pool_memory(bsock->msg, pktsiz + 100);
    }
 
-   bsock->timer_start = watchdog_time;  /* set start wait time */
+   bsock->timer_start = watchdog_time; /* set start wait time */
    bsock->timed_out = 0;
    /* now read the actual data */
    if ((nbytes = read_nbytes(bsock, bsock->msg, pktsiz)) <= 0) {
-      bsock->timer_start = 0;      /* clear timer */
+      bsock->timer_start = 0;     /* clear timer */
       if (errno == 0) {
-         bsock->b_errno = ENODATA;
+        bsock->b_errno = ENODATA;
       } else {
-         bsock->b_errno = errno;
+        bsock->b_errno = errno;
       }
       bsock->errors++;
       Qmsg4(bsock->jcr, M_ERROR, 0, _("Read error from %s:%s:%d: ERR=%s\n"),
-            bsock->who, bsock->host, bsock->port, bnet_strerror(bsock));
+           bsock->who, bsock->host, bsock->port, bnet_strerror(bsock));
       return BNET_ERROR;
    }
-   bsock->timer_start = 0;         /* clear timer */
+   bsock->timer_start = 0;        /* clear timer */
    bsock->in_msg_no++;
    bsock->msglen = nbytes;
    if (nbytes != pktsiz) {
       bsock->b_errno = EIO;
       bsock->errors++;
       Qmsg5(bsock->jcr, M_ERROR, 0, _("Read expected %d got %d from %s:%s:%d\n"),
-            pktsiz, nbytes, bsock->who, bsock->host, bsock->port);
+           pktsiz, nbytes, bsock->who, bsock->host, bsock->port);
       return BNET_ERROR;
    }
    /* always add a zero by to properly terminate any
@@ -269,7 +264,7 @@ int32_t bnet_recv(BSOCK * bsock)
     */
    bsock->msg[nbytes] = 0; /* terminate in case it is a string */
    sm_check(__FILE__, __LINE__, false);
-   return nbytes;                  /* return actual length of message */
+   return nbytes;                 /* return actual length of message */
 }
 
 
@@ -305,7 +300,7 @@ void bnet_suppress_error_messages(BSOCK * bsock, bool flag)
  * Transmit spooled data now to a BSOCK
  */
 int bnet_despool_to_bsock(BSOCK * bsock, void update_attr_spool_size(ssize_t size),
-                          ssize_t tsize)
+                         ssize_t tsize)
 {
    int32_t pktsiz;
    size_t nbytes;
@@ -314,27 +309,27 @@ int bnet_despool_to_bsock(BSOCK * bsock, void update_attr_spool_size(ssize_t siz
 
    rewind(bsock->spool_fd);
    while (fread((char *)&pktsiz, 1, sizeof(int32_t), bsock->spool_fd) ==
-          sizeof(int32_t)) {
+         sizeof(int32_t)) {
       size += sizeof(int32_t);
       bsock->msglen = ntohl(pktsiz);
       if (bsock->msglen > 0) {
-         if (bsock->msglen > (int32_t) sizeof_pool_memory(bsock->msg)) {
-            bsock->msg = realloc_pool_memory(bsock->msg, bsock->msglen + 1);
-         }
-         nbytes = fread(bsock->msg, 1, bsock->msglen, bsock->spool_fd);
-         if (nbytes != (size_t) bsock->msglen) {
-            berrno be;
+        if (bsock->msglen > (int32_t) sizeof_pool_memory(bsock->msg)) {
+           bsock->msg = realloc_pool_memory(bsock->msg, bsock->msglen + 1);
+        }
+        nbytes = fread(bsock->msg, 1, bsock->msglen, bsock->spool_fd);
+        if (nbytes != (size_t) bsock->msglen) {
+           berrno be;
             Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, bsock->msglen);
             Qmsg1(bsock->jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
-                  be.strerror());
-            update_attr_spool_size(tsize - last);
-            return 0;
-         }
-         size += nbytes;
-         if ((++count & 0x3F) == 0) {
-            update_attr_spool_size(size - last);
-            last = size;
-         }
+                 be.strerror());
+           update_attr_spool_size(tsize - last);
+           return 0;
+        }
+        size += nbytes;
+        if ((++count & 0x3F) == 0) {
+           update_attr_spool_size(size - last);
+           last = size;
+        }
       }
       bnet_send(bsock);
    }
@@ -342,7 +337,7 @@ int bnet_despool_to_bsock(BSOCK * bsock, void update_attr_spool_size(ssize_t siz
    if (ferror(bsock->spool_fd)) {
       berrno be;
       Qmsg1(bsock->jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
-            be.strerror());
+           be.strerror());
       return 0;
    }
    return 1;
@@ -355,7 +350,7 @@ int bnet_despool_to_bsock(BSOCK * bsock, void update_attr_spool_size(ssize_t siz
  * the length of the data packet which follows.
  *
  * Returns: false on failure
- *          true  on success
+ *         true  on success
  */
 bool bnet_send(BSOCK * bsock)
 {
@@ -367,63 +362,63 @@ bool bnet_send(BSOCK * bsock)
    }
    pktsiz = htonl((int32_t) bsock->msglen);
    /* send int32_t containing size of data packet */
-   bsock->timer_start = watchdog_time;  /* start timer */
+   bsock->timer_start = watchdog_time; /* start timer */
    bsock->timed_out = 0;
    rc = write_nbytes(bsock, (char *)&pktsiz, sizeof(int32_t));
-   bsock->timer_start = 0;         /* clear timer */
+   bsock->timer_start = 0;        /* clear timer */
    if (rc != sizeof(int32_t)) {
-      if (bsock->msglen == BNET_TERMINATE) {    /* if we were terminating */
-         bsock->terminated = 1;
-         return false;             /* ignore any errors */
+      if (bsock->msglen == BNET_TERMINATE) {   /* if we were terminating */
+        bsock->terminated = 1;
+        return false;             /* ignore any errors */
       }
       bsock->errors++;
       if (errno == 0) {
-         bsock->b_errno = EIO;
+        bsock->b_errno = EIO;
       } else {
-         bsock->b_errno = errno;
+        bsock->b_errno = errno;
       }
       if (rc < 0) {
-         if (!bsock->suppress_error_msgs && !bsock->timed_out) {
-            Qmsg4(bsock->jcr, M_ERROR, 0,
+        if (!bsock->suppress_error_msgs && !bsock->timed_out) {
+           Qmsg4(bsock->jcr, M_ERROR, 0,
                   _("Write error sending len to %s:%s:%d: ERR=%s\n"), bsock->who,
-                  bsock->host, bsock->port, bnet_strerror(bsock));
-         }
+                 bsock->host, bsock->port, bnet_strerror(bsock));
+        }
       } else {
-         Qmsg5(bsock->jcr, M_ERROR, 0,
+        Qmsg5(bsock->jcr, M_ERROR, 0,
                _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"), bsock->who,
-               bsock->host, bsock->port, bsock->msglen, rc);
+              bsock->host, bsock->port, bsock->msglen, rc);
       }
       return false;
    }
 
-   bsock->out_msg_no++;            /* increment message number */
-   if (bsock->msglen <= 0) {       /* length only? */
-      return true;                 /* yes, no data */
+   bsock->out_msg_no++;           /* increment message number */
+   if (bsock->msglen <= 0) {      /* length only? */
+      return true;                /* yes, no data */
    }
 
    /* send data packet */
-   bsock->timer_start = watchdog_time;  /* start timer */
+   bsock->timer_start = watchdog_time; /* start timer */
    bsock->timed_out = 0;
    rc = write_nbytes(bsock, bsock->msg, bsock->msglen);
-   bsock->timer_start = 0;         /* clear timer */
+   bsock->timer_start = 0;        /* clear timer */
    if (rc != bsock->msglen) {
       bsock->errors++;
       if (errno == 0) {
-         bsock->b_errno = EIO;
+        bsock->b_errno = EIO;
       } else {
-         bsock->b_errno = errno;
+        bsock->b_errno = errno;
       }
       if (rc < 0) {
-         if (!bsock->suppress_error_msgs) {
-            Qmsg5(bsock->jcr, M_ERROR, 0,
+        if (!bsock->suppress_error_msgs) {
+           Qmsg5(bsock->jcr, M_ERROR, 0,
                   _("Write error sending %d bytes to %s:%s:%d: ERR=%s\n"), 
-                  bsock->msglen, bsock->who,
-                  bsock->host, bsock->port, bnet_strerror(bsock));
-         }
+                 bsock->msglen, bsock->who,
+                 bsock->host, bsock->port, bnet_strerror(bsock));
+        }
       } else {
-         Qmsg5(bsock->jcr, M_ERROR, 0,
+        Qmsg5(bsock->jcr, M_ERROR, 0,
                _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"),
-               bsock->msglen, bsock->who, bsock->host, bsock->port, rc);
+              bsock->msglen, bsock->who, bsock->host, bsock->port, rc);
       }
       return false;
    }
@@ -433,7 +428,7 @@ bool bnet_send(BSOCK * bsock)
 /*
  * Establish a TLS connection -- server side
  *  Returns: 1 on success
- *           0 failure
+ *          0 failure
  */
 #ifdef HAVE_TLS
 int bnet_tls_server(TLS_CONTEXT *ctx, BSOCK * bsock, alist *verify_list)
@@ -458,8 +453,8 @@ int bnet_tls_server(TLS_CONTEXT *ctx, BSOCK * bsock, alist *verify_list)
       if (!tls_postconnect_verify_cn(tls, verify_list)) {
          Qmsg1(bsock->jcr, M_FATAL, 0, _("TLS certificate verification failed."
                                          " Peer certificate did not match a required commonName\n"),
-                                         bsock->host);
-         goto err;
+                                        bsock->host);
+        goto err;
       }
    }
  
@@ -474,13 +469,13 @@ err:
 /*
  * Establish a TLS connection -- client side
  * Returns: 1 on success
- *          0 failure
+ *         0 failure
  */
 int bnet_tls_client(TLS_CONTEXT *ctx, BSOCK * bsock)
 {
    TLS_CONNECTION *tls;
 
-   tls  = new_tls_connection(ctx, bsock->fd);
+   tls = new_tls_connection(ctx, bsock->fd);
    if (!tls) {
       Qmsg0(bsock->jcr, M_FATAL, 0, _("TLS connection initialization failed.\n"));
       return 0;
@@ -512,8 +507,8 @@ err:
  * the BSOCK connection.
  *
  *   Returns: 1 if data available
- *            0 if timeout
- *           -1 if error
+ *           0 if timeout
+ *          -1 if error
  */
 int bnet_wait_data(BSOCK * bsock, int sec)
 {
@@ -526,18 +521,18 @@ int bnet_wait_data(BSOCK * bsock, int sec)
    tv.tv_usec = 0;
    for (;;) {
       switch (select(bsock->fd + 1, &fdset, NULL, NULL, &tv)) {
-      case 0:                      /* timeout */
-         bsock->b_errno = 0;
-         return 0;
+      case 0:                     /* timeout */
+        bsock->b_errno = 0;
+        return 0;
       case -1:
-         bsock->b_errno = errno;
-         if (errno == EINTR || errno == EAGAIN) {
-            continue;
-         }
-         return -1;                /* error return */
+        bsock->b_errno = errno;
+        if (errno == EINTR || errno == EAGAIN) {
+           continue;
+        }
+        return -1;                /* error return */
       default:
-         bsock->b_errno = 0;
-         return 1;
+        bsock->b_errno = 0;
+        return 1;
       }
    }
 }
@@ -554,38 +549,36 @@ int bnet_wait_data_intr(BSOCK * bsock, int sec)
    FD_SET((unsigned)bsock->fd, &fdset);
    tv.tv_sec = sec;
    tv.tv_usec = 0;
-   for (;;) {
-      switch (select(bsock->fd + 1, &fdset, NULL, NULL, &tv)) {
-      case 0:                      /* timeout */
-         bsock->b_errno = 0;
-         return 0;
-      case -1:
-         bsock->b_errno = errno;
-         return -1;                /* error return */
-      default:
-         bsock->b_errno = 0;
-         return 1;
-      }
+   switch (select(bsock->fd + 1, &fdset, NULL, NULL, &tv)) {
+   case 0:                     /* timeout */
+      bsock->b_errno = 0;
+      return 0;
+   case -1:
+      bsock->b_errno = errno;
+      return -1;               /* error return */
+   default:
+      bsock->b_errno = 0;
    }
+   return 1;
 }
 
 #ifndef NETDB_INTERNAL
-#define NETDB_INTERNAL  -1         /* See errno. */
+#define NETDB_INTERNAL -1         /* See errno. */
 #endif
 #ifndef NETDB_SUCCESS
-#define NETDB_SUCCESS   0          /* No problem. */
+#define NETDB_SUCCESS  0          /* No problem. */
 #endif
 #ifndef HOST_NOT_FOUND
-#define HOST_NOT_FOUND  1          /* Authoritative Answer Host not found. */
+#define HOST_NOT_FOUND 1          /* Authoritative Answer Host not found. */
 #endif
 #ifndef TRY_AGAIN
-#define TRY_AGAIN       2          /* Non-Authoritative Host not found, or SERVERFAIL. */
+#define TRY_AGAIN      2          /* Non-Authoritative Host not found, or SERVERFAIL. */
 #endif
 #ifndef NO_RECOVERY
-#define NO_RECOVERY     3          /* Non recoverable errors, FORMERR, REFUSED, NOTIMP. */
+#define NO_RECOVERY    3          /* Non recoverable errors, FORMERR, REFUSED, NOTIMP. */
 #endif
 #ifndef NO_DATA
-#define NO_DATA         4          /* Valid name, no data record of requested type. */
+#define NO_DATA        4          /* Valid name, no data record of requested type. */
 #endif
 
 /*
@@ -594,9 +587,10 @@ int bnet_wait_data_intr(BSOCK * bsock, int sec)
 static const char *gethost_strerror()
 {
    const char *msg;
+   berrno be;
    switch (h_errno) {
    case NETDB_INTERNAL:
-      msg = strerror(errno);
+      msg = be.strerror();
       break;
    case NETDB_SUCCESS:
       msg = "No problem.";
@@ -648,17 +642,17 @@ static const char *resolv_host(int family, const char *host, dlist * addr_list)
    } else {
       char **p;
       for (p = hp->h_addr_list; *p != 0; p++) {
-         IPADDR *addr =  New(IPADDR(hp->h_addrtype));
-         addr->set_type(IPADDR::R_MULTIPLE);
-         if (addr->get_family() == AF_INET) {
-             addr->set_addr4((struct in_addr*)*p);
-         }
+        IPADDR *addr =  New(IPADDR(hp->h_addrtype));
+        addr->set_type(IPADDR::R_MULTIPLE);
+        if (addr->get_family() == AF_INET) {
+            addr->set_addr4((struct in_addr*)*p);
+        }
 #ifdef HAVE_IPV6
-         else {
-             addr->set_addr6((struct in6_addr*)*p);
-         }
+        else {
+            addr->set_addr6((struct in6_addr*)*p);
+        }
 #endif
-         addr_list->append(addr);
+        addr_list->append(addr);
       }
       V(ip_mutex);
    }
@@ -680,11 +674,11 @@ dlist *bnet_host2ipaddrs(const char *host, int family, const char **errstr)
    dlist *addr_list = New(dlist(addr, &addr->link));
    if (!host || host[0] == '\0') {
       if (family != 0) {
-         addr_list->append(add_any(family));
+        addr_list->append(add_any(family));
       } else {
-         addr_list->append(add_any(AF_INET));
+        addr_list->append(add_any(AF_INET));
 #ifdef HAVE_IPV6
-         addr_list->append(add_any(AF_INET6));
+        addr_list->append(add_any(AF_INET6));
 #endif
       }
    } else if (inet_aton(host, &inaddr)) { /* MA Bug 4 */
@@ -703,24 +697,24 @@ dlist *bnet_host2ipaddrs(const char *host, int family, const char **errstr)
 #endif
    {
       if (family != 0) {
-         errmsg = resolv_host(family, host, addr_list);
-         if (errmsg) {
-            *errstr = errmsg;
-            free_addresses(addr_list);
-            return 0;
-         }
+        errmsg = resolv_host(family, host, addr_list);
+        if (errmsg) {
+           *errstr = errmsg;
+           free_addresses(addr_list);
+           return 0;
+        }
       } else {
-         errmsg = resolv_host(AF_INET, host, addr_list);
+        errmsg = resolv_host(AF_INET, host, addr_list);
 #ifdef HAVE_IPV6
-         if (errmsg) {
-            errmsg = resolv_host(AF_INET6, host, addr_list);
-         }
+        if (errmsg) {
+           errmsg = resolv_host(AF_INET6, host, addr_list);
+        }
 #endif
-         if (errmsg) {
-            *errstr = errmsg;
-            free_addresses(addr_list);
-            return 0;
-         }
+        if (errmsg) {
+           *errstr = errmsg;
+           free_addresses(addr_list);
+           return 0;
+        }
       }
    }
    return addr_list;
@@ -733,7 +727,7 @@ dlist *bnet_host2ipaddrs(const char *host, int family, const char **errstr)
  *
  */
 static BSOCK *bnet_open(JCR * jcr, const char *name, char *host, char *service,
-                        int port, int *fatal)
+                       int port, int *fatal)
 {
    int sockfd = -1;
    dlist *addr_list;
@@ -750,9 +744,9 @@ static BSOCK *bnet_open(JCR * jcr, const char *name, char *host, char *service,
    if ((addr_list = bnet_host2ipaddrs(host, 0, &errstr)) == NULL) {
       /* Note errstr is not malloc'ed */
       Qmsg2(jcr, M_ERROR, 0, "gethostbyname() for host \"%s\" failed: ERR=%s\n",
-            host, errstr);
+           host, errstr);
       Dmsg2(100, "bnet_host2ipaddrs() for host %s failed: ERR=%s\n",
-            host, errstr);
+           host, errstr);
       *fatal = 1;
       return NULL;
    }
@@ -762,30 +756,30 @@ static BSOCK *bnet_open(JCR * jcr, const char *name, char *host, char *service,
       char allbuf[256 * 10];
       char curbuf[256];
       Dmsg2(100, "Current %sAll %s\n",
-                   ipaddr->build_address_str(curbuf, sizeof(curbuf)),
-                   build_addresses_str(addr_list, allbuf, sizeof(allbuf)));
+                  ipaddr->build_address_str(curbuf, sizeof(curbuf)),
+                  build_addresses_str(addr_list, allbuf, sizeof(allbuf)));
       /* Open a TCP socket */
       if ((sockfd = socket(ipaddr->get_family(), SOCK_STREAM, 0)) < 0) {
-         berrno be;
-         save_errno = errno;
-         *fatal = 1;
+        berrno be;
+        save_errno = errno;
+        *fatal = 1;
          Pmsg3(000, "Socket open error. proto=%d port=%d. ERR=%s\n",
-            ipaddr->get_family(), ipaddr->get_port_host_order(), be.strerror());
-         continue;
+           ipaddr->get_family(), ipaddr->get_port_host_order(), be.strerror());
+        continue;
       }
       /*
        * Keep socket from timing out from inactivity
        */
       if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) {
-         berrno be;
+        berrno be;
          Qmsg1(jcr, M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
-               be.strerror());
+              be.strerror());
       }
       /* connect to server */
       if (connect(sockfd, ipaddr->get_sockaddr(), ipaddr->get_sockaddr_len()) < 0) {
-         save_errno = errno;
-         close(sockfd);
-         continue;
+        save_errno = errno;
+        close(sockfd);
+        continue;
       }
       *fatal = 0;
       connected = true;
@@ -793,18 +787,18 @@ static BSOCK *bnet_open(JCR * jcr, const char *name, char *host, char *service,
    }
 
    if (!connected) {
-         free_addresses(addr_list);
+        free_addresses(addr_list);
       errno = save_errno;
       return NULL;
    }
    /*
     * Keep socket from timing out from inactivity
-    *   Do this a second time out of paranoia
+    *  Do this a second time out of paranoia
     */
    if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) {
       berrno be;
       Qmsg1(jcr, M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
-            be.strerror());
+           be.strerror());
    }
    BSOCK* ret =  init_bsock(jcr, sockfd, name, host, port, ipaddr->get_sockaddr());
    free_addresses(addr_list);
@@ -815,24 +809,24 @@ static BSOCK *bnet_open(JCR * jcr, const char *name, char *host, char *service,
  * Try to connect to host for max_retry_time at retry_time intervals.
  */
 BSOCK *bnet_connect(JCR * jcr, int retry_interval, int max_retry_time,
-                    const char *name, char *host, char *service, int port,
-                    int verbose)
+                   const char *name, char *host, char *service, int port,
+                   int verbose)
 {
    int i;
    BSOCK *bsock;
    int fatal = 0;
 
    for (i = 0; (bsock = bnet_open(jcr, name, host, service, port, &fatal)) == NULL;
-        i -= retry_interval) {
+       i -= retry_interval) {
       berrno be;
       if (fatal || (jcr && job_canceled(jcr))) {
-         return NULL;
+        return NULL;
       }
       Dmsg4(100, "Unable to connect to %s on %s:%d. ERR=%s\n",
-            name, host, port, be.strerror());
+           name, host, port, be.strerror());
       if (i < 0) {
-         i = 60 * 5;               /* complain again in 5 minutes */
-         if (verbose)
+        i = 60 * 5;               /* complain again in 5 minutes */
+        if (verbose)
             Qmsg4(jcr, M_WARNING, 0, "Could not connect to %s on %s:%d. ERR=%s\n"
 "Retrying ...\n", name, host, port, be.strerror());
       }
@@ -840,8 +834,8 @@ BSOCK *bnet_connect(JCR * jcr, int retry_interval, int max_retry_time,
       max_retry_time -= retry_interval;
       if (max_retry_time <= 0) {
          Qmsg4(jcr, M_FATAL, 0, _("Unable to connect to %s on %s:%d. ERR=%s\n"),
-               name, host, port, be.strerror());
-         return NULL;
+              name, host, port, be.strerror());
+        return NULL;
       }
    }
    return bsock;
@@ -865,7 +859,7 @@ const char *bnet_strerror(BSOCK * bsock)
 /*
  * Format and send a message
  *  Returns: false on error
- *           true  on success
+ *          true  on success
  */
 bool bnet_fsend(BSOCK * bs, const char *fmt, ...)
 {
@@ -886,7 +880,7 @@ bool bnet_fsend(BSOCK * bs, const char *fmt, ...)
       bs->msglen = bvsnprintf(bs->msg, maxlen, fmt, arg_ptr);
       va_end(arg_ptr);
       if (bs->msglen > 0 && bs->msglen < (maxlen - 5)) {
-         break;
+        break;
       }
       bs->msg = realloc_pool_memory(bs->msg, maxlen + maxlen / 2);
    }
@@ -898,7 +892,7 @@ bool bnet_fsend(BSOCK * bs, const char *fmt, ...)
  *  Actual size obtained is returned in bs->msglen
  *
  *  Returns: 0 on failure
- *           1 on success
+ *          1 on success
  */
 bool bnet_set_buffer_size(BSOCK * bs, uint32_t size, int rw)
 {
@@ -922,20 +916,20 @@ bool bnet_set_buffer_size(BSOCK * bs, uint32_t size, int rw)
    }
    if (rw & BNET_SETBUF_READ) {
       while ((dbuf_size > TAPE_BSIZE) && (setsockopt(bs->fd, SOL_SOCKET,
-              SO_RCVBUF, (sockopt_val_t) & dbuf_size, sizeof(dbuf_size)) < 0)) {
-         berrno be;
+             SO_RCVBUF, (sockopt_val_t) & dbuf_size, sizeof(dbuf_size)) < 0)) {
+        berrno be;
          Qmsg1(bs->jcr, M_ERROR, 0, _("sockopt error: %s\n"), be.strerror());
-         dbuf_size -= TAPE_BSIZE;
+        dbuf_size -= TAPE_BSIZE;
       }
       Dmsg1(200, "set network buffer size=%d\n", dbuf_size);
       if (dbuf_size != start_size) {
-         Qmsg1(bs->jcr, M_WARNING, 0,
+        Qmsg1(bs->jcr, M_WARNING, 0,
                _("Warning network buffer = %d bytes not max size.\n"), dbuf_size);
       }
       if (dbuf_size % TAPE_BSIZE != 0) {
-         Qmsg1(bs->jcr, M_ABORT, 0,
+        Qmsg1(bs->jcr, M_ABORT, 0,
                _("Network buffer size %d not multiple of tape block size.\n"),
-               dbuf_size);
+              dbuf_size);
       }
    }
    if (size != 0) {
@@ -946,20 +940,20 @@ bool bnet_set_buffer_size(BSOCK * bs, uint32_t size, int rw)
    start_size = dbuf_size;
    if (rw & BNET_SETBUF_WRITE) {
       while ((dbuf_size > TAPE_BSIZE) && (setsockopt(bs->fd, SOL_SOCKET,
-              SO_SNDBUF, (sockopt_val_t) & dbuf_size, sizeof(dbuf_size)) < 0)) {
-         berrno be;
+             SO_SNDBUF, (sockopt_val_t) & dbuf_size, sizeof(dbuf_size)) < 0)) {
+        berrno be;
          Qmsg1(bs->jcr, M_ERROR, 0, _("sockopt error: %s\n"), be.strerror());
-         dbuf_size -= TAPE_BSIZE;
+        dbuf_size -= TAPE_BSIZE;
       }
       Dmsg1(200, "set network buffer size=%d\n", dbuf_size);
       if (dbuf_size != start_size) {
-         Qmsg1(bs->jcr, M_WARNING, 0,
+        Qmsg1(bs->jcr, M_WARNING, 0,
                _("Warning network buffer = %d bytes not max size.\n"), dbuf_size);
       }
       if (dbuf_size % TAPE_BSIZE != 0) {
-         Qmsg1(bs->jcr, M_ABORT, 0,
+        Qmsg1(bs->jcr, M_ABORT, 0,
                _("Network buffer size %d not multiple of tape block size.\n"),
-               dbuf_size);
+              dbuf_size);
       }
    }
 
@@ -977,12 +971,14 @@ int bnet_set_nonblocking (BSOCK *bsock) {
 
    /* Get current flags */
    if((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) {
-      Emsg1(M_ABORT, 0, "fcntl F_GETFL error. ERR=%s\n", strerror(errno));
+      berrno be;
+      Emsg1(M_ABORT, 0, "fcntl F_GETFL error. ERR=%s\n", be.strerror());
    }
 
    /* Set O_NONBLOCK flag */
    if((fcntl(bsock->fd, F_SETFL, oflags|O_NONBLOCK)) < 0) {
-      Emsg1(M_ABORT, 0, "fcntl F_SETFL error. ERR=%s\n", strerror(errno));
+      berrno be;
+      Emsg1(M_ABORT, 0, "fcntl F_SETFL error. ERR=%s\n", be.strerror());
    }
 
    bsock->blocking = 0;
@@ -1008,12 +1004,14 @@ int bnet_set_blocking (BSOCK *bsock) {
    int oflags;
    /* Get current flags */
    if((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) {
-      Emsg1(M_ABORT, 0, "fcntl F_GETFL error. ERR=%s\n", strerror(errno));
+      berrno be;
+      Emsg1(M_ABORT, 0, "fcntl F_GETFL error. ERR=%s\n", be.strerror());
    }
 
    /* Set O_NONBLOCK flag */
    if((fcntl(bsock->fd, F_SETFL, oflags & ~O_NONBLOCK)) < 0) {
-      Emsg1(M_ABORT, 0, "fcntl F_SETFL error. ERR=%s\n", strerror(errno));
+      berrno be;
+      Emsg1(M_ABORT, 0, "fcntl F_SETFL error. ERR=%s\n", be.strerror());
    }
 
    bsock->blocking = 1;
@@ -1036,7 +1034,8 @@ int bnet_set_blocking (BSOCK *bsock) {
 void bnet_restore_blocking (BSOCK *bsock, int flags) {
 #ifndef WIN32
    if((fcntl(bsock->fd, F_SETFL, flags)) < 0) {
-      Emsg1(M_ABORT, 0, "fcntl F_SETFL error. ERR=%s\n", strerror(errno));
+      berrno be;
+      Emsg1(M_ABORT, 0, "fcntl F_SETFL error. ERR=%s\n", be.strerror());
    }
 
    bsock->blocking = (flags & O_NONBLOCK);
@@ -1054,7 +1053,7 @@ void bnet_restore_blocking (BSOCK *bsock, int flags) {
  *  This consists of sending a negative packet length
  *
  *  Returns: false on failure
- *           true  on success
+ *          true  on success
  */
 bool bnet_sig(BSOCK * bs, int sig)
 {
@@ -1100,7 +1099,7 @@ const char *bnet_sig_to_ascii(BSOCK * bs)
  *  This probably should be done in net_open
  */
 BSOCK *init_bsock(JCR * jcr, int sockfd, const char *who, const char *host, int port,
-                  struct sockaddr *client_addr)
+                 struct sockaddr *client_addr)
 {
    Dmsg3(100, "who=%s host=%s port=%d\n", who, host, port);
    BSOCK *bsock = (BSOCK *)malloc(sizeof(BSOCK));
@@ -1117,9 +1116,9 @@ BSOCK *init_bsock(JCR * jcr, int sockfd, const char *who, const char *host, int
    memcpy(&bsock->client_addr, client_addr, sizeof(bsock->client_addr));
    /*
     * ****FIXME**** reduce this to a few hours once
-    *   heartbeats are implemented
+    *  heartbeats are implemented
     */
-   bsock->timeout = 60 * 60 * 6 * 24;   /* 6 days timeout */
+   bsock->timeout = 60 * 60 * 6 * 24;  /* 6 days timeout */
    bsock->jcr = jcr;
    return bsock;
 }
@@ -1149,17 +1148,17 @@ void bnet_close(BSOCK * bsock)
       next = bsock->next;
       if (!bsock->duped) {
 #ifdef HAVE_TLS
-         /* Shutdown tls cleanly. */
-         if (bsock->tls) {
-            tls_bsock_shutdown(bsock);
-            free_tls_connection(bsock->tls);
-            bsock->tls = NULL;
-         }
+        /* Shutdown tls cleanly. */
+        if (bsock->tls) {
+           tls_bsock_shutdown(bsock);
+           free_tls_connection(bsock->tls);
+           bsock->tls = NULL;
+        }
 #endif /* HAVE_TLS */
-         if (bsock->timed_out) {
-            shutdown(bsock->fd, 2);     /* discard any pending I/O */
-         }
-         socketClose(bsock->fd);   /* normal close */
+        if (bsock->timed_out) {
+           shutdown(bsock->fd, 2);     /* discard any pending I/O */
+        }
+        socketClose(bsock->fd);   /* normal close */
       }
       term_bsock(bsock);
    }
@@ -1172,7 +1171,7 @@ void term_bsock(BSOCK * bsock)
       free_pool_memory(bsock->msg);
       bsock->msg = NULL;
    } else {
-      ASSERT(1 == 0);              /* double close */
+      ASSERT(1 == 0);             /* double close */
    }
    if (bsock->errmsg) {
       free_pool_memory(bsock->errmsg);
index fa4a6c46d90e98e1a985cbaa0394eaae2dfd28b7..71d36e3541d837d9dd9f512a80b33c1d275d0ce5 100644 (file)
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000-2004 Kern Sibbald and John Walker
+   Copyright (C) 2000-2005 Kern Sibbald
 
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
+   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
+   file LICENSE in the main source directory.
 
-   This library is distributed in the hope that it will be useful,
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
index 2cef7c32e9ad374406947ebc16ed2f4c2c9d0c86..f5c2b5f11e17ae5dae7c3f0d7897474d1ed51856 100644 (file)
@@ -395,12 +395,12 @@ static const char *pool_name(int pool)
  */
 void print_memory_pool_stats()
 {
-   Dmsg0(-1, "Pool   Maxsize  Maxused  Inuse\n");
+   Pmsg0(-1, "Pool   Maxsize  Maxused  Inuse\n");
    for (int i=0; i<=PM_MAX; i++)
-      Dmsg4(-1, "%5s  %7d  %7d  %5d\n", pool_name(i), pool_ctl[i].max_allocated,
+      Pmsg4(-1, "%5s  %7d  %7d  %5d\n", pool_name(i), pool_ctl[i].max_allocated,
         pool_ctl[i].max_used, pool_ctl[i].in_use);
 
-   Dmsg0(-1, "\n");
+   Pmsg0(-1, "\n");
 }
 
 #else
index 2e14810576a36dffb21e9d188d239444d31c0f8c..8151ccd28dbe9d1f594e128e9bbaac127e2ae759 100755 (executable)
@@ -6,28 +6,23 @@
  *   Version $Id$
  *
  */
-
 /*
-   Copyright (C) 2000-2004 Kern Sibbald and John Walker
+   Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
 
+
 #include "bacula.h"
 #include "jcr.h"
 
@@ -760,10 +755,10 @@ d_msg(const char *file, int line, int level, const char *fmt,...)
     char      buf[5000];
     int       len;
     va_list   arg_ptr;
-    int       details = TRUE;
+    bool      details = true;
 
     if (level < 0) {
-       details = FALSE;
+       details = false;
        level = -level;
     }
 
index c84f4cbbb0b3941aa11d9f49afb346cd20ab3ed1..d094e4c4735f7548a7412f473dad267572db716d 100755 (executable)
@@ -5,22 +5,17 @@
  *
 */
 /*
-   Copyright (C) 2002-2004 Kern Sibbald and John Walker
+   Copyright (C) 2002-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -205,7 +200,7 @@ TREE_NODE *insert_tree_node(char *path, char *fname, int type,
    }
    if (*fname) {
       if (!parent) {                 /* if no parent, we need to make one */
-        Dmsg1(100, "make_tree_path for %s\n", path);
+         Dmsg1(100, "make_tree_path for %s\n", path);
         path_len = strlen(path);     /* get new length */
         if (path_len == root->cached_path_len &&
             strcmp(path, root->cached_path) == 0) {
@@ -216,7 +211,7 @@ TREE_NODE *insert_tree_node(char *path, char *fname, int type,
            parent = make_tree_path(path, root);
            root->cached_parent = parent;
         }
-        Dmsg1(100, "parent=%s\n", parent->fname);
+         Dmsg1(100, "parent=%s\n", parent->fname);
       }
    } else {
       fname = path;
@@ -336,7 +331,7 @@ static TREE_NODE *search_and_insert_tree_node(char *fname, int type,
         if (sibling == first_child(parent)) { /* if sibling was at head of list */
            parent->child_ = NULL;        /* force parent to be updated below */
         }
-        Dmsg2(000, "insert before sibling->fname=%s fname=%s\n", sibling->fname, fname);
+         Dmsg2(000, "insert before sibling->fname=%s fname=%s\n", sibling->fname, fname);
         break;
       }
       /* Found it */
@@ -555,7 +550,7 @@ void FillDirectoryTree(char *path, TREE_ROOT *root, TREE_NODE *parent)
       bstrncpy(file, dir->d_name, sizeof(file));
       snprintf(pathbuf, MAXPATHLEN-1, "%s/%s", path, file);
       if (lstat(pathbuf, &statbuf) < 0) {
-        printf("lstat() failed. ERR=%s\n", strerror(errno));
+         printf("lstat() failed. ERR=%s\n", strerror(errno));
         continue;
       }
 //      printf("got file=%s, pathbuf=%s\n", file, pathbuf);
@@ -576,7 +571,7 @@ void FillDirectoryTree(char *path, TREE_ROOT *root, TREE_NODE *parent)
         type = TN_FILE; /* sock */
       else {
         type = TN_FILE;
-        printf("Unknown file type: 0x%x\n", statbuf.st_mode);
+         printf("Unknown file type: 0x%x\n", statbuf.st_mode);
       }
 
       Dmsg2(100, "Doing: %d %s\n", type, pathbuf);
@@ -584,7 +579,7 @@ void FillDirectoryTree(char *path, TREE_ROOT *root, TREE_NODE *parent)
       node->FileIndex = ++FileIndex;
       parent = insert_tree_node(pathbuf, node, root, parent);
       if (S_ISDIR(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode)) {
-        Dmsg2(100, "calling fill. pathbuf=%s, file=%s\n", pathbuf, file);
+         Dmsg2(100, "calling fill. pathbuf=%s, file=%s\n", pathbuf, file);
         FillDirectoryTree(pathbuf, root, node);
       }
    }
@@ -615,7 +610,7 @@ void print_tree(char *path, TREE_NODE *tree)
       termchr = "";
       break;
    }
-   Dmsg3(-1, "%s/%s%s\n", path, tree->fname, termchr);
+   Pmsg3(-1, "%s/%s%s\n", path, tree->fname, termchr);
    switch (tree->type) {
    case TN_FILE:
    case TN_NEWDIR:
index c287b555219e7279bc5dd8726a4f118a4c6f196d..fd1864ad84bf11f69721b3bc767a80ccc02cab26 100644 (file)
@@ -9,19 +9,14 @@
    Copyright (C) 2002-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -55,8 +50,8 @@ DCR *new_dcr(JCR *jcr, DEVICE *dev)
    dcr->max_spool_size = dev->device->max_spool_size;
    /* Attach this dcr only if dev is initialized */
    if (dev->fd != 0 && jcr && jcr->JobType != JT_SYSTEM) {
-      dev->attached_dcrs->append(dcr);  /* attach dcr to device */
-//    jcr->dcrs->append(dcr);         /* put dcr in list for Job */
+      dev->attached_dcrs->append(dcr); /* attach dcr to device */
+//    jcr->dcrs->append(dcr);        /* put dcr in list for Job */
    }
    return dcr;
 }
@@ -75,13 +70,13 @@ static void remove_dcr_from_dcrs(DCR *dcr)
       DCR *ldcr;
       int num = jcr->dcrs->size();
       for (i=0; i < num; i++) {
-         ldcr = (DCR *)jcr->dcrs->get(i);
-         if (ldcr == dcr) {
-            jcr->dcrs->remove(i);
-            if (jcr->dcr == dcr) {
-               jcr->dcr = NULL;
-            }
-         }
+        ldcr = (DCR *)jcr->dcrs->get(i);
+        if (ldcr == dcr) {
+           jcr->dcrs->remove(i);
+           if (jcr->dcr == dcr) {
+              jcr->dcr = NULL;
+           }
+        }
       }
    }
 }
@@ -105,15 +100,15 @@ void free_dcr(DCR *dcr)
       dev->num_writers--;
       if (dev->num_writers < 0) {
          Jmsg1(dcr->jcr, M_ERROR, 0, _("Hey! num_writers=%d!!!!\n"), dev->num_writers);
-         dev->num_writers = 0;
-         dcr->reserved_device = false;
+        dev->num_writers = 0;
+        dcr->reserved_device = false;
       }
       unlock_device(dev);
    }
 
    /* Detach this dcr only if the dev is initialized */
    if (dev->fd != 0 && jcr && jcr->JobType != JT_SYSTEM) {
-      dev->attached_dcrs->remove(dcr);  /* detach dcr from device */
+      dev->attached_dcrs->remove(dcr); /* detach dcr from device */
 //    remove_dcr_from_dcrs(dcr);      /* remove dcr from jcr list */
    }
    if (dcr->block) {
@@ -145,15 +140,15 @@ bool reserve_device_for_read(DCR *dcr)
 
    dev->block(BST_DOING_ACQUIRE);
 
-   if (device_is_unmounted(dev)) {             
+   if (device_is_unmounted(dev)) {            
       Mmsg(jcr->errmsg, _("Device %s is BLOCKED due to user unmount.\n"),
-           dev->print_name());
+          dev->print_name());
       goto bail_out;
    }
 
    if (dev->is_busy()) {
       Mmsg1(jcr->errmsg, _("Device %s is busy.\n"),
-            dev->print_name());
+           dev->print_name());
       goto bail_out;
    }
 
@@ -174,7 +169,7 @@ bail_out:
  *  leave the block pointers just after the label.
  *
  *  Returns: NULL if failed for any reason
- *           dcr  if successful
+ *          dcr  if successful
  */
 DCR *acquire_device_for_read(DCR *dcr)
 {
@@ -192,7 +187,7 @@ DCR *acquire_device_for_read(DCR *dcr)
 
    if (dev->num_writers > 0) {
       Jmsg2(jcr, M_FATAL, 0, _("Num_writers=%d not zero. Job %d canceled.\n"), 
-         dev->num_writers, jcr->JobId);
+        dev->num_writers, jcr->JobId);
       goto get_out;
    }
 
@@ -207,15 +202,14 @@ DCR *acquire_device_for_read(DCR *dcr)
       vol = vol->next;
    }
    if (!vol) {
-      goto get_out;                   /* should not happen */   
+      goto get_out;                  /* should not happen */   
    }
    bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName));
 
    init_device_wait_timers(dcr);
 
-   tape_previously_mounted = dev->can_read() ||
-                             dev->can_append() ||
-                             dev->is_labeled();
+   tape_previously_mounted = dev->can_read() || dev->can_append() ||
+                            dev->is_labeled();
    tape_initially_mounted = tape_previously_mounted;
 
 
@@ -228,10 +222,10 @@ DCR *acquire_device_for_read(DCR *dcr)
    dev->num_parts = dcr->VolCatInfo.VolCatParts;
    
    for (i=0; i<5; i++) {
-      dev->clear_labeled();              /* force reread of label */
+      dev->clear_labeled();             /* force reread of label */
       if (job_canceled(jcr)) {
          Mmsg1(dev->errmsg, _("Job %d canceled.\n"), jcr->JobId);
-         goto get_out;                /* error return */
+        goto get_out;                /* error return */
       }
       /*
        * This code ensures that the device is ready for
@@ -240,91 +234,91 @@ DCR *acquire_device_for_read(DCR *dcr)
        */
       for ( ; !dev->is_open(); ) {
          Dmsg1(120, "bstored: open vol=%s\n", dcr->VolumeName);
-         if (open_dev(dev, dcr->VolumeName, OPEN_READ_ONLY) < 0) {
-            if (dev->dev_errno == EIO) {   /* no tape loaded */
+        if (open_dev(dev, dcr->VolumeName, OPEN_READ_ONLY) < 0) {
+           if (dev->dev_errno == EIO) {   /* no tape loaded */
               Jmsg3(jcr, M_WARNING, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"),
-                    dev->print_name(), dcr->VolumeName, strerror_dev(dev));
-               goto default_path;
-            }
-            
-            /* If we have a dvd that requires mount, 
-             * we need to try to open the label, so the info can be reported
-             * if a wrong volume has been mounted. */
-            if (dev->is_dvd() && (dcr->VolCatInfo.VolCatParts > 0)) {
-               break;
-            }
-            
+                   dev->print_name(), dcr->VolumeName, strerror_dev(dev));
+              goto default_path;
+           }
+           
+           /* If we have a dvd that requires mount, 
+            * we need to try to open the label, so the info can be reported
+            * if a wrong volume has been mounted. */
+           if (dev->is_dvd() && (dcr->VolCatInfo.VolCatParts > 0)) {
+              break;
+           }
+           
             Jmsg3(jcr, M_FATAL, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"),
-                dev->print_name(), dcr->VolumeName, strerror_dev(dev));
-            goto get_out;
-         }
+               dev->print_name(), dcr->VolumeName, strerror_dev(dev));
+           goto get_out;
+        }
          Dmsg1(129, "open_dev %s OK\n", dev->print_name());
       }
       
       if (dev->is_dvd()) {
-         vol_label_status = read_dev_volume_label_guess(dcr, 0);
+        vol_label_status = read_dev_volume_label_guess(dcr, 0);
       } else {
-         vol_label_status = read_dev_volume_label(dcr);
+        vol_label_status = read_dev_volume_label(dcr);
       }
       
       Dmsg0(200, "calling read-vol-label\n");
       switch (vol_label_status) {
       case VOL_OK:
-         vol_ok = true;
-         memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
-         break;                    /* got it */
+        vol_ok = true;
+        memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+        break;                    /* got it */
       case VOL_IO_ERROR:
-         /*
-          * Send error message generated by read_dev_volume_label()
-          *  only we really had a tape mounted. This supresses superfluous
-          *  error messages when nothing is mounted.
-          */
-         if (tape_previously_mounted) {
+        /*
+         * Send error message generated by read_dev_volume_label()
+         *  only we really had a tape mounted. This supresses superfluous
+         *  error messages when nothing is mounted.
+         */
+        if (tape_previously_mounted) {
             Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
-         }
-         goto default_path;
+        }
+        goto default_path;
       case VOL_NAME_ERROR:
-         if (tape_initially_mounted) {
-            tape_initially_mounted = false;
-            goto default_path;
-         }
-         /* Fall through */
+        if (tape_initially_mounted) {
+           tape_initially_mounted = false;
+           goto default_path;
+        }
+        /* Fall through */
       default:
          Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg);
 default_path:
-         tape_previously_mounted = true;
-         
-         /* If the device requires mount, close it, so the device can be ejected.
-          * FIXME: This should perhaps be done for all devices. */
-         if (dev_cap(dev, CAP_REQMOUNT)) {
-            force_close_dev(dev);
-         }
-         
-         /* Call autochanger only once unless ask_sysop called */
-         if (try_autochanger) {
-            int stat;
+        tape_previously_mounted = true;
+        
+        /* If the device requires mount, close it, so the device can be ejected.
+         * FIXME: This should perhaps be done for all devices. */
+        if (dev_cap(dev, CAP_REQMOUNT)) {
+           force_close_dev(dev);
+        }
+        
+        /* Call autochanger only once unless ask_sysop called */
+        if (try_autochanger) {
+           int stat;
             Dmsg2(200, "calling autoload Vol=%s Slot=%d\n",
-               dcr->VolumeName, dcr->VolCatInfo.Slot);
-            stat = autoload_device(dcr, 0, NULL);
-            if (stat > 0) {
-               try_autochanger = false;
-               continue;              /* try reading volume mounted */
-            }
-         }
-         
-         /* Mount a specific volume and no other */
+              dcr->VolumeName, dcr->VolCatInfo.Slot);
+           stat = autoload_device(dcr, 0, NULL);
+           if (stat > 0) {
+              try_autochanger = false;
+              continue;              /* try reading volume mounted */
+           }
+        }
+        
+        /* Mount a specific volume and no other */
          Dmsg0(200, "calling dir_ask_sysop\n");
-         if (!dir_ask_sysop_to_mount_volume(dcr)) {
-            goto get_out;             /* error return */
-         }
-         try_autochanger = true;      /* permit using autochanger again */
-         continue;                    /* try reading again */
+        if (!dir_ask_sysop_to_mount_volume(dcr)) {
+           goto get_out;             /* error return */
+        }
+        try_autochanger = true;      /* permit using autochanger again */
+        continue;                    /* try reading again */
       } /* end switch */
       break;
    } /* end for loop */
    if (!vol_ok) {
       Jmsg1(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s.\n"),
-            dev->print_name());
+           dev->print_name());
       goto get_out;
    }
 
@@ -397,8 +391,8 @@ bail_out:
 
 /*
  * Returns: 1 if drive can be reserved
- *          0 if we should wait
- *         -1 on error
+ *         0 if we should wait
+ *        -1 on error
  */
 static int can_reserve_drive(DCR *dcr) 
 {
@@ -409,21 +403,21 @@ static int can_reserve_drive(DCR *dcr)
     */
    if (!dev->can_append() && dev->num_writers == 0) {
       /* Now check if there are any reservations on the drive */
-      if (dev->reserved_device) {           
-         /* Yes, now check if we want the same Pool and pool type */
-         if (strcmp(dev->pool_name, dcr->pool_name) == 0 &&
-             strcmp(dev->pool_type, dcr->pool_type) == 0) {
-            /* OK, compatible device */
-         } else {
-            /* Drive not suitable for us */
-            return 0;                 /* wait */
-         }
+      if (dev->reserved_device) {          
+        /* Yes, now check if we want the same Pool and pool type */
+        if (strcmp(dev->pool_name, dcr->pool_name) == 0 &&
+            strcmp(dev->pool_type, dcr->pool_type) == 0) {
+           /* OK, compatible device */
+        } else {
+           /* Drive not suitable for us */
+           return 0;                 /* wait */
+        }
       } else {
-         /* Device is available but not yet reserved, reserve it for us */
-         bstrncpy(dev->pool_name, dcr->pool_name, sizeof(dev->pool_name));
-         bstrncpy(dev->pool_type, dcr->pool_type, sizeof(dev->pool_type));
+        /* Device is available but not yet reserved, reserve it for us */
+        bstrncpy(dev->pool_name, dcr->pool_name, sizeof(dev->pool_name));
+        bstrncpy(dev->pool_type, dcr->pool_type, sizeof(dev->pool_type));
       }
-      return 1;                       /* reserve drive */
+      return 1;                      /* reserve drive */
    }
 
    /*
@@ -444,19 +438,19 @@ static int can_reserve_drive(DCR *dcr)
       Dmsg0(190, "device already in append.\n");
       /* Yes, now check if we want the same Pool and pool type */
       if (strcmp(dev->pool_name, dcr->pool_name) == 0 &&
-          strcmp(dev->pool_type, dcr->pool_type) == 0) {
-         /* OK, compatible device */
+         strcmp(dev->pool_type, dcr->pool_type) == 0) {
+        /* OK, compatible device */
       } else {
-         /* Drive not suitable for us */
+        /* Drive not suitable for us */
          Jmsg(jcr, M_WARNING, 0, _("Device %s is busy writing on another Volume.\n"), dev->print_name());
-         return 0;                    /* wait */
+        return 0;                    /* wait */
       }
    } else {
       Pmsg0(000, "Logic error!!!! Should not get here.\n");
       Jmsg0(jcr, M_FATAL, 0, _("Logic error!!!! Should not get here.\n"));
-      return -1;                      /* error, should not get here */
+      return -1;                     /* error, should not get here */
    }
-   return 1;                          /* reserve drive */
+   return 1;                         /* reserve drive */
 }
 
 /*
@@ -464,7 +458,7 @@ static int can_reserve_drive(DCR *dcr)
  *  If this is the first one, we read the label.
  *
  *  Returns: NULL if failed for any reason
- *           dcr if successful.
+ *          dcr if successful.
  *   Note, normally reserve_device_for_append() is called
  *   before this routine.
  */
@@ -507,34 +501,34 @@ DCR *acquire_device_for_append(DCR *dcr)
        */
       bstrncpy(dcr->VolumeName, dev->VolHdr.VolName, sizeof(dcr->VolumeName));
       if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE) &&
-          !(dir_find_next_appendable_volume(dcr) &&
-            strcmp(dev->VolHdr.VolName, dcr->VolumeName) == 0)) { /* wrong tape mounted */
+         !(dir_find_next_appendable_volume(dcr) &&
+           strcmp(dev->VolHdr.VolName, dcr->VolumeName) == 0)) { /* wrong tape mounted */
          Dmsg0(190, "Wrong tape mounted.\n");
-         if (dev->num_writers != 0 || dev->reserved_device) {
+        if (dev->num_writers != 0 || dev->reserved_device) {
             Jmsg(jcr, M_FATAL, 0, _("Device %s is busy writing on another Volume.\n"), dev->print_name());
-            goto get_out;
-         }
-         /* Wrong tape mounted, release it, then fall through to get correct one */
+           goto get_out;
+        }
+        /* Wrong tape mounted, release it, then fall through to get correct one */
          Dmsg0(190, "Wrong tape mounted, release and try mount.\n");
-         release = true;
-         do_mount = true;
+        release = true;
+        do_mount = true;
       } else {
-         /*
-          * At this point, the correct tape is already mounted, so
-          *   we do not need to do mount_next_write_volume(), unless
-          *   we need to recycle the tape.
-          */
+        /*
+         * At this point, the correct tape is already mounted, so
+         *   we do not need to do mount_next_write_volume(), unless
+         *   we need to recycle the tape.
+         */
           recycle = strcmp(dcr->VolCatInfo.VolCatStatus, "Recycle") == 0;
           Dmsg1(190, "Correct tape mounted. recycle=%d\n", recycle);
-          if (recycle && dev->num_writers != 0) {
+         if (recycle && dev->num_writers != 0) {
              Jmsg(jcr, M_FATAL, 0, _("Cannot recycle volume \"%s\""
                   " on device %s because it is in use by another job.\n"),
-                  dev->VolHdr.VolName, dev->print_name());
-             goto get_out;
-          }
-          if (dev->num_writers == 0) {
-             memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
-          }
+                 dev->VolHdr.VolName, dev->print_name());
+            goto get_out;
+         }
+         if (dev->num_writers == 0) {
+            memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+         }
        }
    } else {
       /* Not already in append mode, so mount the device */
@@ -547,16 +541,16 @@ DCR *acquire_device_for_append(DCR *dcr)
       Dmsg0(190, "Do mount_next_write_vol\n");
       bool mounted = mount_next_write_volume(dcr, release);
       if (!mounted) {
-         if (!job_canceled(jcr)) {
+        if (!job_canceled(jcr)) {
             /* Reduce "noise" -- don't print if job canceled */
             Jmsg(jcr, M_FATAL, 0, _("Could not ready device %s for append.\n"),
-               dev->print_name());
-         }
-         goto get_out;
+              dev->print_name());
+        }
+        goto get_out;
       }
    }
 
-   dev->num_writers++;                /* we are now a writer */
+   dev->num_writers++;               /* we are now a writer */
    if (jcr->NumVolumes == 0) {
       jcr->NumVolumes = 1;
    }
@@ -595,7 +589,7 @@ bool release_device(DCR *dcr)
    }
 
    if (dev->can_read()) {
-      dev->clear_read();              /* clear read bit */
+      dev->clear_read();             /* clear read bit */
 
       /******FIXME**** send read volume usage statistics to director */
 
@@ -610,26 +604,26 @@ bool release_device(DCR *dcr)
       Dmsg1(100, "There are %d writers in release_device\n", dev->num_writers);
       if (dev->is_labeled()) {
          Dmsg0(100, "dir_create_jobmedia_record. Release\n");
-         if (!dev->at_weot() && !dir_create_jobmedia_record(dcr)) {
+        if (!dev->at_weot() && !dir_create_jobmedia_record(dcr)) {
             Jmsg(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
-               dcr->VolCatInfo.VolCatName, jcr->Job);
-         }
-         /* If no more writers, write an EOF */
-         if (!dev->num_writers && dev->can_write()) {
-            weof_dev(dev, 1);
-            write_ansi_ibm_labels(dcr, ANSI_EOF_LABEL, dev->VolHdr.VolName);
-         }
-         if (!dev->at_weot()) {
-            dev->VolCatInfo.VolCatFiles = dev->file;   /* set number of files */
-            dev->VolCatInfo.VolCatJobs++;              /* increment number of jobs */
-            /* Note! do volume update before close, which zaps VolCatInfo */
+              dcr->VolCatInfo.VolCatName, jcr->Job);
+        }
+        /* If no more writers, write an EOF */
+        if (!dev->num_writers && dev->can_write()) {
+           weof_dev(dev, 1);
+           write_ansi_ibm_labels(dcr, ANSI_EOF_LABEL, dev->VolHdr.VolName);
+        }
+        if (!dev->at_weot()) {
+           dev->VolCatInfo.VolCatFiles = dev->file;   /* set number of files */
+           dev->VolCatInfo.VolCatJobs++;              /* increment number of jobs */
+           /* Note! do volume update before close, which zaps VolCatInfo */
             Dmsg0(100, "dir_update_vol_info. Release0\n");
-            dir_update_volume_info(dcr, false); /* send Volume info to Director */
-         }
+           dir_update_volume_info(dcr, false); /* send Volume info to Director */
+        }
       }
 
    } else {
-      /*                
+      /*               
        * If we reach here, it is most likely because the job
        *   has failed, since the device is not in read mode and
        *   there are no writers. It was probably reserved.
@@ -652,17 +646,17 @@ bool release_device(DCR *dcr)
       alert = edit_device_codes(dcr, alert, dcr->device->alert_command, "");
       bpipe = open_bpipe(alert, 0, "r");
       if (bpipe) {
-         while (fgets(line, sizeof(line), bpipe->rfd)) {
+        while (fgets(line, sizeof(line), bpipe->rfd)) {
             Jmsg(jcr, M_ALERT, 0, _("Alert: %s"), line);
-         }
-         status = close_bpipe(bpipe);
+        }
+        status = close_bpipe(bpipe);
       } else {
-         status = errno;
+        status = errno;
       }
       if (status != 0) {
-         berrno be;
+        berrno be;
          Jmsg(jcr, M_ALERT, 0, _("3997 Bad alert command: %s: ERR=%s.\n"),
-              alert, be.strerror(status));
+             alert, be.strerror(status));
       }
 
       Dmsg1(400, "alert status=%d\n", status);
index a43e07493c9940433a7c1af7de94a4bdc199bd07..48efb123464c34cf1be257baa2a1a72dd7269949 100644 (file)
@@ -2,18 +2,18 @@
  *
  *   dev.c  -- low level operations on device (storage device)
  *
- *              Kern Sibbald, MM
+ *             Kern Sibbald, MM
  *
  *     NOTE!!!! None of these routines are reentrant. You must
- *        use lock_device() and unlock_device() at a higher level,
- *        or use the xxx_device() equivalents.  By moving the
- *        thread synchronization to a higher level, we permit
+ *       use lock_device() and unlock_device() at a higher level,
+ *       or use the xxx_device() equivalents.  By moving the
+ *       thread synchronization to a higher level, we permit
  *        the higher level routines to "seize" the device and
- *        to carry out operations without worrying about who
- *        set what lock (i.e. race conditions).
+ *       to carry out operations without worrying about who
+ *       set what lock (i.e. race conditions).
  *
  *     Note, this is the device dependent code, and my have
- *           to be modified for each system, but is meant to
+ *          to be modified for each system, but is meant to
  *           be as "generic" as possible.
  *
  *     The purpose of this code is to develop a SIMPLE Storage
@@ -120,10 +120,10 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device)
    if (stat(device->device_name, &statp) < 0) {
       berrno be;
       if (dev) {
-         dev->dev_errno = errno;
+        dev->dev_errno = errno;
       }
       Jmsg2(jcr, M_ERROR, 0, _("Unable to stat device %s: ERR=%s\n"), 
-         device->device_name, be.strerror());
+        device->device_name, be.strerror());
       return NULL;
    }
    
@@ -138,10 +138,10 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device)
       fifo = true;
    } else if (!(device->cap_bits & CAP_REQMOUNT)) {
       if (dev) {
-         dev->dev_errno = ENODEV;
+        dev->dev_errno = ENODEV;
       }
       Jmsg2(jcr, M_ERROR, 0, _("%s is an unknown device type. Must be tape or directory. st_mode=%x\n"),
-         device->device_name, statp.st_mode);
+        device->device_name, statp.st_mode);
       return NULL;
    }
    if (!dev) {
@@ -198,11 +198,11 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device)
     */
    if (dev->is_file() && device->cap_bits & CAP_REQMOUNT) {
       if (stat(device->mount_point, &statp) < 0) {
-         berrno be;
-         dev->dev_errno = errno;
+        berrno be;
+        dev->dev_errno = errno;
          Jmsg2(jcr, M_ERROR, 0, _("Unable to stat mount point %s: ERR=%s\n"), 
-            device->mount_point, be.strerror());
-         return NULL;
+           device->mount_point, be.strerror());
+        return NULL;
       }
       if (!device->mount_command || !device->unmount_command) {
          Jmsg0(jcr, M_ERROR_TERM, 0, _("Mount and unmount commands must defined for a device which requires mount.\n"));
@@ -215,12 +215,12 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device)
 
    if (dev->max_block_size > 1000000) {
       Jmsg3(jcr, M_ERROR, 0, _("Block size %u on device %s is too large, using default %u\n"),
-         dev->max_block_size, dev->print_name(), DEFAULT_BLOCK_SIZE);
+        dev->max_block_size, dev->print_name(), DEFAULT_BLOCK_SIZE);
       dev->max_block_size = 0;
    }
    if (dev->max_block_size % TAPE_BSIZE != 0) {
       Jmsg2(jcr, M_WARNING, 0, _("Max block size %u not multiple of device %s block size.\n"),
-         dev->max_block_size, dev->print_name());
+        dev->max_block_size, dev->print_name());
    }
 
    dev->errmsg = get_pool_memory(PM_EMSG);
@@ -269,7 +269,7 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device)
  * initialize buffer pointers.
  *
  * Returns:  -1  on error
- *           fd  on success
+ *          fd  on success
  *
  * Note, for a tape, the VolName is the name we give to the
  *    volume (not really used here), but for a file, the
@@ -282,9 +282,9 @@ open_dev(DEVICE *dev, char *VolName, int mode)
 {
    if (dev->is_open()) {
       if (dev->openmode == mode) {
-         return dev->fd;
+        return dev->fd;
       } else {
-         close(dev->fd);              /* close so correct mode will be used */
+        close(dev->fd);              /* close so correct mode will be used */
       }
    }
    if (VolName) {
@@ -294,7 +294,7 @@ open_dev(DEVICE *dev, char *VolName, int mode)
    }
 
    Dmsg3(29, "open_dev: tape=%d dev_name=%s vol=%s\n", dev->is_tape(),
-         dev->dev_name, dev->VolCatInfo.VolCatName);
+        dev->dev_name, dev->VolCatInfo.VolCatName);
    dev->state &= ~(ST_LABEL|ST_APPEND|ST_READ|ST_EOT|ST_WEOT|ST_EOF);
    dev->label_type = B_BACULA_LABEL;
    if (dev->is_tape() || dev->is_fifo()) {
@@ -342,27 +342,27 @@ open_again:
       Dmsg2(500, "Open error errno=%d ERR=%s\n", errno, be.strerror());
       if (errno == EINTR || errno == EAGAIN) {
          Dmsg0(500, "Continue open\n");
-         continue;
+        continue;
       }
       /* Busy wait for specified time (default = 5 mins) */
       if (errno == EBUSY && timeout-- > 0) {
          Dmsg2(100, "Device %s busy. ERR=%s\n", dev->print_name(), be.strerror());
-         bmicrosleep(1, 0);
-         continue;
+        bmicrosleep(1, 0);
+        continue;
       }
       /* IO error (no volume) try 10 times every 6 seconds */
       if (errno == EIO && ioerrcnt-- > 0) {
-         bmicrosleep(5, 0);
+        bmicrosleep(5, 0);
          Dmsg0(500, "Continue open\n");
-         continue;
+        continue;
       }
       dev->dev_errno = errno;
       Mmsg2(dev->errmsg, _("Unable to open device %s: ERR=%s\n"),
-            dev->print_name(), be.strerror(dev->dev_errno));
+           dev->print_name(), be.strerror(dev->dev_errno));
       /* Stop any open timer we set */
       if (dev->tid) {
-         stop_thread_timer(dev->tid);
-         dev->tid = 0;
+        stop_thread_timer(dev->tid);
+        dev->tid = 0;
       }
       Emsg0(M_FATAL, 0, dev->errmsg);
       break;
@@ -370,16 +370,16 @@ open_again:
    if (dev->fd >= 0) {
       /* If opened in non-block mode, close it an open it normally */
       if (nonblocking) {
-         nonblocking = 0;
-         close(dev->fd);
-         goto open_again;
+        nonblocking = 0;
+        close(dev->fd);
+        goto open_again;
       }
-      dev->openmode = mode;               /* save open mode */
+      dev->openmode = mode;              /* save open mode */
       dev->dev_errno = 0;
       dev->state |= ST_OPENED;
       dev->use_count = 1;
-      update_pos_dev(dev);                /* update position */
-      set_os_device_parameters(dev);      /* do system dependent stuff */
+      update_pos_dev(dev);               /* update position */
+      set_os_device_parameters(dev);     /* do system dependent stuff */
       Dmsg0(500, "Open OK\n");
    }
    /* Stop any open() timer we started */
@@ -399,7 +399,7 @@ static void open_file_device(DEVICE *dev, int mode)
    struct stat filestat;
    /*
     * Handle opening of File Archive (not a tape)
-    */     
+    */    
    if (dev->part == 0) {
       dev->file_size = 0;
    }
@@ -413,7 +413,7 @@ static void open_file_device(DEVICE *dev, int mode)
    
    if (dev->VolCatInfo.VolCatName[0] == 0) {
       Mmsg(dev->errmsg, _("Could not open file device %s. No Volume name given.\n"),
-         dev->print_name());
+        dev->print_name());
       dev->fd = -1;
       return;
    }
@@ -421,18 +421,18 @@ static void open_file_device(DEVICE *dev, int mode)
 
    if (mount_dev(dev, 1) < 0) {
       Mmsg(dev->errmsg, _("Could not mount device %s.\n"),
-           dev->print_name());
+          dev->print_name());
       Emsg0(M_FATAL, 0, dev->errmsg);
       dev->fd = -1;
       return;
    }
-         
+        
    Dmsg2(29, "open_dev: device is disk %s (mode:%d)\n", archive_name.c_str(), mode);
    dev->openmode = mode;
    
    /*
     * If we are not trying to access the last part, set mode to 
-    *   OPEN_READ_ONLY as writing would be an error.
+    *  OPEN_READ_ONLY as writing would be an error.
     */
    if (dev->part < dev->num_parts) {
       mode = OPEN_READ_ONLY;
@@ -452,21 +452,21 @@ static void open_file_device(DEVICE *dev, int mode)
       berrno be;
       dev->dev_errno = errno;
       Mmsg2(dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(), 
-            be.strerror());
+           be.strerror());
       Emsg0(M_FATAL, 0, dev->errmsg);
    } else {
       dev->dev_errno = 0;
       dev->state |= ST_OPENED;
       dev->use_count = 1;
-      update_pos_dev(dev);                /* update position */
+      update_pos_dev(dev);               /* update position */
       if (fstat(dev->fd, &filestat) < 0) {
-         berrno be;
-         dev->dev_errno = errno;
+        berrno be;
+        dev->dev_errno = errno;
          Mmsg2(dev->errmsg, _("Could not fstat: %s, ERR=%s\n"), archive_name.c_str(), 
-               be.strerror());
-         Emsg0(M_FATAL, 0, dev->errmsg);
+              be.strerror());
+        Emsg0(M_FATAL, 0, dev->errmsg);
       } else {
-         dev->part_size = filestat.st_size;
+        dev->part_size = filestat.st_size;
       }
    }
    Dmsg4(29, "open_dev: disk fd=%d opened, part=%d/%d, part_size=%u\n", dev->fd, dev->part, dev->num_parts, dev->part_size);
@@ -488,7 +488,7 @@ bool _rewind_dev(char *file, int line, DEVICE *dev)
 /*
  * Rewind the device.
  *  Returns: true  on success
- *           false on failure
+ *          false on failure
  */
 bool rewind_dev(DEVICE *dev)
 {
@@ -499,7 +499,7 @@ bool rewind_dev(DEVICE *dev)
    if (dev->fd < 0) {
       dev->dev_errno = EBADF;
       Mmsg1(dev->errmsg, _("Bad call to rewind_dev. Device %s not open\n"),
-            dev->print_name());
+           dev->print_name());
       Emsg0(M_ABORT, 0, dev->errmsg);
       return false;
    }
@@ -515,30 +515,30 @@ bool rewind_dev(DEVICE *dev)
        * retrying every 5 seconds.
        */
       for (i=dev->max_rewind_wait; ; i -= 5) {
-         if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
-            berrno be;
-            clrerror_dev(dev, MTREW);
-            if (i == dev->max_rewind_wait) {
+        if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
+           berrno be;
+           clrerror_dev(dev, MTREW);
+           if (i == dev->max_rewind_wait) {
                Dmsg1(200, "Rewind error, %s. retrying ...\n", be.strerror());
-            }
-            if (dev->dev_errno == EIO && i > 0) {
+           }
+           if (dev->dev_errno == EIO && i > 0) {
                Dmsg0(200, "Sleeping 5 seconds.\n");
-               bmicrosleep(5, 0);
-               continue;
-            }
+              bmicrosleep(5, 0);
+              continue;
+           }
             Mmsg2(dev->errmsg, _("Rewind error on %s. ERR=%s.\n"),
-               dev->print_name(), be.strerror());
-            return false;
-         }
-         break;
+              dev->print_name(), be.strerror());
+           return false;
+        }
+        break;
       }
    } else if (dev->is_file()) {      
       if (lseek_dev(dev, (off_t)0, SEEK_SET) < 0) {
-         berrno be;
-         dev->dev_errno = errno;
+        berrno be;
+        dev->dev_errno = errno;
          Mmsg2(dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"),
-            dev->print_name(), be.strerror());
-         return false;
+           dev->print_name(), be.strerror());
+        return false;
       }
    }
    return true;
@@ -578,13 +578,13 @@ void DEVICE::set_eof()
 void DEVICE::set_eot() 
 {
    state |= (ST_EOF|ST_EOT|ST_WEOT);
-   state &= ~ST_APPEND;          /* make tape read-only */
+   state &= ~ST_APPEND;         /* make tape read-only */
 }
 
 /*
  * Position device to end of medium (end of data)
  *  Returns: true  on succes
- *           false on error
+ *          false on error
  */
 bool
 eod_dev(DEVICE *dev)
@@ -597,7 +597,7 @@ eod_dev(DEVICE *dev)
    if (dev->fd < 0) {
       dev->dev_errno = EBADF;
       Mmsg1(dev->errmsg, _("Bad call to eod_dev. Device %s not open\n"),
-            dev->print_name());
+           dev->print_name());
       return false;
    }
    Dmsg0(29, "eod_dev\n");
@@ -615,14 +615,14 @@ eod_dev(DEVICE *dev)
       pos = lseek_dev(dev, (off_t)0, SEEK_END);
 //    Dmsg1(100, "====== Seek to %lld\n", pos);
       if (pos >= 0) {
-         update_pos_dev(dev);
-         dev->state |= ST_EOT;
-         return true;
+        update_pos_dev(dev);
+        dev->state |= ST_EOT;
+        return true;
       }
       dev->dev_errno = errno;
       berrno be;
       Mmsg2(dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"),
-             dev->print_name(), be.strerror());
+            dev->print_name(), be.strerror());
       return false;
    }
 #ifdef MTEOM
@@ -630,9 +630,9 @@ eod_dev(DEVICE *dev)
       Dmsg0(100,"Using FAST FSF for EOM\n");
       /* If unknown position, rewind */
       if (!dev_get_os_pos(dev, &mt_stat)) {
-        if (!rewind_dev(dev)) {
-          return false;
-        }
+       if (!rewind_dev(dev)) {
+         return false;
+       }
       }
       mt_com.mt_op = MTFSF;
       /*
@@ -641,33 +641,33 @@ eod_dev(DEVICE *dev)
        */
       mt_com.mt_count = INT16_MAX;    /* use big positive number */
       if (mt_com.mt_count < 0) {
-         mt_com.mt_count = INT16_MAX; /* brain damaged system */
+        mt_com.mt_count = INT16_MAX; /* brain damaged system */
       }
    }
 
    if (dev_cap(dev, CAP_MTIOCGET) && (dev_cap(dev, CAP_FASTFSF) || dev_cap(dev, CAP_EOM))) {
       if (dev_cap(dev, CAP_EOM)) {
          Dmsg0(100,"Using EOM for EOM\n");
-         mt_com.mt_op = MTEOM;
-         mt_com.mt_count = 1;
+        mt_com.mt_op = MTEOM;
+        mt_com.mt_count = 1;
       }
 
       if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
-         berrno be;
-         clrerror_dev(dev, mt_com.mt_op);
+        berrno be;
+        clrerror_dev(dev, mt_com.mt_op);
          Dmsg1(50, "ioctl error: %s\n", be.strerror());
-         update_pos_dev(dev);
+        update_pos_dev(dev);
          Mmsg2(dev->errmsg, _("ioctl MTEOM error on %s. ERR=%s.\n"),
-            dev->print_name(), be.strerror());
-         return false;
+           dev->print_name(), be.strerror());
+        return false;
       }
 
       if (!dev_get_os_pos(dev, &mt_stat)) {
-         berrno be;
-         clrerror_dev(dev, -1);
+        berrno be;
+        clrerror_dev(dev, -1);
          Mmsg2(dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"),
-            dev->print_name(), be.strerror());
-         return false;
+           dev->print_name(), be.strerror());
+        return false;
       }
       Dmsg2(100, "EOD file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
       dev->set_eof();
@@ -680,7 +680,7 @@ eod_dev(DEVICE *dev)
        * Rewind then use FSF until EOT reached
        */
       if (!rewind_dev(dev)) {
-         return false;
+        return false;
       }
       /*
        * Move file by file to the end of the tape
@@ -688,24 +688,24 @@ eod_dev(DEVICE *dev)
       int file_num;
       for (file_num=dev->file; !dev->at_eot(); file_num++) {
          Dmsg0(200, "eod_dev: doing fsf 1\n");
-         if (!fsf_dev(dev, 1)) {
+        if (!fsf_dev(dev, 1)) {
             Dmsg0(200, "fsf_dev error.\n");
-            return false;
-         }
-         /*
-          * Avoid infinite loop. ***FIXME*** possibly add code
-          *   to set EOD or to turn off CAP_FASTFSF if on.
-          */
-         if (file_num == (int)dev->file) {
-            struct mtget mt_stat;
+           return false;
+        }
+        /*
+         * Avoid infinite loop. ***FIXME*** possibly add code
+         *   to set EOD or to turn off CAP_FASTFSF if on.
+         */
+        if (file_num == (int)dev->file) {
+           struct mtget mt_stat;
             Dmsg1(100, "fsf_dev did not advance from file %d\n", file_num);
-            if (dev_get_os_pos(dev, &mt_stat)) {
+           if (dev_get_os_pos(dev, &mt_stat)) {
                Dmsg2(100, "Adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno);
-               dev->set_eof();
-               dev->file = mt_stat.mt_fileno;
-            }
-            return false;
-         }
+              dev->set_eof();
+              dev->file = mt_stat.mt_fileno;
+           }
+           return false;
+        }
       }
    }
    /*
@@ -720,12 +720,12 @@ eod_dev(DEVICE *dev)
       /* If BSF worked and fileno is known (not -1), set file */
       if (dev_get_os_pos(dev, &mt_stat)) {
          Dmsg2(100, "BSFATEOF adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno);
-         dev->file = mt_stat.mt_fileno;
+        dev->file = mt_stat.mt_fileno;
       } else {
-         dev->file++;                 /* wing it -- not correct on all OSes */
+        dev->file++;                 /* wing it -- not correct on all OSes */
       }
    } else {
-      update_pos_dev(dev);                   /* update position */
+      update_pos_dev(dev);                  /* update position */
    }
    Dmsg1(200, "EOD dev->file=%d\n", dev->file);
    return ok;
@@ -735,7 +735,7 @@ eod_dev(DEVICE *dev)
  * Set the position of the device -- only for files
  *   For other devices, there is no generic way to do it.
  *  Returns: true  on succes
- *           false on error
+ *          false on error
  */
 bool update_pos_dev(DEVICE *dev)
 {
@@ -755,14 +755,14 @@ bool update_pos_dev(DEVICE *dev)
       dev->file_addr = 0;
       pos = lseek_dev(dev, (off_t)0, SEEK_CUR);
       if (pos < 0) {
-         berrno be;
-         dev->dev_errno = errno;
+        berrno be;
+        dev->dev_errno = errno;
          Pmsg1(000, "Seek error: ERR=%s\n", be.strerror());
          Mmsg2(dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"),
-            dev->print_name(), be.strerror());
-         ok = false;
+           dev->print_name(), be.strerror());
+        ok = false;
       } else {
-         dev->file_addr = pos;
+        dev->file_addr = pos;
       }
    }
    return ok;
@@ -785,67 +785,67 @@ uint32_t status_dev(DEVICE *dev)
 
    if (dev->state & (ST_EOT | ST_WEOT)) {
       stat |= BMT_EOD;
-      Dmsg0(-20, " EOD");
+      Pmsg0(-20, " EOD");
    }
    if (dev->state & ST_EOF) {
       stat |= BMT_EOF;
-      Dmsg0(-20, " EOF");
+      Pmsg0(-20, " EOF");
    }
    if (dev->is_tape()) {
       stat |= BMT_TAPE;
-      Dmsg0(-20," Bacula status:");
-      Dmsg2(-20," file=%d block=%d\n", dev->file, dev->block_num);
+      Pmsg0(-20," Bacula status:");
+      Pmsg2(-20," file=%d block=%d\n", dev->file, dev->block_num);
       if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) {
-         berrno be;
-         dev->dev_errno = errno;
+        berrno be;
+        dev->dev_errno = errno;
          Mmsg2(dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"),
-            dev->print_name(), be.strerror());
-         return 0;
+           dev->print_name(), be.strerror());
+        return 0;
       }
-      Dmsg0(-20, " Device status:");
+      Pmsg0(-20, " Device status:");
 
 #if defined(HAVE_LINUX_OS)
       if (GMT_EOF(mt_stat.mt_gstat)) {
-         stat |= BMT_EOF;
-         Dmsg0(-20, " EOF");
+        stat |= BMT_EOF;
+         Pmsg0(-20, " EOF");
       }
       if (GMT_BOT(mt_stat.mt_gstat)) {
-         stat |= BMT_BOT;
-         Dmsg0(-20, " BOT");
+        stat |= BMT_BOT;
+         Pmsg0(-20, " BOT");
       }
       if (GMT_EOT(mt_stat.mt_gstat)) {
-         stat |= BMT_EOT;
-         Dmsg0(-20, " EOT");
+        stat |= BMT_EOT;
+         Pmsg0(-20, " EOT");
       }
       if (GMT_SM(mt_stat.mt_gstat)) {
-         stat |= BMT_SM;
-         Dmsg0(-20, " SM");
+        stat |= BMT_SM;
+         Pmsg0(-20, " SM");
       }
       if (GMT_EOD(mt_stat.mt_gstat)) {
-         stat |= BMT_EOD;
-         Dmsg0(-20, " EOD");
+        stat |= BMT_EOD;
+         Pmsg0(-20, " EOD");
       }
       if (GMT_WR_PROT(mt_stat.mt_gstat)) {
-         stat |= BMT_WR_PROT;
-         Dmsg0(-20, " WR_PROT");
+        stat |= BMT_WR_PROT;
+         Pmsg0(-20, " WR_PROT");
       }
       if (GMT_ONLINE(mt_stat.mt_gstat)) {
-         stat |= BMT_ONLINE;
-         Dmsg0(-20, " ONLINE");
+        stat |= BMT_ONLINE;
+         Pmsg0(-20, " ONLINE");
       }
       if (GMT_DR_OPEN(mt_stat.mt_gstat)) {
-         stat |= BMT_DR_OPEN;
-         Dmsg0(-20, " DR_OPEN");
+        stat |= BMT_DR_OPEN;
+         Pmsg0(-20, " DR_OPEN");
       }
       if (GMT_IM_REP_EN(mt_stat.mt_gstat)) {
-         stat |= BMT_IM_REP_EN;
-         Dmsg0(-20, " IM_REP_EN");
+        stat |= BMT_IM_REP_EN;
+         Pmsg0(-20, " IM_REP_EN");
       }
 #endif /* !SunOS && !OSF */
       if (dev_cap(dev, CAP_MTIOCGET)) {
-         Dmsg2(-20, " file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
+         Pmsg2(-20, " file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
       } else {
-         Dmsg2(-20, " file=%d block=%d\n", -1, -1);
+         Pmsg2(-20, " file=%d block=%d\n", -1, -1);
       }
    } else {
       stat |= BMT_ONLINE | BMT_BOT;
@@ -857,7 +857,7 @@ uint32_t status_dev(DEVICE *dev)
 /*
  * Load medium in device
  *  Returns: true  on success
- *           false on failure
+ *          false on failure
  */
 bool load_dev(DEVICE *dev)
 {
@@ -877,9 +877,9 @@ bool load_dev(DEVICE *dev)
 #ifndef MTLOAD
    Dmsg0(200, "stored: MTLOAD command not available\n");
    berrno be;
-   dev->dev_errno = ENOTTY;           /* function not available */
+   dev->dev_errno = ENOTTY;          /* function not available */
    Mmsg2(dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"),
-         dev->print_name(), be.strerror());
+        dev->print_name(), be.strerror());
    return false;
 #else
 
@@ -892,7 +892,7 @@ bool load_dev(DEVICE *dev)
       berrno be;
       dev->dev_errno = errno;
       Mmsg2(dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"),
-         dev->print_name(), be.strerror());
+        dev->print_name(), be.strerror());
       return false;
    }
    return true;
@@ -902,7 +902,7 @@ bool load_dev(DEVICE *dev)
 /*
  * Rewind device and put it offline
  *  Returns: true  on success
- *           false on failure
+ *          false on failure
  */
 bool offline_dev(DEVICE *dev)
 {
@@ -934,7 +934,7 @@ bool offline_dev(DEVICE *dev)
       berrno be;
       dev->dev_errno = errno;
       Mmsg2(dev->errmsg, _("ioctl MTOFFL error on %s. ERR=%s.\n"),
-         dev->print_name(), be.strerror());
+        dev->print_name(), be.strerror());
       return false;
    }
    Dmsg1(100, "Offlined device %s\n", dev->print_name());
@@ -964,7 +964,7 @@ bool offline_or_rewind_dev(DEVICE *dev)
 /*
  * Foward space a file
  *   Returns: true  on success
- *            false on failure
+ *           false on failure
  */
 bool
 fsf_dev(DEVICE *dev, int num)
@@ -1006,14 +1006,14 @@ fsf_dev(DEVICE *dev, int num)
       mt_com.mt_count = num;
       stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com);
       if (stat < 0 || !dev_get_os_pos(dev, &mt_stat)) {
-         berrno be;
-         dev->state |= ST_EOT;
+        berrno be;
+        dev->state |= ST_EOT;
          Dmsg0(200, "Set ST_EOT\n");
-         clrerror_dev(dev, MTFSF);
+        clrerror_dev(dev, MTFSF);
          Mmsg2(dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"),
-            dev->print_name(), be.strerror());
+           dev->print_name(), be.strerror());
          Dmsg1(200, "%s", dev->errmsg);
-         return false;
+        return false;
       }
       Dmsg2(200, "fsf file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
       dev->set_eof();
@@ -1032,60 +1032,60 @@ fsf_dev(DEVICE *dev, int num)
       int rbuf_len;
       Dmsg0(200, "FSF has cap_fsf\n");
       if (dev->max_block_size == 0) {
-         rbuf_len = DEFAULT_BLOCK_SIZE;
+        rbuf_len = DEFAULT_BLOCK_SIZE;
       } else {
-         rbuf_len = dev->max_block_size;
+        rbuf_len = dev->max_block_size;
       }
       rbuf = get_memory(rbuf_len);
       mt_com.mt_op = MTFSF;
       mt_com.mt_count = 1;
       while (num-- && !(dev->state & ST_EOT)) {
          Dmsg0(100, "Doing read before fsf\n");
-         if ((stat = read(dev->fd, (char *)rbuf, rbuf_len)) < 0) {
-            if (errno == ENOMEM) {     /* tape record exceeds buf len */
-               stat = rbuf_len;        /* This is OK */
-            } else {
-               berrno be;
-               dev->state |= ST_EOT;
-               clrerror_dev(dev, -1);
+        if ((stat = read(dev->fd, (char *)rbuf, rbuf_len)) < 0) {
+           if (errno == ENOMEM) {     /* tape record exceeds buf len */
+              stat = rbuf_len;        /* This is OK */
+           } else {
+              berrno be;
+              dev->state |= ST_EOT;
+              clrerror_dev(dev, -1);
                Dmsg2(100, "Set ST_EOT read errno=%d. ERR=%s\n", dev->dev_errno,
-                  be.strerror());
+                 be.strerror());
                Mmsg2(dev->errmsg, _("read error on %s. ERR=%s.\n"),
-                  dev->print_name(), be.strerror());
+                 dev->print_name(), be.strerror());
                Dmsg1(100, "%s", dev->errmsg);
-               break;
-            }
-         }
-         if (stat == 0) {                /* EOF */
-            update_pos_dev(dev);
+              break;
+           }
+        }
+        if (stat == 0) {                /* EOF */
+           update_pos_dev(dev);
             Dmsg1(100, "End of File mark from read. File=%d\n", dev->file+1);
-            /* Two reads of zero means end of tape */
-            if (dev->state & ST_EOF) {
-               dev->state |= ST_EOT;
+           /* Two reads of zero means end of tape */
+           if (dev->state & ST_EOF) {
+              dev->state |= ST_EOT;
                Dmsg0(100, "Set ST_EOT\n");
-               break;
-            } else {
-               dev->set_eof();
-               continue;
-            }
-         } else {                        /* Got data */
-            dev->state &= ~(ST_EOF|ST_EOT);
-         }
+              break;
+           } else {
+              dev->set_eof();
+              continue;
+           }
+        } else {                        /* Got data */
+           dev->state &= ~(ST_EOF|ST_EOT);
+        }
 
          Dmsg0(100, "Doing MTFSF\n");
-         stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com);
-         if (stat < 0) {                 /* error => EOT */
-            berrno be;
-            dev->state |= ST_EOT;
+        stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com);
+        if (stat < 0) {                 /* error => EOT */
+           berrno be;
+           dev->state |= ST_EOT;
             Dmsg0(100, "Set ST_EOT\n");
-            clrerror_dev(dev, MTFSF);
+           clrerror_dev(dev, MTFSF);
             Mmsg2(dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"),
-               dev->print_name(), be.strerror());
+              dev->print_name(), be.strerror());
             Dmsg0(100, "Got < 0 for MTFSF\n");
             Dmsg1(100, "%s", dev->errmsg);
-         } else {
-            dev->set_eof();
-         }
+        } else {
+           dev->set_eof();
+        }
       }
       free_memory(rbuf);
 
@@ -1095,14 +1095,14 @@ fsf_dev(DEVICE *dev, int num)
    } else {
       Dmsg0(200, "Doing FSR for FSF\n");
       while (num-- && !(dev->state & ST_EOT)) {
-         dev->fsr(INT32_MAX);    /* returns -1 on EOF or EOT */
+        dev->fsr(INT32_MAX);    /* returns -1 on EOF or EOT */
       }
       if (dev->state & ST_EOT) {
-         dev->dev_errno = 0;
+        dev->dev_errno = 0;
          Mmsg1(dev->errmsg, _("Device %s at End of Tape.\n"), dev->print_name());
-         stat = -1;
+        stat = -1;
       } else {
-         stat = 0;
+        stat = 0;
       }
    }
    update_pos_dev(dev);
@@ -1118,7 +1118,7 @@ fsf_dev(DEVICE *dev, int num)
 /*
  * Backward space a file
  *  Returns: false on failure
- *           true  on success
+ *          true  on success
  */
 bool
 bsf_dev(DEVICE *dev, int num)
@@ -1135,7 +1135,7 @@ bsf_dev(DEVICE *dev, int num)
 
    if (!dev->is_tape()) {
       Mmsg1(dev->errmsg, _("Device %s cannot BSF because it is not a tape.\n"),
-         dev->print_name());
+        dev->print_name());
       return false;
    }
    Dmsg0(29, "bsf_dev\n");
@@ -1150,7 +1150,7 @@ bsf_dev(DEVICE *dev, int num)
       berrno be;
       clrerror_dev(dev, MTBSF);
       Mmsg2(dev->errmsg, _("ioctl MTBSF error on %s. ERR=%s.\n"),
-         dev->print_name(), be.strerror());
+        dev->print_name(), be.strerror());
    }
    update_pos_dev(dev);
    return stat == 0;
@@ -1160,7 +1160,7 @@ bsf_dev(DEVICE *dev, int num)
 /*
  * Foward space num records
  *  Returns: false on failure
- *           true  on success
+ *          true  on success
  */
 bool DEVICE::fsr(int num)
 {
@@ -1196,18 +1196,18 @@ bool DEVICE::fsr(int num)
       Dmsg1(100, "FSF fail: ERR=%s\n", be.strerror());
       if (dev_get_os_pos(this, &mt_stat)) {
          Dmsg4(100, "Adjust from %d:%d to %d:%d\n", file,
-            block_num, mt_stat.mt_fileno, mt_stat.mt_blkno);
-         file = mt_stat.mt_fileno;
-         block_num = mt_stat.mt_blkno;
+           block_num, mt_stat.mt_fileno, mt_stat.mt_blkno);
+        file = mt_stat.mt_fileno;
+        block_num = mt_stat.mt_blkno;
       } else {
-         if (at_eof()) {
-            state |= ST_EOT;
-         } else {
-            set_eof();
-         }
+        if (at_eof()) {
+           state |= ST_EOT;
+        } else {
+           set_eof();
+        }
       }
       Mmsg3(errmsg, _("ioctl MTFSR %d error on %s. ERR=%s.\n"),
-         num, print_name(), be.strerror());
+        num, print_name(), be.strerror());
    }
    update_pos_dev(this);
    return stat == 0;
@@ -1216,7 +1216,7 @@ bool DEVICE::fsr(int num)
 /*
  * Backward space a record
  *   Returns:  false on failure
- *             true  on success
+ *            true  on success
  */
 bool
 bsr_dev(DEVICE *dev, int num)
@@ -1250,7 +1250,7 @@ bsr_dev(DEVICE *dev, int num)
       berrno be;
       clrerror_dev(dev, MTBSR);
       Mmsg2(dev->errmsg, _("ioctl MTBSR error on %s. ERR=%s.\n"),
-         dev->print_name(), be.strerror());
+        dev->print_name(), be.strerror());
    }
    update_pos_dev(dev);
    return stat == 0;
@@ -1259,7 +1259,7 @@ bsr_dev(DEVICE *dev, int num)
 /*
  * Reposition the device to file, block
  * Returns: false on failure
- *          true  on success
+ *         true  on success
  */
 bool
 reposition_dev(DEVICE *dev, uint32_t file, uint32_t block)
@@ -1275,11 +1275,11 @@ reposition_dev(DEVICE *dev, uint32_t file, uint32_t block)
       off_t pos = (((off_t)file)<<32) + block;
       Dmsg1(100, "===== lseek_dev to %d\n", (int)pos);
       if (lseek_dev(dev, pos, SEEK_SET) == (off_t)-1) {
-         berrno be;
-         dev->dev_errno = errno;
+        berrno be;
+        dev->dev_errno = errno;
          Mmsg2(dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"),
-            dev->print_name(), be.strerror());
-         return false;
+           dev->print_name(), be.strerror());
+        return false;
       }
       dev->file = file;
       dev->block_num = block;
@@ -1291,14 +1291,14 @@ reposition_dev(DEVICE *dev, uint32_t file, uint32_t block)
    if (file < dev->file) {
       Dmsg0(100, "Rewind_dev\n");
       if (!rewind_dev(dev)) {
-         return false;
+        return false;
       }
    }
    if (file > dev->file) {
       Dmsg1(100, "fsf %d\n", file-dev->file);
       if (!fsf_dev(dev, file-dev->file)) {
          Dmsg1(100, "fsf failed! ERR=%s\n", strerror_dev(dev));
-         return false;
+        return false;
       }
       Dmsg2(100, "wanted_file=%d at_file=%d\n", file, dev->file);
    }
@@ -1323,7 +1323,7 @@ reposition_dev(DEVICE *dev, uint32_t file, uint32_t block)
 /*
  * Write an end of file on the device
  *   Returns: 0 on success
- *            non-zero on failure
+ *           non-zero on failure
  */
 int
 weof_dev(DEVICE *dev, int num)
@@ -1362,7 +1362,7 @@ weof_dev(DEVICE *dev, int num)
       clrerror_dev(dev, MTWEOF);
       if (stat == -1) {
          Mmsg2(dev->errmsg, _("ioctl MTWEOF error on %s. ERR=%s.\n"),
-            dev->print_name(), be.strerror());
+           dev->print_name(), be.strerror());
        }
    }
    return stat;
@@ -1392,7 +1392,7 @@ clrerror_dev(DEVICE *dev, int func)
    struct mtget mt_stat;
    char buf[100];
 
-   dev->dev_errno = errno;         /* save errno */
+   dev->dev_errno = errno;        /* save errno */
    if (errno == EIO) {
       dev->VolCatInfo.VolCatErrors++;
    }
@@ -1404,60 +1404,60 @@ clrerror_dev(DEVICE *dev, int func)
       switch (func) {
       case -1:
          Emsg0(M_ABORT, 0, "Got ENOTTY on read/write!\n");
-         break;
+        break;
       case MTWEOF:
          msg = "WTWEOF";
-         dev->capabilities &= ~CAP_EOF; /* turn off feature */
-         break;
+        dev->capabilities &= ~CAP_EOF; /* turn off feature */
+        break;
 #ifdef MTEOM
       case MTEOM:
          msg = "WTEOM";
-         dev->capabilities &= ~CAP_EOM; /* turn off feature */
-         break;
+        dev->capabilities &= ~CAP_EOM; /* turn off feature */
+        break;
 #endif
       case MTFSF:
          msg = "MTFSF";
-         dev->capabilities &= ~CAP_FSF; /* turn off feature */
-         break;
+        dev->capabilities &= ~CAP_FSF; /* turn off feature */
+        break;
       case MTBSF:
          msg = "MTBSF";
-         dev->capabilities &= ~CAP_BSF; /* turn off feature */
-         break;
+        dev->capabilities &= ~CAP_BSF; /* turn off feature */
+        break;
       case MTFSR:
          msg = "MTFSR";
-         dev->capabilities &= ~CAP_FSR; /* turn off feature */
-         break;
+        dev->capabilities &= ~CAP_FSR; /* turn off feature */
+        break;
       case MTBSR:
          msg = "MTBSR";
-         dev->capabilities &= ~CAP_BSR; /* turn off feature */
-         break;
+        dev->capabilities &= ~CAP_BSR; /* turn off feature */
+        break;
       case MTREW:
          msg = "MTREW";
-         break;
+        break;
 #ifdef MTSETBLK
       case MTSETBLK:
          msg = "MTSETBLK";
-         break;
+        break;
 #endif
 #ifdef MTSETBSIZ 
       case MTSETBSIZ:
          msg = "MTSETBSIZ";
-         break;
+        break;
 #endif
 #ifdef MTSRSZ
       case MTSRSZ:
          msg = "MTSRSZ";
-         break;
+        break;
 #endif
       default:
          bsnprintf(buf, sizeof(buf), "unknown func code %d", func);
-         msg = buf;
-         break;
+        msg = buf;
+        break;
       }
       if (msg != NULL) {
-         dev->dev_errno = ENOSYS;
+        dev->dev_errno = ENOSYS;
          Mmsg1(dev->errmsg, _("I/O function \"%s\" not supported on this device.\n"), msg);
-         Emsg0(M_ERROR, 0, dev->errmsg);
+        Emsg0(M_ERROR, 0, dev->errmsg);
       }
    }
    /* On some systems such as NetBSD, this clears all errors */
@@ -1528,7 +1528,7 @@ static void do_close(DEVICE *dev)
       get_filename(dev, dev->VolCatInfo.VolCatName, archive_name);
       /* Check that the part file is empty */
       if ((stat(archive_name.c_str(), &statp) == 0) && (statp.st_size == 0)) {
-         unlink(archive_name.c_str());
+        unlink(archive_name.c_str());
       }
    }
    
@@ -1610,7 +1610,7 @@ bool truncate_dev(DEVICE *dev)
       dev->num_parts = 0;
       dev->VolCatInfo.VolCatParts = 0;
       if (open_first_part(dev) < 0) {
-         berrno be;
+        berrno be;
          Mmsg1(dev->errmsg, "Unable to truncate device, because I'm unable to open the first part. ERR=%s\n", be.strerror());
       }
    }
@@ -1698,7 +1698,7 @@ void init_device_wait_timers(DCR *dcr)
    /* ******FIXME******* put these on config variables */
    dev->min_wait = 60 * 60;
    dev->max_wait = 24 * 60 * 60;
-   dev->max_num_wait = 9;              /* 5 waits =~ 1 day, then 1 day at a time */
+   dev->max_num_wait = 9;             /* 5 waits =~ 1 day, then 1 day at a time */
    dev->wait_sec = dev->min_wait;
    dev->rem_wait_sec = dev->wait_sec;
    dev->num_wait = 0;
@@ -1707,7 +1707,7 @@ void init_device_wait_timers(DCR *dcr)
 
    jcr->min_wait = 60 * 60;
    jcr->max_wait = 24 * 60 * 60;
-   jcr->max_num_wait = 9;              /* 5 waits =~ 1 day, then 1 day at a time */
+   jcr->max_num_wait = 9;             /* 5 waits =~ 1 day, then 1 day at a time */
    jcr->wait_sec = jcr->min_wait;
    jcr->rem_wait_sec = jcr->wait_sec;
    jcr->num_wait = 0;
@@ -1719,7 +1719,7 @@ void init_jcr_device_wait_timers(JCR *jcr)
    /* ******FIXME******* put these on config variables */
    jcr->min_wait = 60 * 60;
    jcr->max_wait = 24 * 60 * 60;
-   jcr->max_num_wait = 9;              /* 5 waits =~ 1 day, then 1 day at a time */
+   jcr->max_num_wait = 9;             /* 5 waits =~ 1 day, then 1 day at a time */
    jcr->wait_sec = jcr->min_wait;
    jcr->rem_wait_sec = jcr->wait_sec;
    jcr->num_wait = 0;
@@ -1730,11 +1730,11 @@ void init_jcr_device_wait_timers(JCR *jcr)
  * The dev timers are used for waiting on a particular device 
  *
  * Returns: true if time doubled
- *          false if max time expired
+ *         false if max time expired
  */
 bool double_dev_wait_time(DEVICE *dev)
 {
-   dev->wait_sec *= 2;               /* double wait time */
+   dev->wait_sec *= 2;              /* double wait time */
    if (dev->wait_sec > dev->max_wait) {   /* but not longer than maxtime */
       dev->wait_sec = dev->max_wait;
    }
@@ -1756,18 +1756,18 @@ void set_os_device_parameters(DEVICE *dev)
       mt_com.mt_op = MTSETBLK;
       mt_com.mt_count = 0;
       if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
-         clrerror_dev(dev, MTSETBLK);
+        clrerror_dev(dev, MTSETBLK);
       }
       mt_com.mt_op = MTSETDRVBUFFER;
       mt_com.mt_count = MT_ST_CLEARBOOLEANS;
       if (!dev_cap(dev, CAP_TWOEOF)) {
-         mt_com.mt_count |= MT_ST_TWO_FM;
+        mt_com.mt_count |= MT_ST_TWO_FM;
       }
       if (dev_cap(dev, CAP_EOM)) {
-         mt_com.mt_count |= MT_ST_FAST_MTEOM;
+        mt_com.mt_count |= MT_ST_FAST_MTEOM;
       }
       if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
-         clrerror_dev(dev, MTSETBLK);
+        clrerror_dev(dev, MTSETBLK);
       }
    }
    return;
@@ -1780,13 +1780,13 @@ void set_os_device_parameters(DEVICE *dev)
       mt_com.mt_op = MTSETBSIZ;
       mt_com.mt_count = 0;
       if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
-         clrerror_dev(dev, MTSETBSIZ);
+        clrerror_dev(dev, MTSETBSIZ);
       }
       /* Get notified at logical end of tape */
       mt_com.mt_op = MTEWARN;
       mt_com.mt_count = 1;
       if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
-         clrerror_dev(dev, MTEWARN);
+        clrerror_dev(dev, MTEWARN);
       }
    }
    return;
@@ -1799,7 +1799,7 @@ void set_os_device_parameters(DEVICE *dev)
       mt_com.mt_op = MTSETBSIZ;
       mt_com.mt_count = 0;
       if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
-         clrerror_dev(dev, MTSETBSIZ);
+        clrerror_dev(dev, MTSETBSIZ);
       }
    }
    return;
@@ -1812,7 +1812,7 @@ void set_os_device_parameters(DEVICE *dev)
       mt_com.mt_op = MTSRSZ;
       mt_com.mt_count = 0;
       if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
-         clrerror_dev(dev, MTSRSZ);
+        clrerror_dev(dev, MTSRSZ);
       }
    }
    return;
@@ -1822,6 +1822,6 @@ void set_os_device_parameters(DEVICE *dev)
 static bool dev_get_os_pos(DEVICE *dev, struct mtget *mt_stat)
 {
    return dev_cap(dev, CAP_MTIOCGET) && 
-          ioctl(dev->fd, MTIOCGET, (char *)mt_stat) == 0 &&
-          mt_stat->mt_fileno >= 0;
+         ioctl(dev->fd, MTIOCGET, (char *)mt_stat) == 0 &&
+         mt_stat->mt_fileno >= 0;
 }
index eb3411d8bf71767d85e5b7e274fad382ab55025d..168bf69336601c14dd882716b49124d684c40fb4 100755 (executable)
@@ -6,27 +6,22 @@
  *
  *   Version $Id$
  */
-
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   Copyright (C) 2002-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
+
 #include "bacula.h"
 #include "stored.h"
 #ifdef HAVE_FNMATCH
@@ -71,22 +66,22 @@ void position_bsr_block(BSR *bsr, DEV_BLOCK *block)
  *    so can do fast rejection.
  *
  *   returns:  1 if block may contain valid records
- *             0 if block may be skipped (i.e. it contains no records of
- *                  that can match the bsr).
+ *            0 if block may be skipped (i.e. it contains no records of
+ *                 that can match the bsr).
  *
  */
 int match_bsr_block(BSR *bsr, DEV_BLOCK *block)
 {
    if (!bsr || !bsr->use_fast_rejection || (block->BlockVer < 2)) {
-      return 1;                       /* cannot fast reject */
+      return 1;                      /* cannot fast reject */
    }
 
    for ( ; bsr; bsr=bsr->next) {
       if (!match_block_sesstime(bsr, bsr->sesstime, block)) {
-         continue;
+        continue;
       }
       if (!match_block_sessid(bsr, bsr->sessid, block)) {
-         continue;
+        continue;
       }
       return 1;
    }
@@ -96,7 +91,7 @@ int match_bsr_block(BSR *bsr, DEV_BLOCK *block)
 static int match_block_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_BLOCK *block)
 {
    if (!sesstime) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (sesstime->sesstime == block->VolSessionTime) {
       return 1;
@@ -110,7 +105,7 @@ static int match_block_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_BLOCK *blo
 static int match_block_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_BLOCK *block)
 {
    if (!sessid) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (sessid->sessid <= block->VolSessionId && sessid->sessid2 >= block->VolSessionId) {
       return 1;
@@ -124,11 +119,11 @@ static int match_block_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_BLOCK *block)
 
 /*********************************************************************
  *
- *      Match Bootstrap records
- *        returns  1 on match
- *        returns  0 no match and reposition is set if we should
- *                      reposition the tape
- *       returns -1 no additional matches possible
+ *     Match Bootstrap records
+ *       returns  1 on match
+ *       returns  0 no match and reposition is set if we should
+ *                     reposition the tape
+ *      returns -1 no additional matches possible
  */
 int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec)
 {
@@ -136,8 +131,8 @@ int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *se
 
    /*
     * The bsr->reposition flag is set any time a bsr is done.
-    *   In this case, we can probably reposition the
-    *   tape to the next available bsr position.
+    *  In this case, we can probably reposition the
+    *  tape to the next available bsr position.
     */
    if (bsr) {
       bsr->reposition = false;
@@ -148,10 +143,10 @@ int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *se
        *  found or if we cannot use positioning
        */
       if (stat != 0 || !bsr->use_positioning) {
-         bsr->reposition = false;
+        bsr->reposition = false;
       }
    } else {
-      stat = 1;                       /* no bsr => match all */
+      stat = 1;                      /* no bsr => match all */
    }
    return stat;
 }
@@ -174,12 +169,12 @@ BSR *find_next_bsr(BSR *root_bsr, DEVICE *dev)
    root_bsr->mount_next_volume = false;
    for (bsr=root_bsr; bsr; bsr=bsr->next) {
       if (bsr->done || !match_volume(bsr, bsr->volume, &dev->VolHdr, 1)) {
-         continue;
+        continue;
       }
       if (found_bsr == NULL) {
-         found_bsr = bsr;
+        found_bsr = bsr;
       } else {
-         found_bsr = find_smallest_volfile(found_bsr, bsr);
+        found_bsr = find_smallest_volfile(found_bsr, bsr);
       }
    }
    /*
@@ -205,14 +200,14 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr)
    found_bsr_sfile = vf->sfile;
    while ( (vf=vf->next) ) {
       if (vf->sfile < found_bsr_sfile) {
-         found_bsr_sfile = vf->sfile;
+        found_bsr_sfile = vf->sfile;
       }
    }
    vf = bsr->volfile;
    bsr_sfile = vf->sfile;
    while ( (vf=vf->next) ) {
       if (vf->sfile < bsr_sfile) {
-         bsr_sfile = vf->sfile;
+        bsr_sfile = vf->sfile;
       }
    }
    if (found_bsr_sfile > bsr_sfile) {
@@ -222,19 +217,19 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr)
       vb = found_bsr->volblock;
       found_bsr_sblock = vb->sblock;
       while ( (vb=vb->next) ) {
-         if (vb->sblock < found_bsr_sblock) {
-            found_bsr_sblock = vb->sblock;
-         }
+        if (vb->sblock < found_bsr_sblock) {
+           found_bsr_sblock = vb->sblock;
+        }
       }
       vb = bsr->volblock;
       bsr_sblock = vb->sblock;
       while ( (vb=vb->next) ) {
-         if (vb->sblock < bsr_sblock) {
-            bsr_sblock = vb->sblock;
-         }
+        if (vb->sblock < bsr_sblock) {
+           bsr_sblock = vb->sblock;
+        }
       }
       if (found_bsr_sblock > bsr_sblock) {
-         return_bsr = bsr;
+        return_bsr = bsr;
       }
    }
 
@@ -248,7 +243,7 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr)
  *    for consistency with the other match calls.
  *
  * Returns: true if we should reposition
- *        : false otherwise.
+ *       : false otherwise.
  */
 bool match_set_eof(BSR *bsr, DEV_RECORD *rec)
 {
@@ -263,7 +258,7 @@ bool match_set_eof(BSR *bsr, DEV_RECORD *rec)
       rbsr->done = true;
       rbsr->root->reposition = true;
       Dmsg2(100, "match_set_eof reposition count=%d found=%d\n",
-         rbsr->count, rbsr->found);
+        rbsr->count, rbsr->found);
       return true;
    }
    return false;
@@ -276,7 +271,7 @@ bool match_set_eof(BSR *bsr, DEV_RECORD *rec)
  *   returns -1 no additional matches possible
  */
 static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
-                     SESSION_LABEL *sessrec, bool done)
+                    SESSION_LABEL *sessrec, bool done)
 {
    if (bsr->done) {
       goto no_match;
@@ -286,45 +281,45 @@ static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
    }
    if (!match_volfile(bsr, bsr->volfile, rec, 1)) {
       Dmsg2(100, "Fail on file. bsr=%d rec=%d\n", bsr->volfile->efile,
-         rec->File);
+        rec->File);
       goto no_match;
    }
    if (!match_sesstime(bsr, bsr->sesstime, rec, 1)) {
       Dmsg2(100, "Fail on sesstime. bsr=%d rec=%d\n",
-         bsr->sesstime->sesstime, rec->VolSessionTime);
+        bsr->sesstime->sesstime, rec->VolSessionTime);
       goto no_match;
    }
 
    /* NOTE!! This test MUST come after the sesstime test */
    if (!match_sessid(bsr, bsr->sessid, rec)) {
       Dmsg2(100, "Fail on sessid. bsr=%d rec=%d\n",
-         bsr->sessid->sessid, rec->VolSessionId);
+        bsr->sessid->sessid, rec->VolSessionId);
       goto no_match;
    }
 
    /* NOTE!! This test MUST come after sesstime and sessid tests */
    if (!match_findex(bsr, bsr->FileIndex, rec, 1)) {
       Dmsg2(100, "Fail on findex. bsr=%d rec=%d\n",
-         bsr->FileIndex->findex2, rec->FileIndex);
+        bsr->FileIndex->findex2, rec->FileIndex);
       goto no_match;
    }
    /*
     * If a count was specified and we have a FileIndex, assume
-    *   it is a Bacula created bsr (or the equivalent). We
-    *   then save the bsr where the match occurred so that
-    *   after processing the record or records, we can update
-    *   the found count. I.e. rec->bsr points to the bsr that
-    *   satisfied the match.
+    *  it is a Bacula created bsr (or the equivalent). We
+    *  then save the bsr where the match occurred so that
+    *  after processing the record or records, we can update
+    *  the found count. I.e. rec->bsr points to the bsr that
+    *  satisfied the match.
     */
    if (bsr->count && bsr->FileIndex) {
       rec->bsr = bsr;
-      return 1;                       /* this is a complete match */
+      return 1;                      /* this is a complete match */
    }
 
    /*
     * The selections below are not used by Bacula's
     *   restore command, and don't work because of
-    *   the rec->bsr = bsr optimization above.
+    *  the rec->bsr = bsr optimization above.
     */
    if (!match_jobid(bsr, bsr->JobId, sessrec, 1)) {
       goto no_match;
@@ -360,7 +355,7 @@ no_match:
 static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, bool done)
 {
    if (!volume) {
-      return 0;                       /* Volume must match */
+      return 0;                      /* Volume must match */
    }
    if (strcmp(volume->VolumeName, volrec->VolName) == 0) {
       return 1;
@@ -374,7 +369,7 @@ static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, bool
 static int match_client(BSR *bsr, BSR_CLIENT *client, SESSION_LABEL *sessrec, bool done)
 {
    if (!client) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (fnmatch(client->ClientName, sessrec->ClientName, 0) == 0) {
       return 1;
@@ -388,7 +383,7 @@ static int match_client(BSR *bsr, BSR_CLIENT *client, SESSION_LABEL *sessrec, bo
 static int match_job(BSR *bsr, BSR_JOB *job, SESSION_LABEL *sessrec, bool done)
 {
    if (!job) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (fnmatch(job->Job, sessrec->Job, 0) == 0) {
       return 1;
@@ -402,7 +397,7 @@ static int match_job(BSR *bsr, BSR_JOB *job, SESSION_LABEL *sessrec, bool done)
 static int match_job_type(BSR *bsr, BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec, bool done)
 {
    if (!job_type) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (job_type->JobType == sessrec->JobType) {
       return 1;
@@ -416,7 +411,7 @@ static int match_job_type(BSR *bsr, BSR_JOBTYPE *job_type, SESSION_LABEL *sessre
 static int match_job_level(BSR *bsr, BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec, bool done)
 {
    if (!job_level) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (job_level->JobLevel == sessrec->JobLevel) {
       return 1;
@@ -430,7 +425,7 @@ static int match_job_level(BSR *bsr, BSR_JOBLEVEL *job_level, SESSION_LABEL *ses
 static int match_jobid(BSR *bsr, BSR_JOBID *jobid, SESSION_LABEL *sessrec, bool done)
 {
    if (!jobid) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (jobid->JobId <= sessrec->JobId && jobid->JobId2 >= sessrec->JobId) {
       return 1;
@@ -444,20 +439,20 @@ static int match_jobid(BSR *bsr, BSR_JOBID *jobid, SESSION_LABEL *sessrec, bool
 static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, bool done)
 {
    if (!volfile) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    /* For the moment, these tests work only with tapes. */
    if (!(rec->state & REC_ISTAPE)) {
-      return 1;                       /* All File records OK for this match */
+      return 1;                      /* All File records OK for this match */
    }
 // Dmsg3(100, "match_volfile: sfile=%d efile=%d recfile=%d\n",
-//             volfile->sfile, volfile->efile, rec->File);
+//            volfile->sfile, volfile->efile, rec->File);
    if (volfile->sfile <= rec->File && volfile->efile >= rec->File) {
       return 1;
    }
    /* Once we get past last efile, we are done */
    if (rec->File > volfile->efile) {
-      volfile->done = true;              /* set local done */
+      volfile->done = true;             /* set local done */
    }
    if (volfile->next) {
       return match_volfile(bsr, volfile->next, rec, volfile->done && done);
@@ -468,7 +463,7 @@ static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, bool d
       bsr->done = true;
       bsr->root->reposition = true;
       Dmsg2(100, "bsr done from volfile rec=%d volefile=%d\n",
-         rec->File, volfile->efile);
+        rec->File, volfile->efile);
    }
    return 0;
 }
@@ -476,7 +471,7 @@ static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, bool d
 static int match_stream(BSR *bsr, BSR_STREAM *stream, DEV_RECORD *rec, bool done)
 {
    if (!stream) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (stream->stream == rec->Stream) {
       return 1;
@@ -490,7 +485,7 @@ static int match_stream(BSR *bsr, BSR_STREAM *stream, DEV_RECORD *rec, bool done
 static int match_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_RECORD *rec, bool done)
 {
    if (!sesstime) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (sesstime->sesstime == rec->VolSessionTime) {
       return 1;
@@ -512,7 +507,7 @@ static int match_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_RECORD *rec, boo
 static int match_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_RECORD *rec)
 {
    if (!sessid) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (sessid->sessid <= rec->VolSessionId && sessid->sessid2 >= rec->VolSessionId) {
       return 1;
@@ -530,13 +525,13 @@ static int match_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_RECORD *rec)
  *  ***FIXME*** optimizations
  * We could optimize a lot here by removing the recursion, and 
  *   stopping the search earlier -- say when rec->FileIndex > findex->findex2
- *   and findex->next == NULL.  Also, the current entry tests could be skipped
+ *   and findex->next == NULL. Also, the current entry tests could be skipped
  *   if findex->done is set.
  */
 static int match_findex(BSR *bsr, BSR_FINDEX *findex, DEV_RECORD *rec, bool done)
 {
    if (!findex) {
-      return 1;                       /* no specification matches all */
+      return 1;                      /* no specification matches all */
    }
    if (findex->findex <= rec->FileIndex && findex->findex2 >= rec->FileIndex) {
       return 1;
index 4aa77a03f1f8bf505322733ed1ce5d678e994019..2a9034bc78b002105746a46cabf1efd38183c2a2 100755 (executable)
    Copyright (C) 2002-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   MA 02111-1307, USA. 
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -107,18 +103,18 @@ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...)
    if (jcr) {
       Jmsg(jcr, M_FATAL, 0, _("Bootstrap file error: %s\n"
 "            : Line %d, col %d of file %s\n%s\n"),
-         buf, lc->line_no, lc->col_no, lc->fname, lc->line);
+        buf, lc->line_no, lc->col_no, lc->fname, lc->line);
    } else {
       e_msg(file, line, M_FATAL, 0, _("Bootstrap file error: %s\n"
 "            : Line %d, col %d of file %s\n%s\n"),
-         buf, lc->line_no, lc->col_no, lc->fname, lc->line);
+        buf, lc->line_no, lc->col_no, lc->fname, lc->line);
    }
 }
 
 
 /*********************************************************************
  *
- *      Parse Bootstrap file
+ *     Parse Bootstrap file
  *
  */
 BSR *parse_bsr(JCR *jcr, char *fname)
@@ -132,38 +128,38 @@ BSR *parse_bsr(JCR *jcr, char *fname)
    if ((lc = lex_open_file(lc, fname, s_err)) == NULL) {
       berrno be;
       Emsg2(M_ERROR_TERM, 0, _("Cannot open bootstrap file %s: %s\n"),
-            fname, be.strerror());
+           fname, be.strerror());
    }
    lc->caller_ctx = (void *)jcr;
    while ((token=lex_get_token(lc, T_ALL)) != T_EOF) {
       Dmsg1(200, "parse got token=%s\n", lex_tok_to_str(token));
       if (token == T_EOL) {
-         continue;
+        continue;
       }
       for (i=0; items[i].name; i++) {
-         if (strcasecmp(items[i].name, lc->str) == 0) {
-            token = lex_get_token(lc, T_ALL);
+        if (strcasecmp(items[i].name, lc->str) == 0) {
+           token = lex_get_token(lc, T_ALL);
             Dmsg1 (200, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
-            if (token != T_EQUALS) {
+           if (token != T_EQUALS) {
                scan_err1(lc, "expected an equals, got: %s", lc->str);
-               bsr = NULL;
-               break;
-            }
+              bsr = NULL;
+              break;
+           }
             Dmsg1(200, "calling handler for %s\n", items[i].name);
-            /* Call item handler */
-            bsr = items[i].handler(lc, bsr);
-            i = -1;
-            break;
-         }
+           /* Call item handler */
+           bsr = items[i].handler(lc, bsr);
+           i = -1;
+           break;
+        }
       }
       if (i >= 0) {
          Dmsg1(200, "Keyword = %s\n", lc->str);
          scan_err1(lc, "Keyword %s not found", lc->str);
-         bsr = NULL;
-         break;
+        bsr = NULL;
+        break;
       }
       if (!bsr) {
-         break;
+        break;
       }
    }
    lc = lex_close_file(lc);
@@ -191,7 +187,7 @@ static bool is_fast_rejection_ok(BSR *bsr)
     */
    for ( ; bsr; bsr=bsr->next) {
       if (!(bsr->sesstime && bsr->sessid)) {
-         return false;
+        return false;
       }
    }
    return true;
@@ -201,11 +197,11 @@ static bool is_positioning_ok(BSR *bsr)
 {
    /*
     * Every bsr should have a volfile entry and a volblock entry
-    *   if we are going to use positioning
+    *  if we are going to use positioning
     */
    for ( ; bsr; bsr=bsr->next) {
       if (!bsr->volfile || !bsr->volblock) {
-         return false;
+        return false;
       }
    }
    return true;
@@ -232,19 +228,19 @@ static BSR *store_vol(LEX *lc, BSR *bsr)
    for (p=lc->str; p && *p; ) {
       n = strchr(p, '|');
       if (n) {
-         *n++ = 0;
+        *n++ = 0;
       }
       volume = (BSR_VOLUME *)malloc(sizeof(BSR_VOLUME));
       memset(volume, 0, sizeof(BSR_VOLUME));
       bstrncpy(volume->VolumeName, p, sizeof(volume->VolumeName));
       /* Add it to the end of the volume chain */
       if (!bsr->volume) {
-         bsr->volume = volume;
+        bsr->volume = volume;
       } else {
-         BSR_VOLUME *bc = bsr->volume;
-         for ( ;bc->next; bc=bc->next)
-            { }
-         bc->next = volume;
+        BSR_VOLUME *bc = bsr->volume;
+        for ( ;bc->next; bc=bc->next)
+           { }
+        bc->next = volume;
       }
       p = n;
    }
@@ -262,7 +258,7 @@ static BSR *store_mediatype(LEX *lc, BSR *bsr)
    }
    if (!bsr->volume) {
       Emsg1(M_ERROR,0, _("MediaType %s in bsr at inappropriate place.\n"),
-         lc->str);
+        lc->str);
       return bsr;
    }
    BSR_VOLUME *bv;
@@ -281,23 +277,23 @@ static BSR *store_client(LEX *lc, BSR *bsr)
    for (;;) {
       token = lex_get_token(lc, T_NAME);
       if (token == T_ERROR) {
-         return NULL;
+        return NULL;
       }
       client = (BSR_CLIENT *)malloc(sizeof(BSR_CLIENT));
       memset(client, 0, sizeof(BSR_CLIENT));
       bstrncpy(client->ClientName, lc->str, sizeof(client->ClientName));
       /* Add it to the end of the client chain */
       if (!bsr->client) {
-         bsr->client = client;
+        bsr->client = client;
       } else {
-         BSR_CLIENT *bc = bsr->client;
-         for ( ;bc->next; bc=bc->next)
-            { }
-         bc->next = client;
+        BSR_CLIENT *bc = bsr->client;
+        for ( ;bc->next; bc=bc->next)
+           { }
+        bc->next = client;
       }
       token = lex_get_token(lc, T_ALL);
       if (token != T_COMMA) {
-         break;
+        break;
       }
    }
    return bsr;
@@ -311,24 +307,24 @@ static BSR *store_job(LEX *lc, BSR *bsr)
    for (;;) {
       token = lex_get_token(lc, T_NAME);
       if (token == T_ERROR) {
-         return NULL;
+        return NULL;
       }
       job = (BSR_JOB *)malloc(sizeof(BSR_JOB));
       memset(job, 0, sizeof(BSR_JOB));
       bstrncpy(job->Job, lc->str, sizeof(job->Job));
       /* Add it to the end of the client chain */
       if (!bsr->job) {
-         bsr->job = job;
+        bsr->job = job;
       } else {
-         /* Add to end of chain */
-         BSR_JOB *bc = bsr->job;
-         for ( ;bc->next; bc=bc->next)
-            { }
-         bc->next = job;
+        /* Add to end of chain */
+        BSR_JOB *bc = bsr->job;
+        for ( ;bc->next; bc=bc->next)
+           { }
+        bc->next = job;
       }
       token = lex_get_token(lc, T_ALL);
       if (token != T_COMMA) {
-         break;
+        break;
       }
    }
    return bsr;
@@ -342,7 +338,7 @@ static BSR *store_findex(LEX *lc, BSR *bsr)
    for (;;) {
       token = lex_get_token(lc, T_PINT32_RANGE);
       if (token == T_ERROR) {
-         return NULL;
+        return NULL;
       }
       findex = (BSR_FINDEX *)malloc(sizeof(BSR_FINDEX));
       memset(findex, 0, sizeof(BSR_FINDEX));
@@ -350,17 +346,17 @@ static BSR *store_findex(LEX *lc, BSR *bsr)
       findex->findex2 = lc->pint32_val2;
       /* Add it to the end of the chain */
       if (!bsr->FileIndex) {
-         bsr->FileIndex = findex;
+        bsr->FileIndex = findex;
       } else {
-         /* Add to end of chain */
-         BSR_FINDEX *bs = bsr->FileIndex;
-         for ( ;bs->next; bs=bs->next)
-            {  }
-         bs->next = findex;
+        /* Add to end of chain */
+        BSR_FINDEX *bs = bsr->FileIndex;
+        for ( ;bs->next; bs=bs->next)
+           {  }
+        bs->next = findex;
       }
       token = lex_get_token(lc, T_ALL);
       if (token != T_COMMA) {
-         break;
+        break;
       }
    }
    return bsr;
@@ -375,7 +371,7 @@ static BSR *store_jobid(LEX *lc, BSR *bsr)
    for (;;) {
       token = lex_get_token(lc, T_PINT32_RANGE);
       if (token == T_ERROR) {
-         return NULL;
+        return NULL;
       }
       jobid = (BSR_JOBID *)malloc(sizeof(BSR_JOBID));
       memset(jobid, 0, sizeof(BSR_JOBID));
@@ -383,17 +379,17 @@ static BSR *store_jobid(LEX *lc, BSR *bsr)
       jobid->JobId2 = lc->pint32_val2;
       /* Add it to the end of the chain */
       if (!bsr->JobId) {
-         bsr->JobId = jobid;
+        bsr->JobId = jobid;
       } else {
-         /* Add to end of chain */
-         BSR_JOBID *bs = bsr->JobId;
-         for ( ;bs->next; bs=bs->next)
-            {  }
-         bs->next = jobid;
+        /* Add to end of chain */
+        BSR_JOBID *bs = bsr->JobId;
+        for ( ;bs->next; bs=bs->next)
+           {  }
+        bs->next = jobid;
       }
       token = lex_get_token(lc, T_ALL);
       if (token != T_COMMA) {
-         break;
+        break;
       }
    }
    return bsr;
@@ -417,7 +413,7 @@ static BSR *store_count(LEX *lc, BSR *bsr)
 static BSR *store_jobtype(LEX *lc, BSR *bsr)
 {
    /* *****FIXME****** */
-   Dmsg0(-1, "JobType not yet implemented\n");
+   Pmsg0(-1, "JobType not yet implemented\n");
    return bsr;
 }
 
@@ -425,7 +421,7 @@ static BSR *store_jobtype(LEX *lc, BSR *bsr)
 static BSR *store_joblevel(LEX *lc, BSR *bsr)
 {
    /* *****FIXME****** */
-   Dmsg0(-1, "JobLevel not yet implemented\n");
+   Pmsg0(-1, "JobLevel not yet implemented\n");
    return bsr;
 }
 
@@ -443,7 +439,7 @@ static BSR *store_volfile(LEX *lc, BSR *bsr)
    for (;;) {
       token = lex_get_token(lc, T_PINT32_RANGE);
       if (token == T_ERROR) {
-         return NULL;
+        return NULL;
       }
       volfile = (BSR_VOLFILE *)malloc(sizeof(BSR_VOLFILE));
       memset(volfile, 0, sizeof(BSR_VOLFILE));
@@ -451,17 +447,17 @@ static BSR *store_volfile(LEX *lc, BSR *bsr)
       volfile->efile = lc->pint32_val2;
       /* Add it to the end of the chain */
       if (!bsr->volfile) {
-         bsr->volfile = volfile;
+        bsr->volfile = volfile;
       } else {
-         /* Add to end of chain */
-         BSR_VOLFILE *bs = bsr->volfile;
-         for ( ;bs->next; bs=bs->next)
-            {  }
-         bs->next = volfile;
+        /* Add to end of chain */
+        BSR_VOLFILE *bs = bsr->volfile;
+        for ( ;bs->next; bs=bs->next)
+           {  }
+        bs->next = volfile;
       }
       token = lex_get_token(lc, T_ALL);
       if (token != T_COMMA) {
-         break;
+        break;
       }
    }
    return bsr;
@@ -479,7 +475,7 @@ static BSR *store_volblock(LEX *lc, BSR *bsr)
    for (;;) {
       token = lex_get_token(lc, T_PINT32_RANGE);
       if (token == T_ERROR) {
-         return NULL;
+        return NULL;
       }
       volblock = (BSR_VOLBLOCK *)malloc(sizeof(BSR_VOLBLOCK));
       memset(volblock, 0, sizeof(BSR_VOLBLOCK));
@@ -487,17 +483,17 @@ static BSR *store_volblock(LEX *lc, BSR *bsr)
       volblock->eblock = lc->pint32_val2;
       /* Add it to the end of the chain */
       if (!bsr->volblock) {
-         bsr->volblock = volblock;
+        bsr->volblock = volblock;
       } else {
-         /* Add to end of chain */
-         BSR_VOLBLOCK *bs = bsr->volblock;
-         for ( ;bs->next; bs=bs->next)
-            {  }
-         bs->next = volblock;
+        /* Add to end of chain */
+        BSR_VOLBLOCK *bs = bsr->volblock;
+        for ( ;bs->next; bs=bs->next)
+           {  }
+        bs->next = volblock;
       }
       token = lex_get_token(lc, T_ALL);
       if (token != T_COMMA) {
-         break;
+        break;
       }
    }
    return bsr;
@@ -512,7 +508,7 @@ static BSR *store_sessid(LEX *lc, BSR *bsr)
    for (;;) {
       token = lex_get_token(lc, T_PINT32_RANGE);
       if (token == T_ERROR) {
-         return NULL;
+        return NULL;
       }
       sid = (BSR_SESSID *)malloc(sizeof(BSR_SESSID));
       memset(sid, 0, sizeof(BSR_SESSID));
@@ -520,17 +516,17 @@ static BSR *store_sessid(LEX *lc, BSR *bsr)
       sid->sessid2 = lc->pint32_val2;
       /* Add it to the end of the chain */
       if (!bsr->sessid) {
-         bsr->sessid = sid;
+        bsr->sessid = sid;
       } else {
-         /* Add to end of chain */
-         BSR_SESSID *bs = bsr->sessid;
-         for ( ;bs->next; bs=bs->next)
-            {  }
-         bs->next = sid;
+        /* Add to end of chain */
+        BSR_SESSID *bs = bsr->sessid;
+        for ( ;bs->next; bs=bs->next)
+           {  }
+        bs->next = sid;
       }
       token = lex_get_token(lc, T_ALL);
       if (token != T_COMMA) {
-         break;
+        break;
       }
    }
    return bsr;
@@ -544,24 +540,24 @@ static BSR *store_sesstime(LEX *lc, BSR *bsr)
    for (;;) {
       token = lex_get_token(lc, T_PINT32);
       if (token == T_ERROR) {
-         return NULL;
+        return NULL;
       }
       stime = (BSR_SESSTIME *)malloc(sizeof(BSR_SESSTIME));
       memset(stime, 0, sizeof(BSR_SESSTIME));
       stime->sesstime = lc->pint32_val;
       /* Add it to the end of the chain */
       if (!bsr->sesstime) {
-         bsr->sesstime = stime;
+        bsr->sesstime = stime;
       } else {
-         /* Add to end of chain */
-         BSR_SESSTIME *bs = bsr->sesstime;
-         for ( ;bs->next; bs=bs->next)
-            { }
-         bs->next = stime;
+        /* Add to end of chain */
+        BSR_SESSTIME *bs = bsr->sesstime;
+        for ( ;bs->next; bs=bs->next)
+           { }
+        bs->next = stime;
       }
       token = lex_get_token(lc, T_ALL);
       if (token != T_COMMA) {
-         break;
+        break;
       }
    }
    return bsr;
@@ -576,24 +572,24 @@ static BSR *store_stream(LEX *lc, BSR *bsr)
    for (;;) {
       token = lex_get_token(lc, T_INT32);
       if (token == T_ERROR) {
-         return NULL;
+        return NULL;
       }
       stream = (BSR_STREAM *)malloc(sizeof(BSR_STREAM));
       memset(stream, 0, sizeof(BSR_STREAM));
       stream->stream = lc->int32_val;
       /* Add it to the end of the chain */
       if (!bsr->stream) {
-         bsr->stream = stream;
+        bsr->stream = stream;
       } else {
-         /* Add to end of chain */
-         BSR_STREAM *bs = bsr->stream;
-         for ( ;bs->next; bs=bs->next)
-            { }
-         bs->next = stream;
+        /* Add to end of chain */
+        BSR_STREAM *bs = bsr->stream;
+        for ( ;bs->next; bs=bs->next)
+           { }
+        bs->next = stream;
       }
       token = lex_get_token(lc, T_ALL);
       if (token != T_COMMA) {
-         break;
+        break;
       }
    }
    return bsr;
@@ -627,7 +623,7 @@ static BSR *store_exclude(LEX *lc, BSR *bsr)
 void dump_volfile(BSR_VOLFILE *volfile)
 {
    if (volfile) {
-      Dmsg2(-1, "VolFile     : %u-%u\n", volfile->sfile, volfile->efile);
+      Pmsg2(-1, "VolFile     : %u-%u\n", volfile->sfile, volfile->efile);
       dump_volfile(volfile->next);
    }
 }
@@ -635,7 +631,7 @@ void dump_volfile(BSR_VOLFILE *volfile)
 void dump_volblock(BSR_VOLBLOCK *volblock)
 {
    if (volblock) {
-      Dmsg2(-1, "VolBlock    : %u-%u\n", volblock->sblock, volblock->eblock);
+      Pmsg2(-1, "VolBlock    : %u-%u\n", volblock->sblock, volblock->eblock);
       dump_volblock(volblock->next);
    }
 }
@@ -645,9 +641,9 @@ void dump_findex(BSR_FINDEX *FileIndex)
 {
    if (FileIndex) {
       if (FileIndex->findex == FileIndex->findex2) {
-         Dmsg1(-1, "FileIndex   : %u\n", FileIndex->findex);
+         Pmsg1(-1, "FileIndex   : %u\n", FileIndex->findex);
       } else {
-         Dmsg2(-1, "FileIndex   : %u-%u\n", FileIndex->findex, FileIndex->findex2);
+         Pmsg2(-1, "FileIndex   : %u-%u\n", FileIndex->findex, FileIndex->findex2);
       }
       dump_findex(FileIndex->next);
    }
@@ -657,9 +653,9 @@ void dump_jobid(BSR_JOBID *jobid)
 {
    if (jobid) {
       if (jobid->JobId == jobid->JobId2) {
-         Dmsg1(-1, "JobId       : %u\n", jobid->JobId);
+         Pmsg1(-1, "JobId       : %u\n", jobid->JobId);
       } else {
-         Dmsg2(-1, "JobId       : %u-%u\n", jobid->JobId, jobid->JobId2);
+         Pmsg2(-1, "JobId       : %u-%u\n", jobid->JobId, jobid->JobId2);
       }
       dump_jobid(jobid->next);
    }
@@ -669,9 +665,9 @@ void dump_sessid(BSR_SESSID *sessid)
 {
    if (sessid) {
       if (sessid->sessid == sessid->sessid2) {
-         Dmsg1(-1, "SessId      : %u\n", sessid->sessid);
+         Pmsg1(-1, "SessId      : %u\n", sessid->sessid);
       } else {
-         Dmsg2(-1, "SessId      : %u-%u\n", sessid->sessid, sessid->sessid2);
+         Pmsg2(-1, "SessId      : %u-%u\n", sessid->sessid, sessid->sessid2);
       }
       dump_sessid(sessid->next);
    }
@@ -680,7 +676,7 @@ void dump_sessid(BSR_SESSID *sessid)
 void dump_volume(BSR_VOLUME *volume)
 {
    if (volume) {
-      Dmsg1(-1, "VolumeName  : %s\n", volume->VolumeName);
+      Pmsg1(-1, "VolumeName  : %s\n", volume->VolumeName);
       dump_volume(volume->next);
    }
 }
@@ -689,7 +685,7 @@ void dump_volume(BSR_VOLUME *volume)
 void dump_client(BSR_CLIENT *client)
 {
    if (client) {
-      Dmsg1(-1, "Client      : %s\n", client->ClientName);
+      Pmsg1(-1, "Client      : %s\n", client->ClientName);
       dump_client(client->next);
    }
 }
@@ -697,7 +693,7 @@ void dump_client(BSR_CLIENT *client)
 void dump_job(BSR_JOB *job)
 {
    if (job) {
-      Dmsg1(-1, "Job          : %s\n", job->Job);
+      Pmsg1(-1, "Job          : %s\n", job->Job);
       dump_job(job->next);
    }
 }
@@ -705,7 +701,7 @@ void dump_job(BSR_JOB *job)
 void dump_sesstime(BSR_SESSTIME *sesstime)
 {
    if (sesstime) {
-      Dmsg1(-1, "SessTime    : %u\n", sesstime->sesstime);
+      Pmsg1(-1, "SessTime    : %u\n", sesstime->sesstime);
       dump_sesstime(sesstime->next);
    }
 }
@@ -719,12 +715,12 @@ void dump_bsr(BSR *bsr, bool recurse)
    int save_debug = debug_level;
    debug_level = 1;
    if (!bsr) {
-      Dmsg0(-1, "BSR is NULL\n");
+      Pmsg0(-1, "BSR is NULL\n");
       debug_level = save_debug;
       return;
    }
-   Dmsg1(-1,    "Next        : 0x%x\n", bsr->next);
-   Dmsg1(-1,    "Root bsr    : 0x%x\n", bsr->root);
+   Pmsg1(-1,    "Next        : 0x%x\n", bsr->next);
+   Pmsg1(-1,    "Root bsr    : 0x%x\n", bsr->root);
    dump_volume(bsr->volume);
    dump_sessid(bsr->sessid);
    dump_sesstime(bsr->sesstime);
@@ -735,18 +731,18 @@ void dump_bsr(BSR *bsr, bool recurse)
    dump_job(bsr->job);
    dump_findex(bsr->FileIndex);
    if (bsr->Slot) {
-      Dmsg1(-1, "Slot        : %u\n", bsr->Slot);
+      Pmsg1(-1, "Slot        : %u\n", bsr->Slot);
    }
    if (bsr->count) {
-      Dmsg1(-1, "count       : %u\n", bsr->count);
-      Dmsg1(-1, "found       : %u\n", bsr->found);
+      Pmsg1(-1, "count       : %u\n", bsr->count);
+      Pmsg1(-1, "found       : %u\n", bsr->found);
    }
 
-   Dmsg1(-1,    "done        : %s\n", bsr->done?"yes":"no");
-   Dmsg1(-1,    "positioning : %d\n", bsr->use_positioning);
-   Dmsg1(-1,    "fast_reject : %d\n", bsr->use_fast_rejection);
+   Pmsg1(-1,    "done        : %s\n", bsr->done?"yes":"no");
+   Pmsg1(-1,    "positioning : %d\n", bsr->use_positioning);
+   Pmsg1(-1,    "fast_reject : %d\n", bsr->use_fast_rejection);
    if (recurse && bsr->next) {
-      Dmsg0(-1, "\n");
+      Pmsg0(-1, "\n");
       dump_bsr(bsr->next, true);
    }
    debug_level = save_debug;
@@ -756,7 +752,7 @@ void dump_bsr(BSR *bsr, bool recurse)
 
 /*********************************************************************
  *
- *      Free bsr resources
+ *     Free bsr resources
  */
 
 static void free_bsr_item(BSR *bsr)
@@ -803,30 +799,30 @@ VOL_LIST *new_vol()
  * is not already in the list.
  *
  *   returns: 1 if volume added
- *            0 if volume already in list
+ *           0 if volume already in list
  */
 int add_vol(JCR *jcr, VOL_LIST *vol)
 {
    VOL_LIST *next = jcr->VolList;
 
-   if (!next) {                       /* list empty ? */
-      jcr->VolList = vol;             /* yes, add volume */
+   if (!next) {                      /* list empty ? */
+      jcr->VolList = vol;            /* yes, add volume */
    } else {
       for ( ; next->next; next=next->next) {
-         if (strcmp(vol->VolumeName, next->VolumeName) == 0) {
-            if (vol->start_file < next->start_file) {
-               next->start_file = vol->start_file;
-            }
-            return 0;                 /* already in list */
-         }
+        if (strcmp(vol->VolumeName, next->VolumeName) == 0) {
+           if (vol->start_file < next->start_file) {
+              next->start_file = vol->start_file;
+           }
+           return 0;                 /* already in list */
+        }
       }
       if (strcmp(vol->VolumeName, next->VolumeName) == 0) {
-         if (vol->start_file < next->start_file) {
-            next->start_file = vol->start_file;
-         }
-         return 0;                    /* already in list */
+        if (vol->start_file < next->start_file) {
+           next->start_file = vol->start_file;
+        }
+        return 0;                    /* already in list */
       }
-      next->next = vol;               /* add volume */
+      next->next = vol;              /* add volume */
    }
    return 1;
 }
@@ -861,52 +857,52 @@ void create_vol_list(JCR *jcr)
    if (jcr->bsr) {
       BSR *bsr = jcr->bsr;
       if (!bsr->volume || !bsr->volume->VolumeName) {
-         return;
+        return;
       }
       for ( ; bsr; bsr=bsr->next) {
-         BSR_VOLUME *bsrvol;
-         BSR_VOLFILE *volfile;
-         uint32_t sfile = UINT32_MAX;
-
-         /* Find minimum start file so that we can forward space to it */
-         for (volfile = bsr->volfile; volfile; volfile=volfile->next) {
-            if (volfile->sfile < sfile) {
-               sfile = volfile->sfile;
-            }
-         }
-         /* Now add volumes for this bsr */
-         for (bsrvol = bsr->volume; bsrvol; bsrvol=bsrvol->next) {
-            vol = new_vol();
-            bstrncpy(vol->VolumeName, bsrvol->VolumeName, sizeof(vol->VolumeName));
-            bstrncpy(vol->MediaType,  bsrvol->MediaType,  sizeof(vol->MediaType));
-            vol->start_file = sfile;
-            if (add_vol(jcr, vol)) {
-               jcr->NumVolumes++;
+        BSR_VOLUME *bsrvol;
+        BSR_VOLFILE *volfile;
+        uint32_t sfile = UINT32_MAX;
+
+        /* Find minimum start file so that we can forward space to it */
+        for (volfile = bsr->volfile; volfile; volfile=volfile->next) {
+           if (volfile->sfile < sfile) {
+              sfile = volfile->sfile;
+           }
+        }
+        /* Now add volumes for this bsr */
+        for (bsrvol = bsr->volume; bsrvol; bsrvol=bsrvol->next) {
+           vol = new_vol();
+           bstrncpy(vol->VolumeName, bsrvol->VolumeName, sizeof(vol->VolumeName));
+           bstrncpy(vol->MediaType,  bsrvol->MediaType,  sizeof(vol->MediaType));
+           vol->start_file = sfile;
+           if (add_vol(jcr, vol)) {
+              jcr->NumVolumes++;
                Dmsg2(400, "Added volume=%s mediatype=%s\n", vol->VolumeName,
-                  vol->MediaType);
-            } else {
+                 vol->MediaType);
+           } else {
                Dmsg1(400, "Duplicate volume %s\n", vol->VolumeName);
-               free((char *)vol);
-            }
-            sfile = 0;                /* start at beginning of second volume */
-         }
+              free((char *)vol);
+           }
+           sfile = 0;                /* start at beginning of second volume */
+        }
       }
    } else {
       /* This is the old way -- deprecated */
       for (p = jcr->dcr->VolumeName; p && *p; ) {
          n = strchr(p, '|');             /* volume name separator */
-         if (n) {
-            *n++ = 0;                    /* Terminate name */
-         }
-         vol = new_vol();
-         bstrncpy(vol->VolumeName, p, sizeof(vol->VolumeName));
-         bstrncpy(vol->MediaType, jcr->dcr->media_type, sizeof(vol->MediaType));
-         if (add_vol(jcr, vol)) {
-            jcr->NumVolumes++;
-         } else {
-            free((char *)vol);
-         }
-         p = n;
+        if (n) {
+           *n++ = 0;                    /* Terminate name */
+        }
+        vol = new_vol();
+        bstrncpy(vol->VolumeName, p, sizeof(vol->VolumeName));
+        bstrncpy(vol->MediaType, jcr->dcr->media_type, sizeof(vol->MediaType));
+        if (add_vol(jcr, vol)) {
+           jcr->NumVolumes++;
+        } else {
+           free((char *)vol);
+        }
+        p = n;
       }
    }
 }
index 7b3569d6051c0acec5f62066098b6a1638767890..cf490ce4903f4add545d181bee559ac65d48ef00 100644 (file)
@@ -9,19 +9,14 @@
    Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
index 60e9b760c85aa7720244d499481e795af863ec57..7b2255b7ca1fc48659d555d9e13c8d9408a0be67 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  Spooling code
  *
- *      Kern Sibbald, March 2004
+ *     Kern Sibbald, March 2004
  *
  *  Version $Id$
  */
@@ -9,19 +9,14 @@
    Copyright (C) 2004-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended 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,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   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 along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -40,13 +35,13 @@ static bool write_spool_header(DCR *dcr);
 static bool write_spool_data(DCR *dcr);
 
 struct spool_stats_t {
-   uint32_t data_jobs;                /* current jobs spooling data */
+   uint32_t data_jobs;               /* current jobs spooling data */
    uint32_t attr_jobs;
-   uint32_t total_data_jobs;          /* total jobs to have spooled data */
+   uint32_t total_data_jobs;         /* total jobs to have spooled data */
    uint32_t total_attr_jobs;
-   int64_t max_data_size;             /* max data size */
+   int64_t max_data_size;            /* max data size */
    int64_t max_attr_size;
-   int64_t data_size;                 /* current data size (all jobs running) */
+   int64_t data_size;                /* current data size (all jobs running) */
    int64_t attr_size;
 };
 
@@ -56,9 +51,9 @@ spool_stats_t spool_stats;
 /*
  * Header for data spool record */
 struct spool_hdr {
-   int32_t  FirstIndex;               /* FirstIndex for buffer */
-   int32_t  LastIndex;                /* LastIndex for buffer */
-   uint32_t len;                      /* length of next buffer */
+   int32_t  FirstIndex;              /* FirstIndex for buffer */
+   int32_t  LastIndex;               /* LastIndex for buffer */
+   uint32_t len;                     /* length of next buffer */
 };
 
 enum {
@@ -72,15 +67,15 @@ void list_spool_stats(BSOCK *bs)
    char ed1[30], ed2[30];
    if (spool_stats.data_jobs || spool_stats.max_data_size) {
       bnet_fsend(bs, "Data spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes/job.\n",
-         spool_stats.data_jobs, edit_uint64_with_commas(spool_stats.data_size, ed1),
-         spool_stats.total_data_jobs,
-         edit_uint64_with_commas(spool_stats.max_data_size, ed2));
+        spool_stats.data_jobs, edit_uint64_with_commas(spool_stats.data_size, ed1),
+        spool_stats.total_data_jobs,
+        edit_uint64_with_commas(spool_stats.max_data_size, ed2));
    }
    if (spool_stats.attr_jobs || spool_stats.max_attr_size) {
       bnet_fsend(bs, "Attr spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes.\n",
-         spool_stats.attr_jobs, edit_uint64_with_commas(spool_stats.attr_size, ed1),
-         spool_stats.total_attr_jobs,
-         edit_uint64_with_commas(spool_stats.max_attr_size, ed2));
+        spool_stats.attr_jobs, edit_uint64_with_commas(spool_stats.attr_size, ed1),
+        spool_stats.total_attr_jobs,
+        edit_uint64_with_commas(spool_stats.max_attr_size, ed2));
    }
 }
 
@@ -92,11 +87,11 @@ bool begin_data_spool(DCR *dcr)
       dcr->spool_data = true;
       stat = open_data_spool_file(dcr);
       if (stat) {
-         dcr->spooling = true;
+        dcr->spooling = true;
          Jmsg(dcr->jcr, M_INFO, 0, _("Spooling data ...\n"));
-         P(mutex);
-         spool_stats.data_jobs++;
-         V(mutex);
+        P(mutex);
+        spool_stats.data_jobs++;
+        V(mutex);
       }
    }
    return stat;
@@ -120,8 +115,8 @@ bool commit_data_spool(DCR *dcr)
       stat = despool_data(dcr, true /*commit*/);
       if (!stat) {
          Pmsg1(000, "Bad return from despool WroteVol=%d\n", dcr->WroteVol);
-         close_data_spool_file(dcr);
-         return false;
+        close_data_spool_file(dcr);
+        return false;
       }
       return close_data_spool_file(dcr);
    }
@@ -137,7 +132,7 @@ static void make_unique_data_spool_filename(DCR *dcr, POOLMEM **name)
       dir = working_directory;
    }
    Mmsg(name, "%s/%s.data.spool.%s.%s", dir, my_name, dcr->jcr->Job, 
-        dcr->device->hdr.name);
+       dcr->device->hdr.name);
 }
 
 
@@ -153,7 +148,7 @@ static bool open_data_spool_file(DCR *dcr)
    } else {
       berrno be;
       Jmsg(dcr->jcr, M_FATAL, 0, _("Open data spool file %s failed: ERR=%s\n"), name,
-           be.strerror());
+          be.strerror());
       free_pool_memory(name);
       return false;
    }
@@ -202,7 +197,7 @@ static bool despool_data(DCR *dcr, bool commit)
    Dmsg0(100, "Despooling data\n");
    Jmsg(jcr, M_INFO, 0, _("%s spooled data to Volume. Despooling %s bytes ...\n"),
         commit?"Committing":"Writing",
-        edit_uint64_with_commas(jcr->dcr->spool_size, ec1));
+       edit_uint64_with_commas(jcr->dcr->spool_size, ec1));
    dcr->spooling = false;
    lock_device(dcr->dev);
    dcr->dev_locked = true;
@@ -223,39 +218,39 @@ static bool despool_data(DCR *dcr, bool commit)
    rdev->device = dcr->dev->device;
    rdcr = new_dcr(NULL, rdev);
    rdcr->spool_fd = dcr->spool_fd;
-   rdcr->jcr = jcr;                   /* set a valid jcr */
-   block = dcr->block;                /* save block */
-   dcr->block = rdcr->block;          /* make read and write block the same */
+   rdcr->jcr = jcr;                  /* set a valid jcr */
+   block = dcr->block;               /* save block */
+   dcr->block = rdcr->block;         /* make read and write block the same */
 
    Dmsg1(800, "read/write block size = %d\n", block->buf_len);
    lseek(rdcr->spool_fd, 0, SEEK_SET); /* rewind */
 
    for ( ; ok; ) {
       if (job_canceled(jcr)) {
-         ok = false;
-         break;
+        ok = false;
+        break;
       }
       stat = read_block_from_spool_file(rdcr);
       if (stat == RB_EOT) {
-         break;
+        break;
       } else if (stat == RB_ERROR) {
-         ok = false;
-         break;
+        ok = false;
+        break;
       }
       ok = write_block_to_device(dcr);
       if (!ok) {
          Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"),
-               dcr->dev->print_name(), strerror_dev(dcr->dev));
+              dcr->dev->print_name(), strerror_dev(dcr->dev));
       }
       Dmsg3(800, "Write block ok=%d FI=%d LI=%d\n", ok, block->FirstIndex, block->LastIndex);
    }
-   dcr->block = block;                /* reset block */
+   dcr->block = block;               /* reset block */
 
    lseek(rdcr->spool_fd, 0, SEEK_SET); /* rewind */
    if (ftruncate(rdcr->spool_fd, 0) != 0) {
       berrno be;
       Jmsg(dcr->jcr, M_ERROR, 0, _("Ftruncate spool file failed: ERR=%s\n"),
-         be.strerror());
+        be.strerror());
       Pmsg1(000, "Bad return from ftruncate. ERR=%s\n", be.strerror());
       ok = false;
    }
@@ -269,7 +264,7 @@ static bool despool_data(DCR *dcr, bool commit)
    V(mutex);
    P(dcr->dev->spool_mutex);
    dcr->dev->spool_size -= dcr->spool_size;
-   dcr->spool_size = 0;               /* zap size in input dcr */
+   dcr->spool_size = 0;              /* zap size in input dcr */
    V(dcr->dev->spool_mutex);
    free_memory(rdev->dev_name);
    free_pool_memory(rdev->errmsg);
@@ -279,7 +274,7 @@ static bool despool_data(DCR *dcr, bool commit)
    free(rdev);
    unlock_device(dcr->dev);
    dcr->dev_locked = false;
-   dcr->spooling = true;           /* turn on spooling again */
+   dcr->spooling = true;          /* turn on spooling again */
    return ok;
 }
 
@@ -287,8 +282,8 @@ static bool despool_data(DCR *dcr, bool commit)
  * Read a block from the spool file
  *
  *  Returns RB_OK on success
- *          RB_EOT when file done
- *          RB_ERROR on error
+ *         RB_EOT when file done
+ *         RB_ERROR on error
  */
 static int read_block_from_spool_file(DCR *dcr)
 {
@@ -304,9 +299,9 @@ static int read_block_from_spool_file(DCR *dcr)
       return RB_EOT;
    } else if (stat != (ssize_t)rlen) {
       if (stat == -1) {
-         berrno be;
+        berrno be;
          Jmsg(dcr->jcr, M_FATAL, 0, _("Spool header read error. ERR=%s\n"),
-              be.strerror());
+             be.strerror());
       } else {
          Pmsg2(000, "Spool read error. Wanted %u bytes, got %d\n", rlen, stat);
          Jmsg2(dcr->jcr, M_FATAL, 0, _("Spool header read error. Wanted %u bytes, got %d\n"), rlen, stat);
@@ -340,16 +335,16 @@ static int read_block_from_spool_file(DCR *dcr)
  * Write a block to the spool file
  *
  *  Returns: true on success or EOT
- *           false on hard error
+ *          false on hard error
  */
 bool write_block_to_spool_file(DCR *dcr)
 {
-   uint32_t wlen, hlen;               /* length to write */
+   uint32_t wlen, hlen;              /* length to write */
    bool despool = false;
    DEV_BLOCK *block = dcr->block;
 
    ASSERT(block->binbuf == ((uint32_t) (block->bufp - block->buf)));
-   if (block->binbuf <= WRITE_BLKHDR_LENGTH) {  /* Does block have data in it? */
+   if (block->binbuf <= WRITE_BLKHDR_LENGTH) { /* Does block have data in it? */
       return true;
    }
 
@@ -374,15 +369,15 @@ bool write_block_to_spool_file(DCR *dcr)
       char ec1[30], ec2[30], ec3[30], ec4[30];
       Dmsg4(100, "Despool in write_block_to_spool_file max_size=%s size=%s "
             "max_job_size=%s job_size=%s\n",
-            edit_uint64_with_commas(dcr->max_spool_size, ec1),
-            edit_uint64_with_commas(dcr->spool_size, ec2),
-            edit_uint64_with_commas(dcr->dev->max_spool_size, ec3),
-            edit_uint64_with_commas(dcr->dev->spool_size, ec4));
+           edit_uint64_with_commas(dcr->max_spool_size, ec1),
+           edit_uint64_with_commas(dcr->spool_size, ec2),
+           edit_uint64_with_commas(dcr->dev->max_spool_size, ec3),
+           edit_uint64_with_commas(dcr->dev->spool_size, ec4));
 #endif
       Jmsg(dcr->jcr, M_INFO, 0, _("User specified spool size reached.\n"));
       if (!despool_data(dcr, false)) {
          Pmsg0(000, "Bad return from despool in write_block.\n");
-         return false;
+        return false;
       }
       /* Despooling cleared these variables so reset them */
       P(dcr->dev->spool_mutex);
@@ -419,25 +414,25 @@ static bool write_spool_header(DCR *dcr)
    for (int retry=0; retry<=1; retry++) {
       stat = write(dcr->spool_fd, (char*)&hdr, sizeof(hdr));
       if (stat == -1) {
-         berrno be;
+        berrno be;
          Jmsg(dcr->jcr, M_FATAL, 0, _("Error writing header to spool file. ERR=%s\n"),
-              be.strerror());
+             be.strerror());
       }
       if (stat != (ssize_t)sizeof(hdr)) {
-         /* If we wrote something, truncate it, then despool */
-         if (stat != -1) {
-            if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR) - stat) != 0) {
-               berrno be;
+        /* If we wrote something, truncate it, then despool */
+        if (stat != -1) {
+           if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR) - stat) != 0) {
+              berrno be;
                Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"),
-                  be.strerror());
-               return false;
-            }
-         }
-         if (!despool_data(dcr, false)) {
+                 be.strerror());
+              return false;
+           }
+        }
+        if (!despool_data(dcr, false)) {
             Jmsg(dcr->jcr, M_FATAL, 0, _("Fatal despooling error."));
-            return false;
-         }
-         continue;                    /* try again */
+           return false;
+        }
+        continue;                    /* try again */
       }
       return true;
    }
@@ -454,31 +449,31 @@ static bool write_spool_data(DCR *dcr)
    for (int retry=0; retry<=1; retry++) {
       stat = write(dcr->spool_fd, block->buf, (size_t)block->binbuf);
       if (stat == -1) {
-         berrno be;
+        berrno be;
          Jmsg(dcr->jcr, M_FATAL, 0, _("Error writing data to spool file. ERR=%s\n"),
-              be.strerror());
+             be.strerror());
       }
       if (stat != (ssize_t)block->binbuf) {
-         /*
-          * If we wrote something, truncate it and the header, then despool
-          */
-         if (stat != -1) {
-            if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR)
-                      - stat - sizeof(spool_hdr)) != 0) {
-               berrno be;
+        /*
+         * If we wrote something, truncate it and the header, then despool
+         */
+        if (stat != -1) {
+           if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR)
+                     - stat - sizeof(spool_hdr)) != 0) {
+              berrno be;
                Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"),
-                  be.strerror());
-               return false;
-            }
-         }
-         if (!despool_data(dcr, false)) {
+                 be.strerror());
+              return false;
+           }
+        }
+        if (!despool_data(dcr, false)) {
             Jmsg(dcr->jcr, M_FATAL, 0, _("Fatal despooling error."));
-            return false;
-         }
-         if (!write_spool_header(dcr)) {
-            return false;
-         }
-         continue;                    /* try again */
+           return false;
+        }
+        if (!write_spool_header(dcr)) {
+           return false;
+        }
+        continue;                    /* try again */
       }
       return true;
    }
@@ -521,9 +516,9 @@ static void update_attr_spool_size(ssize_t size)
    P(mutex);
    if (size > 0) {
      if ((spool_stats.attr_size - size) > 0) {
-        spool_stats.attr_size -= size;
+       spool_stats.attr_size -= size;
      } else {
-        spool_stats.attr_size = 0;
+       spool_stats.attr_size = 0;
      }
    }
    V(mutex);
@@ -536,26 +531,26 @@ bool commit_attribute_spool(JCR *jcr)
 
    if (are_attributes_spooled(jcr)) {
       if (fseeko(jcr->dir_bsock->spool_fd, 0, SEEK_END) != 0) {
-         berrno be;
+        berrno be;
          Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"),
-              be.strerror());
-         goto bail_out;
+             be.strerror());
+        goto bail_out;
       }
       size = ftello(jcr->dir_bsock->spool_fd);
       if (size < 0) {
-         berrno be;
+        berrno be;
          Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"),
-              be.strerror());
-         goto bail_out;
+             be.strerror());
+        goto bail_out;
       }
       P(mutex);
       if (spool_stats.attr_size + size > spool_stats.max_attr_size) {
-         spool_stats.max_attr_size = spool_stats.attr_size + size;
+        spool_stats.max_attr_size = spool_stats.attr_size + size;
       }
       spool_stats.attr_size += size;
       V(mutex);
       Jmsg(jcr, M_INFO, 0, _("Sending spooled attrs to the Director. Despooling %s bytes ...\n"),
-            edit_uint64_with_commas(size, ec1));
+           edit_uint64_with_commas(size, ec1));
       bnet_despool_to_bsock(jcr->dir_bsock, update_attr_spool_size, size);
       return close_attr_spool_file(jcr, jcr->dir_bsock);
    }
@@ -582,7 +577,7 @@ bool open_attr_spool_file(JCR *jcr, BSOCK *bs)
    if (!bs->spool_fd) {
       berrno be;
       Jmsg(jcr, M_FATAL, 0, _("fopen attr spool file %s failed: ERR=%s\n"), name,
-           be.strerror());
+          be.strerror());
       free_pool_memory(name);
       return false;
    }