Skip to content

Commit

Permalink
Don't use me global variable in debug mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 18b7db2 commit 0519a4b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
23 changes: 12 additions & 11 deletions src/dird/dird.c
Expand Up @@ -67,10 +67,10 @@ void init_device_resources();
static char *runjob = NULL;
static bool background = true;
static void init_reload(void);
static CONFIG *config;

/* Globals Exported */
DIRRES *me; /* "Global" daemon resource */
DIRRES *me = NULL; /* Our Global resource */
CONFIG *my_config = NULL; /* Our Global config */
char *configfile = NULL;
void *start_heap;

Expand Down Expand Up @@ -281,8 +281,8 @@ int main (int argc, char *argv[])
drop(uid, gid, false); /* reduce privileges if requested */
}

config = new_config_parser();
parse_dir_config(config, configfile, M_ERROR_TERM);
my_config = new_config_parser();
parse_dir_config(my_config, configfile, M_ERROR_TERM);

if (init_crypto() != 0) {
Jmsg((JCR *)NULL, M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
Expand Down Expand Up @@ -397,10 +397,10 @@ void terminate_dird(int sig)
if (debug_level > 5) {
print_memory_pool_stats();
}
if (config) {
config->free_resources();
free(config);
config = NULL;
if (my_config) {
my_config->free_resources();
free(my_config);
my_config = NULL;
}
stop_UA_server();
term_msg(); /* terminate message handler */
Expand Down Expand Up @@ -533,10 +533,10 @@ void reload_config(int sig)
db_sql_pool_flush();

Dmsg1(100, "Reload_config njobs=%d\n", njobs);
reload_table[table].res_table = config->save_resources();
reload_table[table].res_table = my_config->save_resources();
Dmsg1(100, "Saved old config in table %d\n", table);

ok = parse_dir_config(config, configfile, M_ERROR);
ok = parse_dir_config(my_config, configfile, M_ERROR);

Dmsg0(100, "Reloaded config file\n");
if (!ok || !check_resources() || !check_catalog(UPDATE_CATALOG) || !initialize_sql_pooling()) {
Expand All @@ -548,7 +548,7 @@ void reload_config(int sig)
Jmsg(NULL, M_ERROR, 0, _("Please correct configuration file: %s\n"), configfile);
Jmsg(NULL, M_ERROR, 0, _("Resetting previous configuration.\n"));
}
reload_table[rtable].res_table = config->save_resources();
reload_table[rtable].res_table = my_config->save_resources();
/* Now restore old resource values */
int num = r_last - r_first + 1;
RES **res_tab = reload_table[table].res_table;
Expand Down Expand Up @@ -612,6 +612,7 @@ static bool check_resources()
"Without that I don't know who I am :-(\n"), configfile);
OK = false;
} else {
my_config->m_omit_defaults = me->omit_defaults;
set_working_directory(me->working_directory);
if (!me->messages) { /* If message resource not specified */
me->messages = (MSGSRES *)GetNextRes(R_MSGS, NULL);
Expand Down
3 changes: 2 additions & 1 deletion src/dird/dird.h
Expand Up @@ -43,7 +43,8 @@
#include "jobq.h"

/* Globals that dird.c exports */
extern DIRRES *me; /* "Global" daemon resource */
extern DIRRES *me; /* Our Global resource */
extern CONFIG *my_config; /* Our Global config */

/* Used in ua_prune.c and ua_purge.c */

Expand Down
24 changes: 12 additions & 12 deletions src/dird/dird_conf.c
Expand Up @@ -699,9 +699,9 @@ static inline void print_config_size(RES_ITEM *item, POOL_MEM &cfg_str)
1 /* byte */
};

if ((item->flags & CFG_ITEM_REQUIRED) || !me->omit_defaults) {
if ((item->flags & CFG_ITEM_REQUIRED) || !my_config->m_omit_defaults) {
/*
* Always print required items or if me->omit_defaults is false
* Always print required items or if my_config->m_omit_defaults is false
*/
print_item = true;
} else if (item->flags & CFG_ITEM_DEFAULT) {
Expand Down Expand Up @@ -775,9 +775,9 @@ static inline void print_config_time(RES_ITEM *item, POOL_MEM &cfg_str)
0
};

if ((item->flags & CFG_ITEM_REQUIRED) || !me->omit_defaults) {
if ((item->flags & CFG_ITEM_REQUIRED) || !my_config->m_omit_defaults) {
/*
* Always print required items or if me->omit_defaults is false
* Always print required items or if my_config->m_omit_defaults is false
*/
print_item = true;
} else if (item->flags & CFG_ITEM_DEFAULT) {
Expand Down Expand Up @@ -1276,9 +1276,9 @@ bool BRSRES::print_config(POOL_MEM &buff)
/*
* String types
*/
if ((items[i].flags & CFG_ITEM_REQUIRED) || !me->omit_defaults) {
if ((items[i].flags & CFG_ITEM_REQUIRED) || !my_config->m_omit_defaults) {
/*
* Always print required items or if me->omit_defaults is false
* Always print required items or if my_config->m_omit_defaults is false
*/
print_item = true;
} else if (items[i].flags & CFG_ITEM_DEFAULT) {
Expand All @@ -1305,9 +1305,9 @@ bool BRSRES::print_config(POOL_MEM &buff)
s_password *password;

password = items[i].pwdvalue;
if ((items[i].flags & CFG_ITEM_REQUIRED) || !me->omit_defaults) {
if ((items[i].flags & CFG_ITEM_REQUIRED) || !my_config->m_omit_defaults) {
/*
* Always print required items or if me->omit_defaults is false
* Always print required items or if my_config->m_omit_defaults is false
*/
print_item = true;
} else if (items[i].flags & CFG_ITEM_DEFAULT) {
Expand Down Expand Up @@ -1356,9 +1356,9 @@ bool BRSRES::print_config(POOL_MEM &buff)
/*
* Integer types
*/
if ((items[i].flags & CFG_ITEM_REQUIRED) || !me->omit_defaults) {
if ((items[i].flags & CFG_ITEM_REQUIRED) || !my_config->m_omit_defaults) {
/*
* Always print required items or if me->omit_defaults is false
* Always print required items or if my_config->m_omit_defaults is false
*/
print_item = true;
} else if (items[i].flags & CFG_ITEM_DEFAULT) {
Expand Down Expand Up @@ -1386,9 +1386,9 @@ bool BRSRES::print_config(POOL_MEM &buff)
print_config_time(&items[i], cfg_str);
break;
case CFG_TYPE_BOOL:
if ((items[i].flags & CFG_ITEM_REQUIRED) || !me->omit_defaults) {
if ((items[i].flags & CFG_ITEM_REQUIRED) || !my_config->m_omit_defaults) {
/*
* Always print required items or if me->omit_defaults is false
* Always print required items or if my_config->m_omit_defaults is false
*/
print_item = true;
} else if (items[i].flags & CFG_ITEM_DEFAULT) {
Expand Down
27 changes: 14 additions & 13 deletions src/lib/parse_conf.h
Expand Up @@ -229,22 +229,23 @@ typedef void (STORE_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
*/
class CONFIG {
public:
const char *m_cf; /* config file */
LEX_ERROR_HANDLER *m_scan_error; /* error handler if non-null */
LEX_WARNING_HANDLER *m_scan_warning; /* warning handler if non-null */
INIT_RES_HANDLER *m_init_res; /* init resource handler for non default types if non-null */
STORE_RES_HANDLER *m_store_res; /* store resource handler for non default types if non-null */
const char *m_cf; /* Config file */
LEX_ERROR_HANDLER *m_scan_error; /* Error handler if non-null */
LEX_WARNING_HANDLER *m_scan_warning; /* Warning handler if non-null */
INIT_RES_HANDLER *m_init_res; /* Init resource handler for non default types if non-null */
STORE_RES_HANDLER *m_store_res; /* Store resource handler for non default types if non-null */

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 */
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 */
bool m_omit_defaults; /* Omit config variables with default values when dumping the config */

/* The below are not yet implemented */
int32_t m_r_first; /* first daemon resource type */
int32_t 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 */
int32_t m_r_first; /* First daemon resource type */
int32_t 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(
Expand Down

0 comments on commit 0519a4b

Please sign in to comment.