From 7996a8e6221c890f0d2144c7d05d873bbe9b5777 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 10 Mar 2003 13:56:28 +0000 Subject: [PATCH] Another cut at Finclude structures git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@375 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dird_conf.c | 60 +++++++++++++------------- bacula/src/dird/dird_conf.h | 17 ++++++-- bacula/src/dird/fd_cmds.c | 26 ++++++++---- bacula/src/dird/inc_conf.c | 84 ++++++++++++++++++++++++++++--------- bacula/src/version.h | 4 +- 5 files changed, 131 insertions(+), 60 deletions(-) diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 844c7b4831..0b979273f5 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -586,6 +586,36 @@ next_run: } } +/* + * Free all the members of an INCEXE structure + */ +static void free_incexe(INCEXE *incexe) +{ + for (int i=0; inum_names; i++) { + free(incexe->name_list[i]); + } + if (incexe->name_list) { + free(incexe->name_list); + } + for (int i=0; inum_opts; i++) { + FOPTS *fopt = incexe->opts_list[i]; + if (fopt->match) { + free(fopt->match); + } + for (int j=0; jnum_base; j++) { + free(fopt->base_list[j]); + } + if (fopt->base_list) { + free(fopt->base_list); + } + free(fopt); + } + if (incexe->opts_list) { + free(incexe->opts_list); + } + free(incexe); +} + /* * Free memory of resource. * NB, we don't need to worry about freeing any references @@ -677,40 +707,14 @@ void free_resource(int type) case R_FILESET: if ((num=res->res_fs.num_includes)) { while (--num >= 0) { - INCEXE *incexe = res->res_fs.include_items[num]; - for (int i=0; inum_names; i++) { - free(incexe->name_list[i]); - } - if (incexe->name_list) { - free(incexe->name_list); - } - for (int i=0; inum_match; i++) { - free(incexe->match_list[i]); - } - if (incexe->match_list) { - free(incexe->match_list); - } - free(incexe); + free_incexe(res->res_fs.include_items[num]); } free(res->res_fs.include_items); } res->res_fs.num_includes = 0; if ((num=res->res_fs.num_excludes)) { while (--num >= 0) { - INCEXE *incexe = res->res_fs.exclude_items[num]; - for (int i=0; inum_names; i++) { - free(incexe->name_list[i]); - } - if (incexe->name_list) { - free(incexe->name_list); - } - for (int i=0; inum_match; i++) { - free(incexe->match_list[i]); - } - if (incexe->match_list) { - free(incexe->match_list); - } - free(incexe); + free_incexe(res->res_fs.exclude_items[num]); } free(res->res_fs.exclude_items); } diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index 63126b50e0..deb06feb5a 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -180,13 +180,22 @@ struct s_res_job { }; typedef struct s_res_job JOB; -#define MAX_FO_OPTS 30 +#define MAX_FOPTS 30 + +struct s_fopts_item { + char opts[MAX_FOPTS]; /* options string */ + char *match; /* match string */ + char **base_list; /* list of base job names */ + int num_base; /* number of bases in list */ +}; +typedef struct s_fopts_item FOPTS; + /* This is either an include item or an exclude item */ struct s_incexc_item { - char opts[MAX_FO_OPTS]; /* options string */ - char **match_list; /* match strings */ - int num_match; /* number of match strings */ + FOPTS *current_opts; /* points to current options structure */ + FOPTS **opts_list; /* options list */ + int num_opts; /* number of options items */ char **name_list; /* filename list */ int max_names; /* malloc'ed size of name list */ int num_names; /* number of names in the list */ diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 111cd7c69d..5af2618dde 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -143,8 +143,12 @@ int send_include_list(JCR *jcr) goto bail_out; } /* Copy File options */ - strcpy(buf, ie->opts); - strcat(buf, " "); + if (ie->num_opts) { + strcpy(buf, ie->opts_list[0]->opts); + strcat(buf, " "); + } else { + strcpy(buf, "0 "); + } optlen = strlen(buf); while (fgets(buf+optlen, sizeof(buf)-optlen, bpipe->rfd)) { fd->msglen = Mmsg(&fd->msg, "%s", buf); @@ -167,8 +171,12 @@ int send_include_list(JCR *jcr) goto bail_out; } /* Copy File options */ - strcpy(buf, ie->opts); - strcat(buf, " "); + if (ie->num_opts) { + strcpy(buf, ie->opts_list[0]->opts); + strcat(buf, " "); + } else { + strcpy(buf, "0 "); + } optlen = strlen(buf); while (fgets(buf+optlen, sizeof(buf)-optlen, ffd)) { fd->msglen = Mmsg(&fd->msg, "%s", buf); @@ -180,10 +188,14 @@ int send_include_list(JCR *jcr) fclose(ffd); break; default: - pm_strcpy(&fd->msg, ie->opts); - pm_strcat(&fd->msg, " "); + if (ie->num_opts) { + pm_strcpy(&fd->msg, ie->opts_list[0]->opts); + pm_strcat(&fd->msg, " "); + } else { + pm_strcpy(&fd->msg, "0 "); + } pm_strcat(&fd->msg, ie->name_list[j]); - Dmsg1(200, "Include name=%s\n", fd->msg); + Dmsg1(000, "Include name=%s\n", fd->msg); fd->msglen = strlen(fd->msg); if (!bnet_send(fd)) { Jmsg(jcr, M_FATAL, 0, _(">filed: write error on socket\n")); diff --git a/bacula/src/dird/inc_conf.c b/bacula/src/dird/inc_conf.c index da1d12f221..7883627618 100644 --- a/bacula/src/dird/inc_conf.c +++ b/bacula/src/dird/inc_conf.c @@ -37,6 +37,8 @@ void store_finc(LEX *lc, struct res_items *item, int index, int pass); static void store_match(LEX *lc, struct res_items *item, int index, int pass); static void store_opts(LEX *lc, struct res_items *item, int index, int pass); static void store_fname(LEX *lc, struct res_items *item, int index, int pass); +static void store_base(LEX *lc, struct res_items *item, int index, int pass); +static void setup_current_opts(void); /* We build the current resource here as we are @@ -65,7 +67,7 @@ static struct res_items finc_items[] = { {"replace", store_opts, NULL, 0, 0, 0}, {"match", store_match, NULL, 0, 0, 0}, {"file", store_fname, NULL, 0, 0, 0}, - + {"base", store_base, NULL, 0, 0, 0}, {NULL, NULL, NULL, 0, 0, 0} }; @@ -198,6 +200,7 @@ void store_inc(LEX *lc, struct res_items *item, int index, int pass) int inc_opts_len; lc->options |= LOPT_NO_IDENT; /* make spaces significant */ + memset(&res_incexe, 0, sizeof(INCEXE)); /* Get include options */ inc_opts[0] = 0; @@ -233,12 +236,15 @@ void store_inc(LEX *lc, struct res_items *item, int index, int pass) MD5Init(&res_all.res_fs.md5c); res_all.res_fs.have_MD5 = TRUE; } + setup_current_opts(); + bstrncpy(res_incexe.current_opts->opts, inc_opts, MAX_FOPTS); + Dmsg1(200, "incexe opts=%s\n", res_incexe.current_opts->opts); + /* Create incexe structure */ Dmsg0(200, "Create INCEXE structure\n"); incexe = (INCEXE *)malloc(sizeof(INCEXE)); - memset(incexe, 0, sizeof(INCEXE)); - bstrncpy(incexe->opts, inc_opts, sizeof(incexe->opts)); - Dmsg1(200, "incexe opts=%s\n", incexe->opts); + memcpy(incexe, &res_incexe, sizeof(INCEXE)); + memset(&res_incexe, 0, sizeof(INCEXE)); if (item->code == 0) { /* include */ if (res_all.res_fs.num_includes == 0) { res_all.res_fs.include_items = (INCEXE **)malloc(sizeof(INCEXE *)); @@ -347,7 +353,7 @@ void store_finc(LEX *lc, struct res_items *item, int index, int pass) if (pass == 1) { incexe = (INCEXE *)malloc(sizeof(INCEXE)); memcpy(incexe, &res_incexe, sizeof(INCEXE)); - Dmsg1(200, "incexe opts=%s\n", incexe->opts); + memset(&res_incexe, 0, sizeof(INCEXE)); if (item->code == 0) { /* include */ if (res_all.res_fs.num_includes == 0) { res_all.res_fs.include_items = (INCEXE **)malloc(sizeof(INCEXE *)); @@ -377,7 +383,6 @@ void store_finc(LEX *lc, struct res_items *item, int index, int pass) static void store_match(LEX *lc, struct res_items *item, int index, int pass) { int token; - char *match; if (pass == 1) { /* Pickup Match string @@ -387,19 +392,14 @@ static void store_match(LEX *lc, struct res_items *item, int index, int pass) case T_IDENTIFIER: case T_UNQUOTED_STRING: case T_QUOTED_STRING: - match = (char *)malloc(lc->str_len + 1); - strcpy(match, lc->str); - res_incexe.num_match++; - if (res_incexe.match_list == NULL) { - res_incexe.match_list = (char **)malloc(sizeof(char *) * res_incexe.num_match); - } else { - res_incexe.match_list = (char **)realloc(res_incexe.match_list, - sizeof(char *) * res_incexe.num_match); + setup_current_opts(); + if (res_incexe.current_opts->match) { + scan_err0(lc, _("More than one match specified.\n")); } - res_incexe.match_list[res_incexe.num_match-1] = match; + res_incexe.current_opts->match = bstrdup(lc->str); break; default: - scan_err1(lc, "Expected a filename, got: %s", lc->str); + scan_err1(lc, _("Expected a filename, got: %s\n"), lc->str); } } else { /* pass 2 */ lex_get_token(lc, T_ALL); @@ -407,8 +407,36 @@ static void store_match(LEX *lc, struct res_items *item, int index, int pass) scan_to_eol(lc); } +/* Store Base info */ +static void store_base(LEX *lc, struct res_items *item, int index, int pass) +{ + int token; + FOPTS *copt; -/* Store Filename info */ + if (pass == 1) { + setup_current_opts(); + /* + * Pickup Base Job Name + */ + token = lex_get_token(lc, T_NAME); + copt = res_incexe.current_opts; + if (copt->base_list == NULL) { + copt->base_list = (char **)malloc(sizeof(char *)); + } else { + copt->base_list = (char **)realloc(copt->base_list, + sizeof(char *) * (copt->num_base+1)); + } + copt->base_list[copt->num_base++] = bstrdup(lc->str); + } else { /* pass 2 */ + lex_get_token(lc, T_ALL); + } + scan_to_eol(lc); +} +/* + * Store Filename info. Note, for minor efficiency reasons, we + * always increase the name buffer by 10 items because we expect + * to add more entries. + */ static void store_fname(LEX *lc, struct res_items *item, int index, int pass) { int token; @@ -439,7 +467,7 @@ static void store_fname(LEX *lc, struct res_items *item, int index, int pass) Dmsg1(200, "Add to name_list %s\n", incexe->name_list[incexe->num_names -1]); break; default: - scan_err1(lc, "Expected a filename, got: %s", lc->str); + scan_err1(lc, _("Expected a filename, got: %s"), lc->str); } } else { /* pass 2 */ lex_get_token(lc, T_ALL); @@ -468,7 +496,25 @@ static void store_opts(LEX *lc, struct res_items *item, int index, int pass) Dmsg2(200, "keyword=%d %s\n", keyword, FS_option_kw[keyword].name); scan_include_options(lc, keyword, inc_opts, sizeof(inc_opts)); - bstrncat(res_incexe.opts, inc_opts, MAX_FO_OPTS); + if (pass == 1) { + setup_current_opts(); + + bstrncat(res_incexe.current_opts->opts, inc_opts, MAX_FOPTS); + } scan_to_eol(lc); } + + + +/* If current_opts not defined, create first entry */ +static void setup_current_opts(void) +{ + if (res_incexe.current_opts == NULL) { + res_incexe.current_opts = (FOPTS *)malloc(sizeof(FOPTS)); + memset(res_incexe.current_opts, 0, sizeof(FOPTS)); + res_incexe.num_opts = 1; + res_incexe.opts_list = (FOPTS **)malloc(sizeof(FOPTS *)); + res_incexe.opts_list[0] = res_incexe.current_opts; + } +} diff --git a/bacula/src/version.h b/bacula/src/version.h index d66a9a6521..3855f31ace 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.30" #define VSTRING "1" -#define BDATE "07 March 2003" -#define LSMDATE "07Mar03" +#define BDATE "10 March 2003" +#define LSMDATE "10Mar03" /* Debug flags */ #define DEBUG 1 -- 2.39.5