]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix counter bugs reported by Chris Allen
authorKern Sibbald <kern@sibbald.com>
Thu, 11 Sep 2003 16:20:21 +0000 (16:20 +0000)
committerKern Sibbald <kern@sibbald.com>
Thu, 11 Sep 2003 16:20:21 +0000 (16:20 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@699 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/expand.c
bacula/src/filed/filed.c
bacula/src/filed/win32/winmain.cpp
bacula/src/lib/var.c

index 265faa767808d39870e3c14b77dd82ba284b91f7..a36b788f379ab61a3f759e3385d5562db8393594 100644 (file)
@@ -130,6 +130,9 @@ static int job_item(JCR *jcr, int code,
 struct s_built_in_vars {char *var_name; int code; int (*func)(JCR *jcr, int code,
                         const char **val_ptr, int *val_len, int *val_size);};
 
+/*
+ * Table of build in variables
+ */
 static struct s_built_in_vars built_in_vars[] = {
    { N_("Year"),       1, date_item},
    { N_("Month"),      2, date_item},
@@ -156,6 +159,10 @@ static struct s_built_in_vars built_in_vars[] = {
 };
 
 
+/*
+ * Search the table of built-in variables, and if found,
+ *   call the appropriate subroutine to do the work.
+ */
 static var_rc_t lookup_built_in_var(var_t *ctx, void *my_ctx, 
          const char *var_ptr, int var_len, int var_index, 
          const char **val_ptr, int *val_len, int *val_size)
@@ -200,30 +207,32 @@ static var_rc_t lookup_counter_var(var_t *ctx, void *my_ctx,
         *val_ptr = bstrdup(buf);
         *val_len = strlen(buf);
         *val_size = *val_len;
-        if (var_inc && counter->Catalog) {
-           COUNTER_DBR cr;
-           JCR *jcr = (JCR *)my_ctx;
-           memset(&cr, 0, sizeof(cr));
-           bstrncpy(cr.Counter, counter->hdr.name, sizeof(cr.Counter));
-           cr.MinValue = counter->MinValue;
-           cr.MaxValue = counter->MaxValue;
+        if (var_inc) {               /* increment the variable? */
            if (counter->CurrentValue == counter->MaxValue) {
               counter->CurrentValue = counter->MinValue;
            } else {
               counter->CurrentValue++;
            }
-           cr.CurrentValue = counter->CurrentValue;
-            Dmsg1(100, "New value=%d\n", cr.CurrentValue);
-           if (counter->WrapCounter) {
-              bstrncpy(cr.WrapCounter, counter->WrapCounter->hdr.name, sizeof(cr.WrapCounter));
-           } else {
-              cr.WrapCounter[0] = 0;
-           }
-           if (!db_update_counter_record(jcr, jcr->db, &cr)) {
-               Jmsg(jcr, M_ERROR, 0, _("Count not update counter %s: ERR=%s\n"),
-                 counter->hdr.name, db_strerror(jcr->db));
+           if (counter->Catalog) {   /* update catalog if need be */
+              COUNTER_DBR cr;
+              JCR *jcr = (JCR *)my_ctx;
+              memset(&cr, 0, sizeof(cr));
+              bstrncpy(cr.Counter, counter->hdr.name, sizeof(cr.Counter));
+              cr.MinValue = counter->MinValue;
+              cr.MaxValue = counter->MaxValue;
+              cr.CurrentValue = counter->CurrentValue;
+               Dmsg1(100, "New value=%d\n", cr.CurrentValue);
+              if (counter->WrapCounter) {
+                 bstrncpy(cr.WrapCounter, counter->WrapCounter->hdr.name, sizeof(cr.WrapCounter));
+              } else {
+                 cr.WrapCounter[0] = 0;
+              }
+              if (!db_update_counter_record(jcr, jcr->db, &cr)) {
+                  Jmsg(jcr, M_ERROR, 0, _("Count not update counter %s: ERR=%s\n"),
+                    counter->hdr.name, db_strerror(jcr->db));
+              }
            }
-        }  
+        }       
         stat = VAR_OK;
         break;
       }
@@ -234,7 +243,7 @@ static var_rc_t lookup_counter_var(var_t *ctx, void *my_ctx,
 
 
 /*
- * Called here to look up a variable   
+ * Called here from "core" expand code to look up a variable   
  */
 static var_rc_t lookup_var(var_t *ctx, void *my_ctx, 
          const char *var_ptr, int var_len, int var_inc, int var_index, 
@@ -244,6 +253,7 @@ static var_rc_t lookup_var(var_t *ctx, void *my_ctx,
    var_rc_t stat;
    int count;
 
+   /* Note, if val_size > 0 and val_ptr!=NULL, the core code will free() it */
    if ((stat = lookup_built_in_var(ctx, my_ctx, var_ptr, var_len, var_index,
        val_ptr, val_len, val_size)) == VAR_OK) {
       return VAR_OK;
@@ -268,7 +278,7 @@ static var_rc_t lookup_var(var_t *ctx, void *my_ctx,
    if (var_index == 0) {
       *val_ptr = val;
       *val_len = strlen(val);
-      *val_size = 0;
+      *val_size = 0;                  /* don't try to free val_ptr */
       return VAR_OK;
    }
    /* He wants to index the "array" */
index ac74fa27fb8332517bae597444dcd89f7151f793..4ad2c704d25120d04c8bb966b358f3410462a2af 100644 (file)
@@ -60,7 +60,7 @@ static void usage()
 {
    fprintf(stderr, _(
 "\nVersion: " VERSION " (" BDATE ")\n\n"
-"Usage: filed [-f -s] [-c config_file] [-d debug_level] [config_file]\n"  
+"Usage: bacula-fd [-f -s] [-c config_file] [-d debug_level]\n"  
 "        -c <file>   use <file> as configuration file\n"
 "        -dnn        set debug level to nn\n"
 "        -f          run in foreground (for debugging)\n"
index 23df92aa289460db3cec67ec6d8e440ef9f72d8c..6ab088c8236c200ea56f2a4ded1b35b33cc23215 100755 (executable)
@@ -60,8 +60,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR CmdLine, int iCmdShow)
 {
    char *szCmdLine = CmdLine;
-   char *wordPtr,*tempPtr;
-   int i,quote;
+   char *wordPtr, *tempPtr;
+   int i, quote;
 
    /* Save the application instance and main thread id */
    hAppInstance = hInstance;
@@ -80,15 +80,17 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
     * the last character before first space is a double
     * quote, we throw away the junk.
     */
+
    wordPtr = szCmdLine;
    while (*wordPtr && *wordPtr != ' ')
       wordPtr++;
    if (wordPtr > szCmdLine)      /* backup to char before space */
       wordPtr--;
    /* if first character is not a quote and last is, junk it */
-   if (*szCmdLine != '"' && *wordPtr == '"')
+   if (*szCmdLine != '"' && *wordPtr == '"') {
       szCmdLine = wordPtr + 1;
-   //      MessageBox(NULL, szCmdLine, "Cmdline", MB_OK);
+   }
+// MessageBox(NULL, szCmdLine, "Cmdline", MB_OK);
 
    /* Build Unix style argc *argv[] */      
 
index ae777fbea83ea765dd09208279bdc7f52919cdf2..87d043a2860fafa42b0075fdca2a41fff5fd2f6c 100644 (file)
@@ -690,11 +690,12 @@ parse_opargtext_or_variable(
                goto error_return;
            }
        }
+       tokenbuf_free(&tmp);          /* KES 11/9/2003 */
     } while (rc > 0);
     tokenbuf_free(&tmp);
     return (p - begin);
 
-    error_return:
+error_return:
     tokenbuf_free(&tmp);
     tokenbuf_free(result);
     return rc;
@@ -740,12 +741,13 @@ parse_exptext_or_variable(
                goto error_return;
            }
        }
+       tokenbuf_free(&tmp);          /* KES 11/9/2003 */
     } while (rc > 0);
 
     tokenbuf_free(&tmp);
     return (p - begin);
 
-    error_return:
+error_return:
     tokenbuf_free(&tmp);
     tokenbuf_free(result);
     return rc;
@@ -791,12 +793,13 @@ parse_substext_or_variable(
                goto error_return;
            }
        }
+       tokenbuf_free(&tmp);          /* KES 11/9/2003 */
     } while (rc > 0);
 
     tokenbuf_free(&tmp);
     return (p - begin);
 
-    error_return:
+error_return:
     tokenbuf_free(&tmp);
     tokenbuf_free(result);
     return rc;
@@ -934,7 +937,7 @@ op_transpose(
     tokenbuf_free(&dstclass);
     return VAR_OK;
 
-    error_return:
+error_return:
     tokenbuf_free(search);
     tokenbuf_free(replace);
     tokenbuf_free(&srcclass);
@@ -1633,7 +1636,7 @@ parse_operation(
     return (p - begin);
 
     /* return with an error */
-    error_return:
+error_return:
     tokenbuf_free(data);
     tokenbuf_free(&tmptokbuf);
     tokenbuf_free(&search);
@@ -1695,10 +1698,10 @@ parse_numexp_operand(
                return rc;
            p += rc;
            *result = 0;
-       }
-       else if (rc < 0)
+           tokenbuf_free(&tmp);      /* KES 11/9/2003 */
+       } else if (rc < 0) {
            return rc;
-       else {
+       else {
            p += rc;
            /* parse remaining numerical expression */
            rc = parse_numexp(var, ctx, tmp.begin, tmp.end, result, failed);
@@ -1926,6 +1929,7 @@ parse_variable_complex(
            }
            p += rc;
        }
+       tokenbuf_free(&tmp);          /* KES 11/9/2003 */
     } while (rc > 0);
 
     /* we must have the complete expanded variable name now, 
@@ -1996,7 +2000,7 @@ parse_variable_complex(
     }
 
     /* parse optional post-operations */
-    goahead:
+goahead:
     if (p[-1] == ':') {
        tokenbuf_free(&tmp);
        tokenbuf_init(&tmp);
@@ -2029,9 +2033,9 @@ parse_variable_complex(
        if (ctx->force_expand) {
            rc = VAR_ERR_UNDEFINED_VARIABLE;
            goto error_return;
-       }
-       else
+       } else {
            tokenbuf_set(result, begin - 1, p, 0);
+       }
     }
 
     /* return successfully */
@@ -2040,7 +2044,7 @@ parse_variable_complex(
     return (p - begin);
 
     /* return with an error */
-    error_return:
+error_return:
     tokenbuf_free(&name);
     tokenbuf_free(&tmp);
     tokenbuf_free(result);