From 765ee0b4659ebba18766d555451a7b174520964b Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 27 Feb 2008 20:44:38 +0000 Subject: [PATCH] Eliminate FORTIFY_CODE=2 bug, and make first cut at removing daemon globals used by parser. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6501 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 5 ++++ bacula/src/dird/dird.c | 10 +++++-- bacula/src/filed/fd-plugins.c | 6 ++-- bacula/src/lib/parse_conf.c | 53 ++++++++++++++++++++++++++++++++--- bacula/src/lib/parse_conf.h | 40 ++++++++++++++++++++++++-- bacula/technotes-2.3 | 4 +++ 6 files changed, 107 insertions(+), 11 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index 769c92a92d..5a34b80e5b 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -118,6 +118,11 @@ Priority: Duplicate Job Proximity = (0) + My suggestion was to define it as the minimum guard time between + executions of a specific job -- ie, if a job was scheduled within Job + Proximity number of seconds, it would be considered a duplicate and + consolidated. + Skip = Do not allow two or more jobs with the same name to run simultaneously within the proximity interval. The second and subsequent jobs are skipped without further processing (other than to note the job diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index d6722a66a7..4cb1b27cb5 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -64,7 +64,8 @@ void init_device_resources(); static char *runjob = NULL; static int background = 1; static void init_reload(void); - +static PARSER *parser; + /* Globals Exported */ DIRRES *director; /* Director resource */ int FDConnectTimeout; @@ -77,6 +78,7 @@ extern int r_first, r_last; /* first and last resources */ extern RES_TABLE resources[]; extern RES **res_head; extern RES_ITEM job_items[]; +extern int res_all_size; #if defined(_MSC_VER) extern "C" { // work around visual compiler mangling variables @@ -226,7 +228,10 @@ int main (int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + parser = new_parser(); + parser->init(configfile, NULL, M_ERROR_TERM, (void *)&res_all, res_all_size, + r_first, r_last, resources, res_head); + parser->parse_config(); if (init_crypto() != 0) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n")); @@ -350,6 +355,7 @@ void terminate_dird(int sig) print_memory_pool_stats(); } free_config_resources(); + free(parser); term_ua_server(); term_msg(); /* terminate message handler */ cleanup_crypto(); diff --git a/bacula/src/filed/fd-plugins.c b/bacula/src/filed/fd-plugins.c index 8df62d1906..116b6799fe 100644 --- a/bacula/src/filed/fd-plugins.c +++ b/bacula/src/filed/fd-plugins.c @@ -137,13 +137,13 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level) struct save_pkt sp; bEvent event; - bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; - event.eventType = bEventBackupCommand; - if (!plugin_list) { return 1; /* Return if no plugins loaded */ } + bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; + event.eventType = bEventBackupCommand; + /* Handle plugin command here backup */ Dmsg1(100, "plugin cmd=%s\n", cmd); if (!(p = strchr(cmd, ':'))) { diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 6144714f98..110bfec8a6 100644 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -196,12 +196,12 @@ const char *res_to_str(int rcode) * Initialize the static structure to zeros, then * apply all the default values. */ -static void init_resource(int type, RES_ITEM *items, int pass) +static void init_resource(PARSER *parser, int type, RES_ITEM *items, int pass) { int i; int rindex = type - r_first; - memset((char *)&res_all, 0, res_all_size); + memset(parser->m_res_all, 0, parser->m_res_all_size); res_all.hdr.rcode = type; res_all.hdr.refcnt = 1; @@ -773,6 +773,36 @@ enum parse_state { p_resource }; +PARSER *new_parser() +{ + PARSER *parser; + parser = (PARSER *)malloc(sizeof(PARSER)); + memset(parser, 0, sizeof(PARSER)); + return parser; +} + +void PARSER::init( + const char *cf, + LEX_ERROR_HANDLER *scan_error, + int err_type, + void *vres_all, + int res_all_size, + int r_first, + int r_last, + RES_TABLE *resources, + RES **res_head) +{ + m_cf = cf; + m_scan_error = scan_error; + m_err_type = err_type; + m_res_all = vres_all; + m_res_all_size = res_all_size; + m_r_first = r_first; + m_r_last = r_last; + m_resources = resources; + m_res_head = res_head; +} + /********************************************************************* * * Parse configuration file @@ -783,6 +813,18 @@ enum parse_state { */ int parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type) +{ + int ok; + PARSER *parser = new_parser(); + parser->init(cf, scan_error, err_type, (void *)&res_all, res_all_size, + r_first, r_last, resources, res_head); + ok = parser->parse_config(); + free(parser); + return ok; +} + + +bool PARSER::parse_config() { LEX *lc = NULL; int token, i, pass; @@ -792,6 +834,9 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type) int level = 0; static bool first = true; int errstat; + const char *cf = m_cf; + LEX_ERROR_HANDLER *scan_error = m_scan_error; + int err_type = m_err_type; if (first && (errstat=rwl_init(&res_lock)) != 0) { berrno be; @@ -857,7 +902,7 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type) } state = p_resource; res_type = resources[i].rcode; - init_resource(res_type, items, pass); + init_resource(this, res_type, items, pass); break; } } @@ -970,7 +1015,7 @@ const char *get_default_configdir() #endif } -bool +static bool find_config_file(const char *config_file, char *full_path, int max_path) { if (first_path_separator(config_file) != NULL) { diff --git a/bacula/src/lib/parse_conf.h b/bacula/src/lib/parse_conf.h index 3e630b55fc..a480844ce6 100644 --- a/bacula/src/lib/parse_conf.h +++ b/bacula/src/lib/parse_conf.h @@ -37,6 +37,7 @@ struct RES_ITEM; /* Declare forward referenced structure */ class RES; /* Declare forware referenced structure */ typedef void (MSG_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass); + /* This is the structure that defines * the record types (items) permitted within each * resource. It is used to define the configuration @@ -65,7 +66,7 @@ struct RES_ITEM { /* For storing name_addr items in res_items table */ #define ITEM(x) {(char **)&res_all.x} -#define MAX_RES_ITEMS 70 /* maximum resource items per RES */ +#define MAX_RES_ITEMS 80 /* maximum resource items per RES */ /* This is the universal header that is * at the beginning of every resource @@ -93,6 +94,38 @@ struct RES_TABLE { int rcode; /* code if needed */ }; +class PARSER { +public: + const char *m_cf; /* config file */ + LEX_ERROR_HANDLER *m_scan_error; /* error handler if non-null */ + int m_err_type; /* the way to terminate on failure */ + void *m_res_all; /* pointer to res_all buffer */ + int m_res_all_size; /* length of buffer */ + /* The below are not yet implemented */ + int m_r_first; /* first daemon resource type */ + int m_r_last; /* last daemon resource type */ + RES_TABLE *m_resources; /* pointer to table of permitted resources */ + RES **m_res_head; /* pointer to defined resources */ + brwlock_t m_res_lock; /* resource lock */ + + /* functions */ + void init( + const char *cf, + LEX_ERROR_HANDLER *scan_error, + int err_type, + void *vres_all, + int res_all_size, + int r_first, + int r_last, + RES_TABLE *resources, + RES **res_head); + + bool parse_config(); +}; + +PARSER *new_parser(); + + /* Common Resource definitions */ #define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1 /* maximum resource name length */ @@ -117,6 +150,7 @@ public: inline char *MSGS::name() const { return hdr.name; } /* Configuration routines */ + int parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error = NULL, int err_type=M_ERROR_TERM); void free_config_resources(void); RES **save_config_resources(void); @@ -144,7 +178,9 @@ const char *res_to_str(int rcode); #endif - +/* + * Standard global parsers defined in parse_config.c + */ void store_str(LEX *lc, RES_ITEM *item, int index, int pass); void store_dir(LEX *lc, RES_ITEM *item, int index, int pass); void store_password(LEX *lc, RES_ITEM *item, int index, int pass); diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index ffbb33a2a9..0b9b941b6d 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,6 +1,10 @@ Technical notes on version 2.3 General: +27Feb08 +kes Eliminate FORTIFY_CODE=2 bug, and make first cut at removing + daemon globals used by parser. +kes Apply Joao's patch to separate DB_TYPE and DB_PROG in configure. 26Feb08 kes Fix free of plugin_list when none exists. 25Feb08 -- 2.39.5