Skip to content

Commit

Permalink
config: introduce ResHeadContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz authored and alaaeddineelamri committed Aug 4, 2022
1 parent 9af9bff commit dad0ea1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/src/dird/dird.cc
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ bool DoReloadConfig()
int num_rcodes = my_config->r_num_;
for (int i = 0; i < num_rcodes; i++) {
// restore original config
my_config->res_head_[i] = prev_config.res_table[i];
my_config->res_head_container_->res_head_[i] = prev_config.res_table[i];
}

// me is changed above by CheckResources()
Expand Down
9 changes: 5 additions & 4 deletions core/src/dird/ua_output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ static void ShowAll(UaContext* ua, bool hide_sensitive_data, bool verbose)
// Skip R_DEVICE since it is really not used or updated
continue;
default:
if (my_config->res_head_[j]) {
my_config->DumpResourceCb_(j, my_config->res_head_[j], bsendmsg, ua,
hide_sensitive_data, verbose);
if (my_config->res_head_container_->res_head_[j]) {
my_config->DumpResourceCb_(
j, my_config->res_head_container_->res_head_[j], bsendmsg, ua,
hide_sensitive_data, verbose);
}
break;
}
Expand Down Expand Up @@ -263,7 +264,7 @@ bool show_cmd(UaContext* ua, const char* cmd)
len)) {
type = show_cmd_available_resources[j].type;
if (type > 0) {
res = my_config->res_head_[type];
res = my_config->res_head_container_->res_head_[type];
} else {
res = NULL;
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/lib/parse_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,19 @@ ConfigurationParser::ConfigurationParser(
SaveResourceCb_ = SaveResourceCb;
DumpResourceCb_ = DumpResourceCb;
FreeResourceCb_ = FreeResourceCb;
res_head_container_.reset(new ResHeadContainer(this, res_head_));
}

ConfigurationParser::~ConfigurationParser()
{
#if 0
if (res_head_) {
for (int i = 0; i <= r_num_ - 1; i++) {
if (res_head_[i]) { FreeResourceCb_(res_head_[i], i); }
res_head_[i] = nullptr;
}
}
#endif
}

void ConfigurationParser::InitializeQualifiedResourceNameTypeConverter(
Expand Down
38 changes: 35 additions & 3 deletions core/src/lib/parse_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
struct ResourceItem;
class ConfigParserStateMachine;
class ConfigurationParser;

class ResHeadContainer;
/* For storing name_addr items in res_items table */

/* using offsetof on non-standard-layout types is conditionally supported. As
Expand Down Expand Up @@ -217,8 +217,11 @@ class ConfigurationParser {
int32_t r_own_; /* own resource type */
BareosResource* own_resource_; /* Pointer to own resource */
ResourceTable*
resource_definitions_; /* Pointer to table of permitted resources */
BareosResource** res_head_; /* Pointer to defined resources */
resource_definitions_; /* Pointer to table of permitted resources */
private:
BareosResource** res_head_; /* Pointer to defined resources */
public:
std::shared_ptr<ResHeadContainer> res_head_container_;
mutable brwlock_t res_lock_; /* Resource lock */

SaveResourceCb_t SaveResourceCb_;
Expand Down Expand Up @@ -413,6 +416,35 @@ class ConfigurationParser {
void SetResourceDefaultsParserPass2(ResourceItem* item);
};

struct ResHeadContainer {
BareosResource** res_head_;
ConfigurationParser* config_;
ResHeadContainer(ConfigurationParser* config, BareosResource** res_head)
{
res_head_ = res_head;
config_ = config;
printf("ResHeadContainer::ResHeadContainer : res_head_ is at %p\n",
res_head_);
}

~ResHeadContainer()
{
int num = config_->r_num_;
for (int j = 0; j < num; j++) {
config_->FreeResourceCb_(res_head_[j], j);
res_head_[j] = nullptr;
}
printf("ResHeadContainer::~ResHeadContainer : feeing restable at %p\n",
res_head_);
// free(res_head_);
printf("ResHeadContainer::~ResHeadContainer : freed restable at %p\n",
res_head_);
// Dmsg0(100, "ResHeadContainer::~ResHeadContainer : freed restable at
// %p\n", res_head_);
}
};


bool PrintMessage(void* sock, const char* fmt, ...);
bool IsTlsConfigured(TlsResource* tls_resource);

Expand Down
2 changes: 0 additions & 2 deletions core/src/tests/test_config_parser_dir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ TEST(ConfigParser_Dir, bareos_configparser_tests)

delete my_config;
}

TEST(ConfigParser_Dir, runscript_test)
{
OSDependentInit();
Expand Down Expand Up @@ -234,5 +233,4 @@ TEST(ConfigParser_Dir, CFG_TYPE_TIME)
test_config_directive_type(test_CFG_TYPE_TIME);
}


} // namespace directordaemon

0 comments on commit dad0ea1

Please sign in to comment.