From 25a226f1106ed93db0bcae444ea4d1f3de6ff6bf Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 11 Sep 2003 16:20:21 +0000 Subject: [PATCH] Fix counter bugs reported by Chris Allen git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@699 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/expand.c | 50 ++++++++++++++++++------------ bacula/src/filed/filed.c | 2 +- bacula/src/filed/win32/winmain.cpp | 10 +++--- bacula/src/lib/var.c | 28 ++++++++++------- 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/bacula/src/dird/expand.c b/bacula/src/dird/expand.c index 265faa7678..a36b788f37 100644 --- a/bacula/src/dird/expand.c +++ b/bacula/src/dird/expand.c @@ -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" */ diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index ac74fa27fb..4ad2c704d2 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -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 use as configuration file\n" " -dnn set debug level to nn\n" " -f run in foreground (for debugging)\n" diff --git a/bacula/src/filed/win32/winmain.cpp b/bacula/src/filed/win32/winmain.cpp index 23df92aa28..6ab088c823 100755 --- a/bacula/src/filed/win32/winmain.cpp +++ b/bacula/src/filed/win32/winmain.cpp @@ -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[] */ diff --git a/bacula/src/lib/var.c b/bacula/src/lib/var.c index ae777fbea8..87d043a286 100644 --- a/bacula/src/lib/var.c +++ b/bacula/src/lib/var.c @@ -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); -- 2.39.5