Skip to content

Commit

Permalink
config: some improvements on callbacks
Browse files Browse the repository at this point in the history
- ASSERT against nullpointer
- always use the callback instead of the function directly
  • Loading branch information
franku committed Sep 17, 2018
1 parent 3ddbfb0 commit c044a2a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions core/src/dird/dird_conf.cc
Expand Up @@ -3892,7 +3892,7 @@ static void DumpResource(int type,

bail_out:
if (recurse && res->res_dir.hdr.next) {
DumpResource(type, res->res_dir.hdr.next, sendit, sock, hide_sensitive_data, verbose);
my_config->DumpResourceCb_(type, res->res_dir.hdr.next, sendit, sock, hide_sensitive_data, verbose);
}
}

Expand Down Expand Up @@ -4122,7 +4122,7 @@ static void FreeResource(CommonResourceHeader *sres, int type)
* Common stuff again -- free the resource, recurse to next one
*/
if (res) { free(res); }
if (nres) { FreeResource(nres, type); }
if (nres) { my_config->FreeResourceCb_(nres, type); }
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/filed/filed_conf.cc
Expand Up @@ -367,7 +367,7 @@ static void DumpResource(int type,
sendit(sock, "%s", buf.c_str());

if (recurse && res->res_dir.hdr.next) {
DumpResource(type, res->res_dir.hdr.next, sendit, sock, hide_sensitive_data, verbose);
my_config->DumpResourceCb_(type, res->res_dir.hdr.next, sendit, sock, hide_sensitive_data, verbose);
}
}

Expand Down Expand Up @@ -471,7 +471,7 @@ static void FreeResource(CommonResourceHeader *sres, int type)
}
/* Common stuff again -- free the resource, recurse to next one */
if (res) { free(res); }
if (nres) { FreeResource(nres, type); }
if (nres) { my_config->FreeResourceCb_(nres, type); }
}

/**
Expand Down
9 changes: 8 additions & 1 deletion core/src/lib/parse_conf.cc
Expand Up @@ -98,7 +98,11 @@ ConfigurationParser::ConfigurationParser()
, r_own_ (0)
, resources_ (0)
, res_head_(nullptr)
, use_config_include_dir_ (false) {
, use_config_include_dir_ (false)
, ParseConfigReadyCb_(nullptr)
, SaveResourceCb_(nullptr)
, DumpResourceCb_(nullptr)
, FreeResourceCb_(nullptr) {
return;
}

Expand Down Expand Up @@ -142,6 +146,9 @@ ConfigurationParser::ConfigurationParser(
config_default_filename_ = config_default_filename == nullptr ? "" : config_default_filename;
config_include_dir_ = config_include_dir == nullptr ? "" : config_include_dir;
ParseConfigReadyCb_ = ParseConfigReadyCb;
ASSERT(SaveResourceCb);
ASSERT(DumpResourceCb);
ASSERT(FreeResourceCb);
SaveResourceCb_ = SaveResourceCb;
DumpResourceCb_ = DumpResourceCb;
FreeResourceCb_ = FreeResourceCb;
Expand Down
4 changes: 2 additions & 2 deletions core/src/stored/stored_conf.cc
Expand Up @@ -645,7 +645,7 @@ static void DumpResource(int type,
sendit(sock, "%s", buf.c_str());

if (recurse && res->res_dir.hdr.next) {
DumpResource(type, (CommonResourceHeader *)res->res_dir.hdr.next, sendit, sock, hide_sensitive_data,
my_config->DumpResourceCb_(type, (CommonResourceHeader *)res->res_dir.hdr.next, sendit, sock, hide_sensitive_data,
verbose);
}
}
Expand Down Expand Up @@ -901,7 +901,7 @@ static void FreeResource(CommonResourceHeader *sres, int type)
* Common stuff again -- free the resource, recurse to next one
*/
if (res) { free(res); }
if (nres) { FreeResource(nres, type); }
if (nres) { my_config->FreeResourceCb_(nres, type); }
}

} /* namespace storagedaemon */

0 comments on commit c044a2a

Please sign in to comment.