Skip to content

Commit

Permalink
Make default intialization somewhat more robust.
Browse files Browse the repository at this point in the history
A config entry with a default value but without the ITEM_DEFAULT
flag is almost always an error so just warn about it and set the flag so
we no longer get nasty surprises. Also found one additional error.
  • Loading branch information
Marco van Wieringen committed May 5, 2013
1 parent 4a2cf33 commit 9a86c90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/lib/parse_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ static inline void init_resource(CONFIG *config, int type, RES_ITEM *items, int
Dmsg3(900, "Item=%s def=%s defval=%s\n", items[i].name,
(items[i].flags & ITEM_DEFAULT) ? "yes" : "no",
(items[i].default_value) ? items[i].default_value : "None");

/*
* Sanity check.
*
* Items with a default value but without the ITEM_DEFAULT flag set
* are most of the time an indication of a programmers error.
*/
if (items[i].default_value != NULL && !(items[i].flags & ITEM_DEFAULT)) {
Pmsg1(000, _("Found config item %s which has default value but no ITEM_DEFAULT flag set\n"),
items[i].name);
items[i].flags |= ITEM_DEFAULT;
}

if (items[i].flags & ITEM_DEFAULT && items[i].default_value != NULL) {
/*
* First try to handle the generic types.
Expand Down
2 changes: 1 addition & 1 deletion src/stored/stored_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static RES_ITEM dev_items[] = {
{ "forwardspacefile", store_bit, ITEM(res_dev.cap_bits), CAP_FSF, ITEM_DEFAULT, "on" },
{ "fastforwardspacefile", store_bit, ITEM(res_dev.cap_bits), CAP_FASTFSF, ITEM_DEFAULT, "on" },
{ "removablemedia", store_bit, ITEM(res_dev.cap_bits), CAP_REM, ITEM_DEFAULT, "on" },
{ "randomaccess", store_bit, ITEM(res_dev.cap_bits), CAP_RACCESS, 0, "off" },
{ "randomaccess", store_bit, ITEM(res_dev.cap_bits), CAP_RACCESS, ITEM_DEFAULT, "off" },
{ "automaticmount", store_bit, ITEM(res_dev.cap_bits), CAP_AUTOMOUNT, ITEM_DEFAULT, "off" },
{ "labelmedia", store_bit, ITEM(res_dev.cap_bits), CAP_LABEL, ITEM_DEFAULT, "off" },
{ "alwaysopen", store_bit, ITEM(res_dev.cap_bits), CAP_ALWAYSOPEN, ITEM_DEFAULT, "on" },
Expand Down

0 comments on commit 9a86c90

Please sign in to comment.