From 4d60c18ab1ed0f57f48639778e8ed2f09b0b7f3c Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Tue, 5 Apr 2022 17:02:06 +0200 Subject: [PATCH] config: rename res_head_container_ -> config_resources_container_ --- core/src/console/console_conf.cc | 3 -- core/src/dird/dird_conf.cc | 19 ++++---- core/src/dird/jcr_private.h | 8 ++-- core/src/dird/job.cc | 9 ++-- core/src/dird/ua_output.cc | 14 ++++-- core/src/dird/ua_server.cc | 4 +- core/src/filed/filed_conf.cc | 5 +- core/src/lib/parse_conf.cc | 59 +++++++++++------------- core/src/lib/parse_conf.h | 26 ++++++----- core/src/lib/parse_conf_state_machine.cc | 10 ++-- core/src/lib/res.cc | 4 +- core/src/qt-tray-monitor/tray_conf.cc | 5 +- core/src/stored/stored_conf.cc | 5 +- 13 files changed, 81 insertions(+), 90 deletions(-) diff --git a/core/src/console/console_conf.cc b/core/src/console/console_conf.cc index 8b0fafaa95a..b77202d5c3e 100644 --- a/core/src/console/console_conf.cc +++ b/core/src/console/console_conf.cc @@ -35,9 +35,6 @@ namespace console { -/* static BareosResource* sres_head[R_NUM]; */ -/* static BareosResource** res_head = sres_head; */ - static bool SaveResource(int type, ResourceItem* items, int pass); static void FreeResource(BareosResource* sres, int type); static void DumpResource(int type, diff --git a/core/src/dird/dird_conf.cc b/core/src/dird/dird_conf.cc index f4c02c5bf56..872c4854555 100644 --- a/core/src/dird/dird_conf.cc +++ b/core/src/dird/dird_conf.cc @@ -77,8 +77,6 @@ extern struct s_kw RunFields[]; * types. Note, these should be unique for each * daemon though not a requirement. */ -/* static BareosResource* sres_head[R_NUM]; */ -/* static BareosResource** res_head = sres_head; */ static PoolMem* configure_usage_string = NULL; extern void StoreInc(LEX* lc, ResourceItem* item, int index, int pass); @@ -2533,24 +2531,25 @@ static void StoreDevice(LEX* lc, ResourceItem* item, int index, int pass, - BareosResource** res_head) + BareosResource** configuration_resources) { int rindex = R_DEVICE; if (pass == 1) { LexGetToken(lc, BCT_NAME); - if (!res_head[rindex]) { + if (!configuration_resources[rindex]) { DeviceResource* device_resource = new DeviceResource; device_resource->rcode_ = R_DEVICE; device_resource->resource_name_ = strdup(lc->str); - res_head[rindex] = device_resource; /* store first entry */ + configuration_resources[rindex] = device_resource; /* store first entry */ Dmsg3(900, "Inserting first %s res: %s index=%d\n", my_config->ResToStr(R_DEVICE), device_resource->resource_name_, rindex); } else { bool found = false; BareosResource* next; - for (next = res_head[rindex]; next->next_; next = next->next_) { + for (next = configuration_resources[rindex]; next->next_; + next = next->next_) { if (bstrcmp(next->resource_name_, lc->str)) { found = true; // already defined break; @@ -2580,7 +2579,7 @@ static void StoreMigtype(LEX* lc, ResourceItem* item, int index, int pass, - BareosResource** res_head) + BareosResource** configuration_resources) { LexGetToken(lc, BCT_NAME); // Store the type both in pass 1 and pass 2 @@ -3216,7 +3215,7 @@ static void ParseConfigCb(LEX* lc, ResourceItem* item, int index, int pass, - BareosResource** res_head) + BareosResource** configuration_resources) { switch (item->type) { case CFG_TYPE_AUTOPASSWORD: @@ -3235,7 +3234,7 @@ static void ParseConfigCb(LEX* lc, StoreAuthtype(lc, item, index, pass); break; case CFG_TYPE_DEVICE: - StoreDevice(lc, item, index, pass, res_head); + StoreDevice(lc, item, index, pass, configuration_resources); break; case CFG_TYPE_JOBTYPE: StoreJobtype(lc, item, index, pass); @@ -3256,7 +3255,7 @@ static void ParseConfigCb(LEX* lc, StoreRunscript(lc, item, index, pass); break; case CFG_TYPE_MIGTYPE: - StoreMigtype(lc, item, index, pass, res_head); + StoreMigtype(lc, item, index, pass, configuration_resources); break; case CFG_TYPE_INCEXC: StoreInc(lc, item, index, pass); diff --git a/core/src/dird/jcr_private.h b/core/src/dird/jcr_private.h index f5c87ec0d50..ed39293a6a3 100644 --- a/core/src/dird/jcr_private.h +++ b/core/src/dird/jcr_private.h @@ -96,14 +96,14 @@ struct Resources { }; struct JobControlRecordPrivate { - JobControlRecordPrivate( std::shared_ptr res_head_container) { - job_res_head_container_ = res_head_container; + JobControlRecordPrivate( std::shared_ptr configuration_resources_container) { + job_config_resources_container_ = configuration_resources_container; RestoreJobId = 0; MigrateJobId = 0; VerifyJobId = 0; } ~JobControlRecordPrivate() { - job_res_head_container_ = nullptr; + job_config_resources_container_ = nullptr; } - std::shared_ptr job_res_head_container_; + std::shared_ptr job_config_resources_container_; pthread_t SD_msg_chan{}; /**< Message channel thread id */ bool SD_msg_chan_started{}; /**< Message channel thread started */ pthread_cond_t term_wait = PTHREAD_COND_INITIALIZER; /**< Wait for job termination */ diff --git a/core/src/dird/job.cc b/core/src/dird/job.cc index 41a54bf21b5..b3ad30bbb57 100644 --- a/core/src/dird/job.cc +++ b/core/src/dird/job.cc @@ -1627,10 +1627,11 @@ void GetJobStorage(UnifiedStorageResource* store, JobControlRecord* NewDirectorJcr() { JobControlRecord* jcr = new_jcr(DirdFreeJcr); - jcr->impl = new JobControlRecordPrivate(my_config->res_head_container_); - Dmsg1(10, "NewDirectorJcr(): res_head_ is at %p %s\n", - my_config->res_head_container_->res_head_, - my_config->res_head_container_->TimeStampAsString().c_str()); + jcr->impl + = new JobControlRecordPrivate(my_config->config_resources_container_); + Dmsg1(10, "NewDirectorJcr(): configuration_resources_ is at %p %s\n", + my_config->config_resources_container_->configuration_resources_, + my_config->config_resources_container_->TimeStampAsString().c_str()); return jcr; } diff --git a/core/src/dird/ua_output.cc b/core/src/dird/ua_output.cc index 79168721c9c..a9004f3663b 100644 --- a/core/src/dird/ua_output.cc +++ b/core/src/dird/ua_output.cc @@ -184,10 +184,13 @@ 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_container_->res_head_[j]) { - my_config->DumpResourceCb_( - j, my_config->res_head_container_->res_head_[j], bsendmsg, ua, - hide_sensitive_data, verbose); + if (my_config->config_resources_container_ + ->configuration_resources_[j]) { + my_config->DumpResourceCb_(j, + my_config->config_resources_container_ + ->configuration_resources_[j], + bsendmsg, ua, hide_sensitive_data, + verbose); } break; } @@ -264,7 +267,8 @@ bool show_cmd(UaContext* ua, const char* cmd) len)) { type = show_cmd_available_resources[j].type; if (type > 0) { - res = my_config->res_head_container_->res_head_[type]; + res = my_config->config_resources_container_ + ->configuration_resources_[type]; } else { res = NULL; } diff --git a/core/src/dird/ua_server.cc b/core/src/dird/ua_server.cc index 9c8245baf6a..f6a5dfc997d 100644 --- a/core/src/dird/ua_server.cc +++ b/core/src/dird/ua_server.cc @@ -56,7 +56,9 @@ JobControlRecord* new_control_jcr(const char* base_name, int job_type) jcr = NewDirectorJcr(); // exclude JT_SYSTEM job from shared config counting - if (job_type == JT_SYSTEM) { jcr->impl->job_res_head_container_ = nullptr; } + if (job_type == JT_SYSTEM) { + jcr->impl->job_config_resources_container_ = nullptr; + } /* The job and defaults are not really used, but we set them up to ensure that * everything is correctly initialized. */ diff --git a/core/src/filed/filed_conf.cc b/core/src/filed/filed_conf.cc index 2c54cf8d005..90d269507ec 100644 --- a/core/src/filed/filed_conf.cc +++ b/core/src/filed/filed_conf.cc @@ -56,9 +56,6 @@ namespace filedaemon { -/* static BareosResource* sres_head[R_NUM]; */ -/* static BareosResource** res_head = sres_head; */ - static bool SaveResource(int type, ResourceItem* items, int pass); static void FreeResource(BareosResource* sres, int type); static void DumpResource(int type, @@ -232,7 +229,7 @@ static void ParseConfigCb(LEX* lc, ResourceItem* item, int index, int pass, - BareosResource** res_head) + BareosResource** configuration_resources) { switch (item->type) { case CFG_TYPE_CIPHER: diff --git a/core/src/lib/parse_conf.cc b/core/src/lib/parse_conf.cc index 1fa6ce7921a..a4364f94e16 100644 --- a/core/src/lib/parse_conf.cc +++ b/core/src/lib/parse_conf.cc @@ -96,8 +96,6 @@ ConfigurationParser::ConfigurationParser() , r_own_(0) , own_resource_(nullptr) , resource_definitions_(0) - /* , res_head_(nullptr) */ - /* , res_head_backup_(nullptr) */ , SaveResourceCb_(nullptr) , DumpResourceCb_(nullptr) , FreeResourceCb_(nullptr) @@ -138,7 +136,7 @@ ConfigurationParser::ConfigurationParser( err_type_ = err_type; r_num_ = r_num; resource_definitions_ = resource_definitions; - res_head_container_.reset(new ResHeadContainer(this)); + config_resources_container_.reset(new ResHeadContainer(this)); config_default_filename_ = config_default_filename == nullptr ? "" : config_default_filename; config_include_dir_ = config_include_dir == nullptr ? "" : config_include_dir; @@ -151,17 +149,7 @@ ConfigurationParser::ConfigurationParser( DumpResourceCb_ = DumpResourceCb; FreeResourceCb_ = FreeResourceCb; } -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 -} +ConfigurationParser::~ConfigurationParser() {} void ConfigurationParser::InitializeQualifiedResourceNameTypeConverter( const std::map& map) @@ -208,7 +196,7 @@ bool ConfigurationParser::ParseConfig() scan_warning_); if (success && ParseConfigReadyCb_) { ParseConfigReadyCb_(*this); } - res_head_container_->timestamp_ = std::chrono::system_clock::now(); + config_resources_container_->timestamp_ = std::chrono::system_clock::now(); return success; } @@ -290,13 +278,15 @@ bool ConfigurationParser::AppendToResourcesChain(BareosResource* new_resource, return false; } - if (!res_head_container_->res_head_[rindex]) { - res_head_container_->res_head_[rindex] = new_resource; + if (!config_resources_container_->configuration_resources_[rindex]) { + config_resources_container_->configuration_resources_[rindex] + = new_resource; Dmsg3(900, "Inserting first %s res: %s index=%d\n", ResToStr(rcode), new_resource->resource_name_, rindex); } else { // append BareosResource* last = nullptr; - BareosResource* current = res_head_container_->res_head_[rindex]; + BareosResource* current + = config_resources_container_->configuration_resources_[rindex]; do { if (bstrcmp(current->resource_name_, new_resource->resource_name_)) { Emsg2(M_ERROR, 0, @@ -521,23 +511,23 @@ bool ConfigurationParser::FindConfigPath(PoolMem& full_path) // when last job also owning finishes void ConfigurationParser::ReleasePreviousResourceTable() { - res_head_container_backup_ = nullptr; + config_resources_container_backup_ = nullptr; } -// swap the previously saved res_head_previous_ with res_head_ -// and release the res_head_previous_ +// swap the previously saved configuration_resources_previous_ with +// configuration_resources_ and release the configuration_resources_previous_ void ConfigurationParser::RestoreResourceTable() { - std::swap(res_head_container_, res_head_container_backup_); - res_head_container_backup_ = nullptr; + std::swap(config_resources_container_, config_resources_container_backup_); + config_resources_container_backup_ = nullptr; } -// copy the current resource table to res_head_backup_ -// and create a new empty res_head_container_ +// copy the current resource table to configuration_resources_backup_ +// and create a new empty config_resources_container_ void ConfigurationParser::BackupResourceTable() { - std::swap(res_head_container_, res_head_container_backup_); - res_head_container_.reset(new ResHeadContainer(this)); + std::swap(config_resources_container_, config_resources_container_backup_); + config_resources_container_.reset(new ResHeadContainer(this)); } bool ConfigurationParser::RemoveResource(int rcode, const char* name) @@ -554,14 +544,16 @@ bool ConfigurationParser::RemoveResource(int rcode, const char* name) * resource_definitions must be added. If it is referenced, don't remove it. */ last = nullptr; - for (BareosResource* res = res_head_container_->res_head_[rindex]; res; - res = res->next_) { + for (BareosResource* res + = config_resources_container_->configuration_resources_[rindex]; + res; res = res->next_) { if (bstrcmp(res->resource_name_, name)) { if (!last) { Dmsg2(900, _("removing resource %s, name=%s (first resource in list)\n"), ResToStr(rcode), name); - res_head_container_->res_head_[rindex] = res->next_; + config_resources_container_->configuration_resources_[rindex] + = res->next_; } else { Dmsg2(900, _("removing resource %s, name=%s\n"), ResToStr(rcode), name); last->next_ = res->next_; @@ -615,9 +607,10 @@ void ConfigurationParser::DumpResources(bool sendit(void* sock, bool hide_sensitive_data) { for (int i = 0; i <= r_num_ - 1; i++) { - if (res_head_container_->res_head_[i]) { - DumpResourceCb_(i, res_head_container_->res_head_[i], sendit, sock, - hide_sensitive_data, false); + if (config_resources_container_->configuration_resources_[i]) { + DumpResourceCb_(i, + config_resources_container_->configuration_resources_[i], + sendit, sock, hide_sensitive_data, false); } } } diff --git a/core/src/lib/parse_conf.h b/core/src/lib/parse_conf.h index a4b15ca815b..b249ead51f7 100644 --- a/core/src/lib/parse_conf.h +++ b/core/src/lib/parse_conf.h @@ -185,7 +185,7 @@ typedef void(STORE_RES_HANDLER)(LEX* lc, ResourceItem* item, int index, int pass, - BareosResource** res_head); + BareosResource** configuration_resources); typedef void(PRINT_RES_HANDLER)(ResourceItem& item, OutputFormatterResource& send, bool hide_sensitive_data, @@ -219,8 +219,8 @@ class ConfigurationParser { BareosResource* own_resource_; /* Pointer to own resource */ ResourceTable* resource_definitions_; /* Pointer to table of permitted resources */ - std::shared_ptr res_head_container_; - std::shared_ptr res_head_container_backup_; + std::shared_ptr config_resources_container_; + std::shared_ptr config_resources_container_backup_; mutable brwlock_t res_lock_; /* Resource lock */ SaveResourceCb_t SaveResourceCb_; @@ -433,30 +433,32 @@ static std::string TPAsString(const std::chrono::system_clock::time_point& tp) class ResHeadContainer { public: std::chrono::time_point timestamp_{}; - BareosResource** res_head_ = nullptr; + BareosResource** configuration_resources_ = nullptr; ConfigurationParser* config_ = nullptr; ResHeadContainer(ConfigurationParser* config) { config_ = config; int num = config_->r_num_; - res_head_ = (BareosResource**)malloc(num * sizeof(BareosResource*)); + configuration_resources_ + = (BareosResource**)malloc(num * sizeof(BareosResource*)); - for (int i = 0; i < num; i++) { res_head_[i] = nullptr; } - Dmsg1(10, "ResHeadContainer: new res_head_ %p\n", res_head_); + for (int i = 0; i < num; i++) { configuration_resources_[i] = nullptr; } + Dmsg1(10, "ResHeadContainer: new configuration_resources_ %p\n", + configuration_resources_); } ~ResHeadContainer() { - Dmsg1(10, "ResHeadContainer freeing %p %s\n", res_head_, + Dmsg1(10, "ResHeadContainer freeing %p %s\n", configuration_resources_, TPAsString(timestamp_).c_str()); int num = config_->r_num_; for (int j = 0; j < num; j++) { - config_->FreeResourceCb_(res_head_[j], j); - res_head_[j] = nullptr; + config_->FreeResourceCb_(configuration_resources_[j], j); + configuration_resources_[j] = nullptr; } - free(res_head_); - res_head_ = nullptr; + free(configuration_resources_); + configuration_resources_ = nullptr; } std::string TimeStampAsString() { return TPAsString(timestamp_); } diff --git a/core/src/lib/parse_conf_state_machine.cc b/core/src/lib/parse_conf_state_machine.cc index 4dd85b8b76d..c604af9e490 100644 --- a/core/src/lib/parse_conf_state_machine.cc +++ b/core/src/lib/parse_conf_state_machine.cc @@ -145,7 +145,8 @@ ConfigParserStateMachine::ScanResource(int token) if (my_config_.store_res_) { my_config_.store_res_(lexical_parser_, item, resource_item_index, parser_pass_number_, - my_config_.res_head_container_->res_head_); + my_config_.config_resources_container_ + ->configuration_resources_); } } } else { @@ -281,9 +282,10 @@ void ConfigParserStateMachine::DumpResourcesAfterSecondPass() { if (debug_level >= 900 && parser_pass_number_ == 2) { for (int i = 0; i <= my_config_.r_num_ - 1; i++) { - my_config_.DumpResourceCb_(i, - my_config_.res_head_container_->res_head_[i], - PrintMessage, nullptr, false, false); + my_config_.DumpResourceCb_( + i, + my_config_.config_resources_container_->configuration_resources_[i], + PrintMessage, nullptr, false, false); } } } diff --git a/core/src/lib/res.cc b/core/src/lib/res.cc index b54fa4aa287..be380df8c44 100644 --- a/core/src/lib/res.cc +++ b/core/src/lib/res.cc @@ -96,7 +96,7 @@ BareosResource* ConfigurationParser::GetResWithName(int rcode, if (lock) { LockRes(this); } - res = res_head_container_->res_head_[rindex]; + res = config_resources_container_->configuration_resources_[rindex]; while (res) { if (bstrcmp(res->resource_name_, name)) { break; } res = res->next_; @@ -119,7 +119,7 @@ BareosResource* ConfigurationParser::GetNextRes(int rcode, int rindex = rcode; if (res == NULL) { - nres = res_head_container_->res_head_[rindex]; + nres = config_resources_container_->configuration_resources_[rindex]; } else { nres = res->next_; } diff --git a/core/src/qt-tray-monitor/tray_conf.cc b/core/src/qt-tray-monitor/tray_conf.cc index 0e5fbdcb70e..81b5d056107 100644 --- a/core/src/qt-tray-monitor/tray_conf.cc +++ b/core/src/qt-tray-monitor/tray_conf.cc @@ -55,9 +55,6 @@ static const std::string default_config_filename("tray-monitor.conf"); -/* static BareosResource* sres_head[R_NUM]; */ -/* static BareosResource** res_head = sres_head; */ - static bool SaveResource(int type, ResourceItem* items, int pass); static void FreeResource(BareosResource* sres, int type); static void DumpResource(int type, @@ -166,7 +163,7 @@ static ResourceItem con_font_items[] = { * NOTE!!! keep it in the same order as the R_codes * or eliminate all resource_definitions[rindex].name * - * name items rcode res_head + * name items rcode configuration_resources */ static ResourceTable resource_definitions[] = { {"Monitor", "Monitors", mon_items, R_MONITOR, sizeof(MonitorResource), diff --git a/core/src/stored/stored_conf.cc b/core/src/stored/stored_conf.cc index 90af6970328..73dba7326b5 100644 --- a/core/src/stored/stored_conf.cc +++ b/core/src/stored/stored_conf.cc @@ -48,9 +48,6 @@ namespace storagedaemon { -/* static BareosResource* sres_head[R_NUM]; */ -/* static BareosResource** res_head = sres_head; */ - static void FreeResource(BareosResource* sres, int type); static bool SaveResource(int type, ResourceItem* items, int pass); static void DumpResource(int type, @@ -446,7 +443,7 @@ static void ParseConfigCb(LEX* lc, ResourceItem* item, int index, int pass, - BareosResource** res_head) + BareosResource** configuration_resources) { switch (item->type) { case CFG_TYPE_AUTOPASSWORD: