From c879001a9d7a768affedf971d023f943eb1bf787 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 23 Jun 2008 06:41:41 +0000 Subject: [PATCH] kes Make first step toward eliminating globals from config scanning. Also should be a workaround for FORTIFY_SOURCE GNU C bug -- fixes bug #1042. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7219 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/console/console.c | 8 +++- bacula/src/console/console_conf.c | 13 ++++-- bacula/src/dird/dird.c | 23 ++++------ bacula/src/dird/dird_conf.c | 15 +++++-- bacula/src/dird/dird_conf.h | 6 +-- bacula/src/dird/ua_cmds.c | 3 -- bacula/src/dird/ua_dotcmds.c | 3 -- bacula/src/dird/ua_output.c | 4 -- bacula/src/dird/ua_server.c | 3 -- bacula/src/filed/filed.c | 12 +++-- bacula/src/filed/filed_conf.c | 15 +++++-- bacula/src/gnome2-console/console.c | 9 +++- bacula/src/gnome2-console/console_conf.c | 13 ++++-- bacula/src/lib/lib.h | 2 +- bacula/src/lib/parse_conf.c | 19 +++----- bacula/src/lib/parse_conf.h | 11 ++++- bacula/src/lib/protos.h | 2 +- bacula/src/lib/res.c | 6 +-- bacula/src/qt-console/bat_conf.cpp | 13 ++++-- bacula/src/qt-console/main.cpp | 6 ++- bacula/src/stored/bcopy.c | 7 ++- bacula/src/stored/bextract.c | 19 ++++---- bacula/src/stored/bls.c | 8 ++-- bacula/src/stored/bscan.c | 5 ++- bacula/src/stored/btape.c | 12 +++-- bacula/src/stored/dircmd.c | 2 - bacula/src/stored/status.c | 2 - bacula/src/stored/stored.c | 12 +++-- bacula/src/stored/stored_conf.c | 13 ++++-- bacula/src/tools/dbcheck.c | 10 +++-- bacula/src/tools/testfind.c | 12 ++++- bacula/src/tray-monitor/tray-monitor.c | 10 ++++- bacula/src/tray-monitor/tray_conf.c | 15 +++++-- bacula/src/version.h | 4 +- bacula/src/wx-console/console_conf.c | 57 +++++++++++++----------- bacula/src/wx-console/console_thread.cpp | 30 ++++++++----- bacula/src/wx-console/main.cpp | 2 +- bacula/technotes-2.5 | 3 ++ 38 files changed, 260 insertions(+), 149 deletions(-) diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 5553958b5b..91849d6280 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -61,6 +61,7 @@ /* Imported functions */ int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons); +extern bool parse_cons_config(CONFIG *config, const char *configfile, int exit_code); /* Forward referenced functions */ static void terminate_console(int sig); @@ -91,6 +92,7 @@ static int numcon; static POOLMEM *args; static char *argk[MAX_CMD_ARGS]; static char *argv[MAX_CMD_ARGS]; +static CONFIG *config; /* Command prototypes */ @@ -633,7 +635,8 @@ int main(int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + config = new_config_parser(); + parse_cons_config(config, configfile, M_ERROR_TERM); if (init_crypto() != 0) { Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n")); @@ -845,6 +848,9 @@ static void terminate_console(int sig) exit(1); } already_here = true; + config->free_resources(); + free(config); + config = NULL; cleanup_crypto(); free_pool_memory(args); if (!no_conio) { diff --git a/bacula/src/console/console_conf.c b/bacula/src/console/console_conf.c index 73165e828f..b2e1e0678d 100644 --- a/bacula/src/console/console_conf.c +++ b/bacula/src/console/console_conf.c @@ -54,8 +54,8 @@ * types. Note, these should be unique for each * daemon though not a requirement. */ -int r_first = R_FIRST; -int r_last = R_LAST; +int32_t r_first = R_FIRST; +int32_t r_last = R_LAST; static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; @@ -74,7 +74,7 @@ extern "C" { // work around visual compiler mangling variables #else URES res_all; #endif -int res_all_size = sizeof(res_all); +int32_t res_all_size = sizeof(res_all); /* Definition of records permitted within each * resource with the routine to process the record @@ -329,3 +329,10 @@ void save_resource(int type, RES_ITEM *items, int pass) } } } + +bool parse_cons_config(CONFIG *config, const char *configfile, int exit_code) +{ + config->init(configfile, NULL, exit_code, (void *)&res_all, res_all_size, + r_first, r_last, resources, res_head); + return config->parse_config(); +} diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 9a0326e7dd..e8104b4865 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -46,7 +46,7 @@ static void dir_sql_query(JCR *jcr, const char *cmd); /* Exported subroutines */ extern "C" void reload_config(int sig); extern void invalidate_schedules(); - +extern bool parse_dir_config(CONFIG *config, const char *configfile, int exit_code); /* Imported subroutines */ JCR *wait_for_next_job(char *runjob); @@ -74,15 +74,10 @@ char *configfile = NULL; void *start_heap; /* Globals Imported */ -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 - extern URES res_all; + extern URES res_all; } #else extern URES res_all; @@ -229,9 +224,7 @@ int main (int argc, char *argv[]) } config = new_config_parser(); - config->init(configfile, NULL, M_ERROR_TERM, (void *)&res_all, res_all_size, - r_first, r_last, resources, res_head); - config->parse_config(); + parse_dir_config(config, configfile, M_ERROR_TERM); if (init_crypto() != 0) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n")); @@ -355,9 +348,11 @@ void terminate_dird(int sig) if (debug_level > 5) { print_memory_pool_stats(); } - config->free_resources(); - free(config); - config = NULL; + if (config) { + config->free_resources(); + free(config); + config = NULL; + } term_ua_server(); term_msg(); /* terminate message handler */ cleanup_crypto(); @@ -486,7 +481,7 @@ void reload_config(int sig) reload_table[table].res_table = config->save_resources(); Dmsg1(100, "Saved old config in table %d\n", table); - ok = parse_config(configfile, 0, M_ERROR); /* no exit on error */ + ok = parse_dir_config(config, configfile, M_ERROR); Dmsg0(100, "Reloaded config file\n"); if (!ok || !check_resources() || !check_catalog()) { diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index fa9e345684..615c2699e0 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -57,8 +57,8 @@ * types. Note, these should be unique for each * daemon though not a requirement. */ -int r_first = R_FIRST; -int r_last = R_LAST; +int32_t r_first = R_FIRST; +int32_t r_last = R_LAST; static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; @@ -88,12 +88,12 @@ static void store_short_runscript(LEX *lc, RES_ITEM *item, int index, int pass); */ #if defined(_MSC_VER) extern "C" { // work around visual compiler mangling variables - URES res_all; + URES res_all; } #else URES res_all; #endif -int res_all_size = sizeof(res_all); +int32_t res_all_size = sizeof(res_all); /* Definition of records permitted within each @@ -1992,3 +1992,10 @@ extern "C" char *job_code_callback_filesetname(JCR *jcr, const char* param) return NULL; } } + +bool parse_dir_config(CONFIG *config, const char *configfile, int exit_code) +{ + config->init(configfile, NULL, exit_code, (void *)&res_all, res_all_size, + r_first, r_last, resources, res_head); + return config->parse_config(); +} diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index 8693318a7b..0d10339a8d 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -78,14 +78,14 @@ struct s_kw { /* Job Level keyword structure */ struct s_jl { const char *level_name; /* level keyword */ - uint32_t level; /* level */ - uint32_t job_type; /* JobType permitting this level */ + int32_t level; /* level */ + int32_t job_type; /* JobType permitting this level */ }; /* Job Type keyword structure */ struct s_jt { const char *type_name; - uint32_t job_type; + int32_t job_type; }; /* Definition of the contents of each Resource */ diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 063a1b4c55..6952b3b9bd 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -40,9 +40,6 @@ /* Imported subroutines */ /* Imported variables */ -extern int r_first; -extern int r_last; -extern struct s_res resources[]; extern jobq_t job_queue; /* job queue */ diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index ced146c49a..da23d78a36 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -42,9 +42,6 @@ #include "dird.h" /* Imported variables */ -extern int r_first; -extern int r_last; -extern struct s_res resources[]; /* Imported functions */ extern void do_messages(UAContext *ua, const char *cmd); diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index bf624fbca6..f9118cce67 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -41,10 +41,6 @@ /* Imported subroutines */ /* Imported variables */ -extern int r_first; -extern int r_last; -extern RES_TABLE resources[]; -extern RES **res_head; /* Imported functions */ diff --git a/bacula/src/dird/ua_server.c b/bacula/src/dird/ua_server.c index e7cb1002a6..80b2f1f442 100644 --- a/bacula/src/dird/ua_server.c +++ b/bacula/src/dird/ua_server.c @@ -38,9 +38,6 @@ #include "dird.h" /* Imported variables */ -extern int r_first; -extern int r_last; -extern struct s_res resources[]; /* Forward referenced functions */ diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index 1d731da927..fa5efee219 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -39,6 +39,7 @@ /* Imported Functions */ extern void *handle_client_request(void *dir_sock); +extern bool parse_fd_config(CONFIG *config, const char *configfile, int exit_code); /* Forward referenced functions */ void terminate_filed(int sig); @@ -56,7 +57,7 @@ char *configfile = NULL; static bool foreground = false; static workq_t dir_workq; /* queue of work from Director */ static pthread_t server_tid; - +static CONFIG *config; static void usage() { @@ -181,7 +182,8 @@ int main (int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + config = new_config_parser(); + parse_fd_config(config, configfile, M_ERROR_TERM); if (init_crypto() != 0) { Emsg0(M_ERROR, 0, _("Cryptography library initialization failed.\n")); @@ -262,8 +264,12 @@ void terminate_filed(int sig) if (debug_level > 0) { print_memory_pool_stats(); } + if (config) { + config->free_resources(); + free(config); + config = NULL; + } term_msg(); - free_config_resources(); cleanup_crypto(); close_memory_pool(); /* release free memory in pool */ sm_dump(false); /* dump orphaned buffers */ diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index 4641e9d6a4..c852236bde 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -56,8 +56,8 @@ * types. Note, these should be unique for each * daemon though not a requirement. */ -int r_first = R_FIRST; -int r_last = R_LAST; +int32_t r_first = R_FIRST; +int32_t r_last = R_LAST; static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; @@ -72,12 +72,12 @@ RES **res_head = sres_head; */ #if defined(_MSC_VER) extern "C" { // work around visual compiler mangling variables - URES res_all; + URES res_all; } #else URES res_all; #endif -int res_all_size = sizeof(res_all); +int32_t res_all_size = sizeof(res_all); /* Definition of records permitted within each * resource with the routine to process the record @@ -445,3 +445,10 @@ void save_resource(int type, RES_ITEM *items, int pass) } } } + +bool parse_fd_config(CONFIG *config, const char *configfile, int exit_code) +{ + config->init(configfile, NULL, exit_code, (void *)&res_all, res_all_size, + r_first, r_last, resources, res_head); + return config->parse_config(); +} diff --git a/bacula/src/gnome2-console/console.c b/bacula/src/gnome2-console/console.c index 1916de1979..1aa6d11672 100644 --- a/bacula/src/gnome2-console/console.c +++ b/bacula/src/gnome2-console/console.c @@ -43,6 +43,8 @@ /* Imported functions */ int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons); void select_restore_setup(); +extern bool parse_gcons_config(CONFIG *config, const char *configfile, int exit_code); + /* Dummy functions */ int generate_daemon_event(JCR *jcr, const char *event) { return 1; } @@ -92,6 +94,7 @@ static bool ready = false; static bool quit = false; static guint initial; static int numdir = 0; +static CONFIG *config; #define CONFIG_FILE "./bgnome-console.conf" /* default configuration file */ @@ -280,7 +283,8 @@ int main(int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + config = new_config_parser(); + parse_gcons_config(config, configfile, M_ERROR_TERM); if (init_crypto() != 0) { Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n")); @@ -694,6 +698,9 @@ void terminate_console(int sig) if (already_here) /* avoid recursive temination problems */ exit(1); already_here = true; + config->free_resources(); + free(config); + config = NULL; cleanup_crypto(); disconnect_from_director((gpointer)NULL); gtk_main_quit(); diff --git a/bacula/src/gnome2-console/console_conf.c b/bacula/src/gnome2-console/console_conf.c index 31b9b6c04c..74c833facc 100644 --- a/bacula/src/gnome2-console/console_conf.c +++ b/bacula/src/gnome2-console/console_conf.c @@ -56,8 +56,8 @@ * types. Note, these should be unique for each * daemon though not a requirement. */ -int r_first = R_FIRST; -int r_last = R_LAST; +int32_t r_first = R_FIRST; +int32_t r_last = R_LAST; static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; @@ -70,7 +70,7 @@ RES **res_head = sres_head; * scan is complete. */ URES res_all; -int res_all_size = sizeof(res_all); +int32_t res_all_size = sizeof(res_all); /* Definition of records permitted within each * resource with the routine to process the record @@ -334,3 +334,10 @@ void save_resource(int type, RES_ITEM *items, int pass) } } } + +bool parse_gcons_config(CONFIG *config, const char *configfile, int exit_code) +{ + config->init(configfile, NULL, exit_code, (void *)&res_all, res_all_size, + r_first, r_last, resources, res_head); + return config->parse_config(); +} diff --git a/bacula/src/lib/lib.h b/bacula/src/lib/lib.h index 7ecc0858a6..3820c3a334 100644 --- a/bacula/src/lib/lib.h +++ b/bacula/src/lib/lib.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 1811a5ade4..63003e8aea 100644 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -69,15 +69,6 @@ #define MAX_PATH 1024 #endif -/* Each daemon has a slightly different set of - * resources, so it will define the following - * global values. - */ -extern int r_first; -extern int r_last; -extern RES_TABLE resources[]; -extern RES **res_head; - /* * Define the Union of all the common resource structure definitions. */ @@ -93,7 +84,6 @@ extern "C" URES res_all; #else extern URES res_all; #endif -extern int res_all_size; extern brwlock_t res_lock; /* resource lock */ @@ -811,6 +801,7 @@ void CONFIG::init( * Note, the default behavior unless you have set an alternate * scan_error handler is to die on an error. */ +#ifdef xxx int parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type) { @@ -822,6 +813,7 @@ parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type) free(config); return ok; } +#endif bool CONFIG::parse_config() @@ -979,8 +971,8 @@ bool CONFIG::parse_config() } if (debug_level >= 900 && pass == 2) { int i; - for (i=r_first; i<=r_last; i++) { - dump_resource(i, res_head[i-r_first], prtmsg, NULL); + for (i=m_r_first; i<=m_r_last; i++) { + dump_resource(i, m_res_head[i-m_r_first], prtmsg, NULL); } } lc = lex_close_file(lc); @@ -1079,6 +1071,8 @@ RES **CONFIG::new_res_head() return res; } + +#ifdef xxx void free_config_resources() { for (int i=r_first; i<=r_last; i++) { @@ -1087,7 +1081,6 @@ void free_config_resources() } } -#ifdef xxx RES **save_config_resources() { int num = r_last - r_first + 1; diff --git a/bacula/src/lib/parse_conf.h b/bacula/src/lib/parse_conf.h index 898c916193..8012beeca4 100644 --- a/bacula/src/lib/parse_conf.h +++ b/bacula/src/lib/parse_conf.h @@ -38,6 +38,7 @@ 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 @@ -122,7 +123,7 @@ inline char *MSGS::name() const { return hdr.name; } /* * Old C style configuration routines -- deprecated do not use. */ -int parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error = NULL, int err_type=M_ERROR_TERM); +//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); RES **new_res_head(); @@ -138,6 +139,7 @@ public: int32_t m_err_type; /* the way to terminate on failure */ void *m_res_all; /* pointer to res_all buffer */ int32_t m_res_all_size; /* length of buffer */ + /* The below are not yet implemented */ int32_t m_r_first; /* first daemon resource type */ int32_t m_r_last; /* last daemon resource type */ @@ -208,3 +210,10 @@ void store_time(LEX *lc, RES_ITEM *item, int index, int pass); void store_size(LEX *lc, RES_ITEM *item, int index, int pass); void store_defs(LEX *lc, RES_ITEM *item, int index, int pass); void store_label(LEX *lc, RES_ITEM *item, int index, int pass); + +/* ***FIXME*** eliminate these globals */ +extern int32_t r_first; +extern int32_t r_last; +extern RES_TABLE resources[]; +extern RES **res_head; +extern int32_t res_all_size; diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index c5c153bdb6..80df88a0f4 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/src/lib/res.c b/bacula/src/lib/res.c index 4209943ffe..8ba547b5a3 100644 --- a/bacula/src/lib/res.c +++ b/bacula/src/lib/res.c @@ -40,13 +40,13 @@ * resources, so it will define the following * global values. */ -extern int r_first; -extern int r_last; +extern int32_t r_first; +extern int32_t r_last; extern RES_TABLE resources[]; extern RES **res_head; brwlock_t res_lock; /* resource lock */ -static int res_locked = 0; /* set when resource chains locked -- for debug */ +static int res_locked = 0; /* resource chain lock count -- for debug */ /* #define TRACE_RES */ diff --git a/bacula/src/qt-console/bat_conf.cpp b/bacula/src/qt-console/bat_conf.cpp index 8dca8462a3..403591caf2 100644 --- a/bacula/src/qt-console/bat_conf.cpp +++ b/bacula/src/qt-console/bat_conf.cpp @@ -56,8 +56,8 @@ * types. Note, these should be unique for each * daemon though not a requirement. */ -int r_first = R_FIRST; -int r_last = R_LAST; +int32_t r_first = R_FIRST; +int32_t r_last = R_LAST; static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; @@ -70,7 +70,7 @@ RES **res_head = sres_head; * scan is complete. */ URES res_all; -int res_all_size = sizeof(res_all); +int32_t res_all_size = sizeof(res_all); /* Definition of records permitted within each * resource with the routine to process the record @@ -338,3 +338,10 @@ void save_resource(int type, RES_ITEM *items, int pass) } } } + +bool parse_bat_config(CONFIG *config, const char *configfile, int exit_code) +{ + config->init(configfile, NULL, exit_code, (void *)&res_all, res_all_size, + r_first, r_last, resources, res_head); + return config->parse_config(); +} diff --git a/bacula/src/qt-console/main.cpp b/bacula/src/qt-console/main.cpp index 8a2f01667d..6e471829f7 100644 --- a/bacula/src/qt-console/main.cpp +++ b/bacula/src/qt-console/main.cpp @@ -47,9 +47,12 @@ void terminate_console(int sig); static void usage(); static int check_resources(); +extern bool parse_bat_config(CONFIG *config, const char *configfile, int exit_code); + #define CONFIG_FILE "./bat.conf" /* default configuration file */ /* Static variables */ +static CONFIG *config; static char *configfile = NULL; int main(int argc, char *argv[]) @@ -136,7 +139,8 @@ int main(int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + config = new_config_parser(); + parse_bat_config(config, configfile, M_ERROR_TERM); if (init_crypto() != 0) { Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n")); diff --git a/bacula/src/stored/bcopy.c b/bacula/src/stored/bcopy.c index e99662477a..dc302f45b2 100644 --- a/bacula/src/stored/bcopy.c +++ b/bacula/src/stored/bcopy.c @@ -40,6 +40,7 @@ /* Dummy functions */ int generate_daemon_event(JCR *jcr, const char *event) { return 1; } +extern bool parse_sd_config(CONFIG *config, const char *configfile, int exit_code); /* Forward referenced functions */ static void get_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *sessrec); @@ -59,6 +60,7 @@ static uint32_t jobs = 0; static DEV_BLOCK *out_block; static SESSION_LABEL sessrec; +static CONFIG *config; #define CONFIG_FILE "bacula-sd.conf" char *configfile = NULL; STORES *me = NULL; /* our Global resource */ @@ -74,7 +76,7 @@ PROG_COPYRIGHT "\nVersion: %s (%s)\n\n" "Usage: bcopy [-d debug_level] \n" " -b bootstrap specify a bootstrap file\n" -" -c specify configuration file\n" +" -c specify a Storage configuration file\n" " -d set debug level to \n" " -dt print timestamp in debug output\n" " -i specify input Volume names (separated by |)\n" @@ -169,7 +171,8 @@ int main (int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + config = new_config_parser(); + parse_sd_config(config, configfile, M_ERROR_TERM); /* Setup and acquire input device for reading */ Dmsg0(100, "About to setup input jcr\n"); diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 7679da70af..b8ef13157b 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -39,6 +39,8 @@ #include "stored.h" #include "findlib/find.h" +extern bool parse_sd_config(CONFIG *config, const char *configfile, int exit_code); + static void do_extract(char *fname); static bool record_cb(DCR *dcr, DEV_RECORD *rec); @@ -64,6 +66,7 @@ static char *wbuf; /* write buffer address */ static uint32_t wsize; /* write size */ static uint64_t fileAddr = 0; /* file write address */ +static CONFIG *config; #define CONFIG_FILE "bacula-sd.conf" char *configfile = NULL; STORES *me = NULL; /* our Global resource */ @@ -78,7 +81,7 @@ PROG_COPYRIGHT "\nVersion: %s (%s)\n\n" "Usage: bextract \n" " -b specify a bootstrap file\n" -" -c specify a configuration file\n" +" -c specify a Storage configuration file\n" " -d set debug level to \n" " -dt print timestamp in debug output\n" " -e exclude list\n" @@ -198,7 +201,8 @@ int main (int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + config = new_config_parser(); + parse_sd_config(config, configfile, M_ERROR_TERM); if (!got_inc) { /* If no include file, */ add_fname_to_include_list(ff, 0, "/"); /* include everything */ @@ -343,11 +347,11 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) build_attr_output_fnames(jcr, attr); - if (attr->type == FT_DELETED) { /* TODO: choose the right fname/ofname */ - Jmsg(jcr, M_INFO, 0, _("%s was deleted.\n"), attr->fname); - extract = false; - return true; - } + if (attr->type == FT_DELETED) { /* TODO: choose the right fname/ofname */ + Jmsg(jcr, M_INFO, 0, _("%s was deleted.\n"), attr->fname); + extract = false; + return true; + } extract = false; stat = create_file(jcr, attr, &bfd, REPLACE_ALWAYS); @@ -521,4 +525,3 @@ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatParts); return 1; } - diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 3e18ddb76f..0e3d9566f7 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -40,6 +40,7 @@ /* Dummy functions */ int generate_daemon_event(JCR *jcr, const char *event) { return 1; } +extern bool parse_sd_config(CONFIG *config, const char *configfile, int exit_code); static void do_blocks(char *infname); static void do_jobs(char *infname); @@ -58,6 +59,7 @@ static JCR *jcr; static SESSION_LABEL sessrec; static uint32_t num_files = 0; static ATTR *attr; +static CONFIG *config; #define CONFIG_FILE "bacula-sd.conf" char *configfile = NULL; @@ -78,7 +80,7 @@ PROG_COPYRIGHT "\nVersion: %s (%s)\n\n" "Usage: bls [options] \n" " -b specify a bootstrap file\n" -" -c specify a config file\n" +" -c specify a Storage configuration file\n" " -d set debug level to \n" " -dt print timestamp in debug output\n" " -e exclude list\n" @@ -214,7 +216,8 @@ int main (int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + config = new_config_parser(); + parse_sd_config(config, configfile, M_ERROR_TERM); if (ff->included_files_list == NULL) { add_fname_to_include_list(ff, 0, "/"); @@ -475,4 +478,3 @@ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatParts); return 1; } - diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index fde0ba1ff0..c55c0a0359 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -44,6 +44,7 @@ /* Dummy functions */ int generate_daemon_event(JCR *jcr, const char *event) { return 1; } +extern bool parse_sd_config(CONFIG *config, const char *configfile, int exit_code); /* Forward referenced functions */ static void do_scan(void); @@ -102,6 +103,7 @@ static int num_pools = 0; static int num_media = 0; static int num_files = 0; +static CONFIG *config; #define CONFIG_FILE "bacula-sd.conf" char *configfile = NULL; STORES *me = NULL; /* our Global resource */ @@ -251,7 +253,8 @@ int main (int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + config = new_config_parser(); + parse_sd_config(config, configfile, M_ERROR_TERM); LockRes(); me = (STORES *)GetNextRes(R_STORAGE, NULL); if (!me) { diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 95ecfc43e1..6a7844fcb9 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -50,6 +50,7 @@ /* Dummy functions */ int generate_daemon_event(JCR *jcr, const char *event) { return 1; } +extern bool parse_sd_config(CONFIG *config, const char *configfile, int exit_code); /* External subroutines */ extern void free_config_resources(); @@ -102,6 +103,7 @@ static void do_unfill(); /* Static variables */ +static CONFIG *config; #define CONFIG_FILE "bacula-sd.conf" char *configfile = NULL; @@ -269,8 +271,8 @@ int main(int margc, char *margv[]) daemon_start_time = time(NULL); - parse_config(configfile); - + config = new_config_parser(); + parse_sd_config(config, configfile, M_ERROR_TERM); /* See if we can open a device */ if (margc == 0) { @@ -321,7 +323,11 @@ static void terminate_btape(int stat) if (configfile) { free(configfile); } - free_config_resources(); + if (config) { + config->free_resources(); + free(config); + config = NULL; + } if (args) { free_pool_memory(args); args = NULL; diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index b2eb57dcfd..972c66fc8a 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -54,8 +54,6 @@ /* Imported variables */ extern BSOCK *filed_chan; -extern int r_first, r_last; -extern struct s_res resources[]; extern struct s_last_job last_job; extern bool init_done; diff --git a/bacula/src/stored/status.c b/bacula/src/stored/status.c index eb02eb2418..82b9a4dbb6 100644 --- a/bacula/src/stored/status.c +++ b/bacula/src/stored/status.c @@ -42,8 +42,6 @@ /* Imported variables */ extern BSOCK *filed_chan; -extern int r_first, r_last; -extern struct s_res resources[]; extern void *start_heap; /* Static variables */ diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 36ae297f39..d855d61c99 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -43,7 +43,7 @@ #include "stored.h" /* Imported functions */ - +extern bool parse_sd_config(CONFIG *config, const char *configfile, int exit_code); /* Forward referenced functions */ void terminate_stored(int sig); @@ -73,6 +73,7 @@ bool init_done = false; static bool foreground = 0; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static workq_t dird_workq; /* queue for processing connections */ +static CONFIG *config; static void usage() @@ -209,7 +210,8 @@ int main (int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + config = new_config_parser(); + parse_sd_config(config, configfile, M_ERROR_TERM); if (init_crypto() != 0) { Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n")); @@ -614,7 +616,11 @@ void terminate_stored(int sig) free(configfile); configfile = NULL; } - free_config_resources(); + if (config) { + config->free_resources(); + free(config); + config = NULL; + } if (debug_level > 10) { print_memory_pool_stats(); diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index dc141317af..fadf14feb9 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -37,8 +37,8 @@ #include "stored.h" /* First and last resource ids */ -int r_first = R_FIRST; -int r_last = R_LAST; +int32_t r_first = R_FIRST; +int32_t r_last = R_LAST; static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; @@ -56,7 +56,7 @@ extern "C" { // work around visual compiler mangling variables #else URES res_all; #endif -int res_all_size = sizeof(res_all); +int32_t res_all_size = sizeof(res_all); /* Definition of records permitted within each * resource with the routine to process the record @@ -681,3 +681,10 @@ void save_resource(int type, RES_ITEM *items, int pass) } } } + +bool parse_sd_config(CONFIG *config, const char *configfile, int exit_code) +{ + config->init(configfile, NULL, exit_code, (void *)&res_all, res_all_size, + r_first, r_last, resources, res_head); + return config->parse_config(); +} diff --git a/bacula/src/tools/dbcheck.c b/bacula/src/tools/dbcheck.c index 07a501e4f7..1b6a509c49 100644 --- a/bacula/src/tools/dbcheck.c +++ b/bacula/src/tools/dbcheck.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2002-2007 Free Software Foundation Europe e.V. + Copyright (C) 2002-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -41,6 +41,8 @@ #include "lib/runscript.h" #include "dird/dird_conf.h" +extern bool parse_dir_config(CONFIG *config, const char *configfile, int exit_code); + /* Dummy functions */ int generate_daemon_event(JCR *jcr, const char *event) { return 1; } @@ -71,6 +73,7 @@ static ID_LIST id_list; static NAME_LIST name_list; static char buf[20000]; static bool quit = false; +static CONFIG *config; #define MAX_ID_LIST_LEN 10000000 @@ -104,7 +107,7 @@ static void usage() "Usage: dbcheck [-c config] [-C catalog name] [-d debug_level] []\n" " -b batch mode\n" " -C catalog name in the director conf file\n" -" -c director conf filename\n" +" -c Director conf filename\n" " -d set debug level to \n" " -dt print timestamp in debug output\n" " -f fix inconsistencies\n" @@ -180,7 +183,8 @@ int main (int argc, char *argv[]) if (argc > 0) { Pmsg0(0, _("Warning skipping the additional parameters for working directory/dbname/user/password/host.\n")); } - parse_config(configfile); + config = new_config_parser(); + parse_dir_config(config, configfile, M_ERROR_TERM); LockRes(); foreach_res(catalog, R_CATALOG) { if (catalogname && !strcmp(catalog->hdr.name, catalogname)) { diff --git a/bacula/src/tools/testfind.c b/bacula/src/tools/testfind.c index 246b4df825..81dc27b131 100644 --- a/bacula/src/tools/testfind.c +++ b/bacula/src/tools/testfind.c @@ -44,6 +44,7 @@ int generate_daemon_event(JCR *jcr, const char *event) { return 1; } int generate_job_event(JCR *jcr, const char *event) { return 1; } void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) { } +extern bool parse_dir_config(CONFIG *config, const char *configfile, int exit_code); /* Global variables */ static int num_files = 0; @@ -52,6 +53,7 @@ static int max_path_len = 0; static int trunc_fname = 0; static int trunc_path = 0; static int attrs = 0; +static CONFIG *config; static JCR *jcr; @@ -133,7 +135,8 @@ main (int argc, char *const *argv) argc -= optind; argv += optind; - parse_config(configfile); + config = new_config_parser(); + parse_dir_config(config, configfile, M_ERROR_TERM); MSGS *msg; @@ -166,7 +169,12 @@ main (int argc, char *const *argv) find_files(jcr, ff, print_file, NULL); free_jcr(jcr); - free_config_resources(); + if (config) { + config->free_resources(); + free(config); + config = NULL; + } + term_last_jobs_list(); /* Clean up fileset */ diff --git a/bacula/src/tray-monitor/tray-monitor.c b/bacula/src/tray-monitor/tray-monitor.c index df2b46f09d..260bbbedec 100644 --- a/bacula/src/tray-monitor/tray-monitor.c +++ b/bacula/src/tray-monitor/tray-monitor.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2007 Free Software Foundation Europe e.V. + Copyright (C) 2004-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -46,6 +46,7 @@ int authenticate_director(JCR *jcr, MONITOR *monitor, DIRRES *director); int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client); int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store); +extern bool parse_tmon_config(CONFIG *config, const char *configfile, int exit_code); /* Dummy functions */ int generate_daemon_event(JCR *jcr, const char *event) { return 1; } @@ -63,6 +64,7 @@ static int nitems = 0; static int fullitem = 0; //Item to be display in detailled status window static int lastupdated = -1; //Last item updated static monitoritem items[32]; +static CONFIG *config; /* Data received from DIR/FD/SD */ static char OKqstatus[] = "%c000 OK .status\n"; @@ -253,7 +255,8 @@ int main(int argc, char *argv[]) configfile = bstrdup(CONFIG_FILE); } - parse_config(configfile); + config = new_config_parser(); + parse_tmon_config(config, configfile, M_ERROR_TERM); LockRes(); nitems = 0; @@ -529,6 +532,9 @@ int main(int argc, char *argv[]) gtk_object_destroy(GTK_OBJECT(window)); gtk_object_destroy(GTK_OBJECT(mTrayMenu)); + config->free_resources(); + free(config); + config = NULL; term_msg(); #if TRAY_DEBUG_MEMORY diff --git a/bacula/src/tray-monitor/tray_conf.c b/bacula/src/tray-monitor/tray_conf.c index d6d866ef52..6d0242d468 100644 --- a/bacula/src/tray-monitor/tray_conf.c +++ b/bacula/src/tray-monitor/tray_conf.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2007 Free Software Foundation Europe e.V. + Copyright (C) 2004-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -56,8 +56,8 @@ * types. Note, these should be unique for each * daemon though not a requirement. */ -int r_first = R_FIRST; -int r_last = R_LAST; +int32_t r_first = R_FIRST; +int32_t r_last = R_LAST; static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; @@ -67,7 +67,7 @@ RES **res_head = sres_head; * scan is complete. */ URES res_all; -int res_all_size = sizeof(res_all); +int32_t res_all_size = sizeof(res_all); /* Definition of records permitted within each @@ -379,3 +379,10 @@ void save_resource(int type, RES_ITEM *items, int pass) } } } + +bool parse_tmon_config(CONFIG *config, const char *configfile, int exit_code) +{ + config->init(configfile, NULL, exit_code, (void *)&res_all, res_all_size, + r_first, r_last, resources, res_head); + return config->parse_config(); +} diff --git a/bacula/src/version.h b/bacula/src/version.h index d9fd1b75b1..8cecadb8b8 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.5.1" -#define BDATE "20 June 2008" -#define LSMDATE "20Jun08" +#define BDATE "22 June 2008" +#define LSMDATE "22Jun08" #define PROG_COPYRIGHT "Copyright (C) %d-2008 Free Software Foundation Europe e.V.\n" #define BYEAR "2008" /* year for copyright messages in progs */ diff --git a/bacula/src/wx-console/console_conf.c b/bacula/src/wx-console/console_conf.c index 35979f793b..e9f5730a2a 100644 --- a/bacula/src/wx-console/console_conf.c +++ b/bacula/src/wx-console/console_conf.c @@ -1,28 +1,7 @@ -/* - * Main configuration file parser for Bacula User Agent - * some parts may be split into separate files such as - * the schedule configuration (sch_config.c). - * - * Note, the configuration file parser consists of three parts - * - * 1. The generic lexical scanner in lib/lex.c and lib/lex.h - * - * 2. The generic config scanner in lib/parse_config.c and - * lib/parse_config.h. - * These files contain the parser code, some utility - * routines, and the common store routines (name, int, - * string). - * - * 3. The daemon specific file, which contains the Resource - * definitions as well as any specific store routines - * for the resource records. - * - * Kern Sibbald, January MM, September MM - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -46,6 +25,27 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * Main configuration file parser for Bacula User Agent + * some parts may be split into separate files such as + * the schedule configuration (sch_config.c). + * + * Note, the configuration file parser consists of three parts + * + * 1. The generic lexical scanner in lib/lex.c and lib/lex.h + * + * 2. The generic config scanner in lib/parse_config.c and + * lib/parse_config.h. + * These files contain the parser code, some utility + * routines, and the common store routines (name, int, + * string). + * + * 3. The daemon specific file, which contains the Resource + * definitions as well as any specific store routines + * for the resource records. + * + * Kern Sibbald, January MM, September MM + */ /* _("...") macro returns a wxChar*, so if we need a char*, we need to convert it with: * wxString(_("...")).mb_str(*wxConvCurrent) */ @@ -66,8 +66,8 @@ * types. Note, these should be unique for each * daemon though not a requirement. */ -int r_first = R_FIRST; -int r_last = R_LAST; +int32_t r_first = R_FIRST; +int32_t r_last = R_LAST; static RES *sres_head[R_LAST - R_FIRST + 1]; RES **res_head = sres_head; @@ -86,7 +86,7 @@ extern "C" { // work around visual compiler mangling variables #else URES res_all; #endif -int res_all_size = sizeof(res_all); +int32_t res_all_size = sizeof(res_all); /* Definition of records permitted within each * resource with the routine to process the record @@ -335,3 +335,10 @@ void save_resource(int type, RES_ITEM *items, int pass) } } } + +bool parse_wxcons_config(CONFIG *config, const char *configfile, LEX_ERROR_HANDLER *scan_error) +{ + config->init(configfile, scan_error, M_ERROR_TERM, (void *)&res_all, res_all_size, + r_first, r_last, resources, res_head); + return config->parse_config(); +} diff --git a/bacula/src/wx-console/console_thread.cpp b/bacula/src/wx-console/console_thread.cpp index 964a7a5aa8..0d2c0f1294 100644 --- a/bacula/src/wx-console/console_thread.cpp +++ b/bacula/src/wx-console/console_thread.cpp @@ -1,15 +1,7 @@ -/* - * - * Interaction thread between director and the GUI - * - * Nicolas Boichat, April 2004 - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2006 Free Software Foundation Europe e.V. + Copyright (C) 2004-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -33,6 +25,14 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Interaction thread between director and the GUI + * + * Nicolas Boichat, April 2004 + * + * Version $Id$ + */ // http://66.102.9.104/search?q=cache:Djc1mPF3hRoJ:cvs.sourceforge.net/viewcvs.py/audacity/audacity-src/src/AudioIO.cpp%3Frev%3D1.102+macos+x+wxthread&hl=fr @@ -65,12 +65,16 @@ char TERM_msg[] = "2999 Terminate\n"; /* Imported functions */ int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons); +bool parse_wxcons_config(CONFIG *config, const char *cfgfile, LEX_ERROR_HANDLER *scan_error); bool console_thread::inited = false; bool console_thread::configloaded = false; wxString console_thread::working_dir = wxT("."); int numdir = 0; +static CONFIG *config = NULL; +static void scan_err(const char *file, int line, LEX *lc, const char *msg, ...); + /* * Call-back for reading a passphrase for an encrypted PEM file @@ -224,7 +228,10 @@ wxString console_thread::LoadConfig(wxString configfile) return _("Error while initializing library."); } - free_config_resources(); + if (config) { + config->free_resources(); + free(config); + } MSGS* msgs = (MSGS *)bmalloc(sizeof(MSGS)); memset(msgs, 0, sizeof(MSGS)); @@ -238,7 +245,8 @@ wxString console_thread::LoadConfig(wxString configfile) //init_console_msg(console_thread::working_dir.mb_str(*wxConvCurrent)); errmsg = wxT(""); - if (!parse_config(configfile.mb_str(*wxConvCurrent), &scan_err)) { + config = new_config_parser(); + if (!parse_wxcons_config(config, configfile.mb_str(*wxConvCurrent), &scan_err)) { configloaded = false; term_msg(); return errmsg; diff --git a/bacula/src/wx-console/main.cpp b/bacula/src/wx-console/main.cpp index 8091076e75..4b15b8021d 100644 --- a/bacula/src/wx-console/main.cpp +++ b/bacula/src/wx-console/main.cpp @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-20076 Free Software Foundation Europe e.V. + Copyright (C) 2004-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index 8eadc84422..7d4f3ca543 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -30,6 +30,9 @@ vtape driver General: +kes Make first step toward eliminating globals from config + scanning. Also should be a workaround for FORTIFY_SOURCE + GNU C bug -- fixes bug #1042. 21Jun08 kes Apply duplicate job tests to restarted jobs. kes Copy more data when restarting a job so that run -- 2.39.5