Skip to content

Commit

Permalink
config: added a callback for all daemons before config loads
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Jul 4, 2019
1 parent 835d5d1 commit 2433929
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 14 deletions.
8 changes: 5 additions & 3 deletions core/src/console/console_conf.cc
Expand Up @@ -246,20 +246,22 @@ static bool SaveResource(int type, ResourceItem* items, int pass)
return (error == 0);
}

static void ConfigReadyCallback(ConfigurationParser& my_config)
static void ConfigBeforeCallback(ConfigurationParser& my_config)
{
std::map<int, std::string> map{{R_DIRECTOR, "R_DIRECTOR"},
{R_CONSOLE, "R_CONSOLE"}};
my_config.InitializeQualifiedResourceNameTypeConverter(map);
}

static void ConfigReadyCallback(ConfigurationParser& my_config) {}

ConfigurationParser* InitConsConfig(const char* configfile, int exit_code)
{
ConfigurationParser* config = new ConfigurationParser(
configfile, nullptr, nullptr, nullptr, nullptr, nullptr, exit_code,
R_FIRST, R_LAST, resources, res_head, default_config_filename.c_str(),
"bconsole.d", ConfigReadyCallback, SaveResource, DumpResource,
FreeResource);
"bconsole.d", ConfigBeforeCallback, ConfigReadyCallback, SaveResource,
DumpResource, FreeResource);
if (config) { config->r_own_ = R_CONSOLE; }
return config;
}
Expand Down
17 changes: 15 additions & 2 deletions core/src/dird/dird_conf.cc
Expand Up @@ -3694,6 +3694,19 @@ static void ResetAllClientConnectionHandshakeModes(
};
}

static void ConfigBeforeCallback(ConfigurationParser& my_config)
{
std::map<int, std::string> map{
{R_DIRECTOR, "R_DIRECTOR"}, {R_CLIENT, "R_CLIENT"},
{R_JOBDEFS, "R_JOBDEFS"}, {R_JOB, "R_JOB"},
{R_STORAGE, "R_STORAGE"}, {R_CATALOG, "R_CATALOG"},
{R_SCHEDULE, "R_SCHEDULE"}, {R_FILESET, "R_FILESET"},
{R_POOL, "R_POOL"}, {R_MSGS, "R_MSGS"},
{R_COUNTER, "R_COUNTER"}, {R_PROFILE, "R_PROFILE"},
{R_CONSOLE, "R_CONSOLE"}, {R_DEVICE, "R_DEVICE"}};
my_config.InitializeQualifiedResourceNameTypeConverter(map);
}

static void ConfigReadyCallback(ConfigurationParser& my_config)
{
CreateAndAddUserAgentConsoleResource(my_config);
Expand Down Expand Up @@ -3806,8 +3819,8 @@ ConfigurationParser* InitDirConfig(const char* configfile, int exit_code)
ConfigurationParser* config = new ConfigurationParser(
configfile, nullptr, nullptr, InitResourceCb, ParseConfigCb,
PrintConfigCb, exit_code, R_FIRST, R_LAST, resources, res_head,
default_config_filename.c_str(), "bareos-dir.d", ConfigReadyCallback,
SaveResource, DumpResource, FreeResource);
default_config_filename.c_str(), "bareos-dir.d", ConfigBeforeCallback,
ConfigReadyCallback, SaveResource, DumpResource, FreeResource);
if (config) { config->r_own_ = R_DIRECTOR; }
return config;
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/filed/filed_conf.cc
Expand Up @@ -250,7 +250,7 @@ static void ParseConfigCb(LEX* lc, ResourceItem* item, int index, int pass)
}
}

static void ConfigReadyCallback(ConfigurationParser& my_config)
static void ConfigBeforeCallback(ConfigurationParser& my_config)
{
std::map<int, std::string> map{{R_DIRECTOR, "R_DIRECTOR"},
{R_CLIENT, "R_CLIENT"},
Expand All @@ -260,13 +260,15 @@ static void ConfigReadyCallback(ConfigurationParser& my_config)
my_config.InitializeQualifiedResourceNameTypeConverter(map);
}

static void ConfigReadyCallback(ConfigurationParser& my_config) {}

ConfigurationParser* InitFdConfig(const char* configfile, int exit_code)
{
ConfigurationParser* config = new ConfigurationParser(
configfile, nullptr, nullptr, InitResourceCb, ParseConfigCb, nullptr,
exit_code, R_FIRST, R_LAST, resources, res_head,
default_config_filename.c_str(), "bareos-fd.d", ConfigReadyCallback,
SaveResource, DumpResource, FreeResource);
default_config_filename.c_str(), "bareos-fd.d", ConfigBeforeCallback,
ConfigReadyCallback, SaveResource, DumpResource, FreeResource);
if (config) { config->r_own_ = R_CLIENT; }
return config;
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/lib/parse_conf.cc
Expand Up @@ -119,6 +119,7 @@ ConfigurationParser::ConfigurationParser(
BareosResource** res_head,
const char* config_default_filename,
const char* config_include_dir,
void (*ParseConfigBeforeCb)(ConfigurationParser&),
void (*ParseConfigReadyCb)(ConfigurationParser&),
SaveResourceCb_t SaveResourceCb,
DumpResourceCb_t DumpResourceCb,
Expand All @@ -141,6 +142,7 @@ ConfigurationParser::ConfigurationParser(
config_default_filename_ =
config_default_filename == nullptr ? "" : config_default_filename;
config_include_dir_ = config_include_dir == nullptr ? "" : config_include_dir;
ParseConfigBeforeCb_ = ParseConfigBeforeCb;
ParseConfigReadyCb_ = ParseConfigReadyCb;
ASSERT(SaveResourceCb);
ASSERT(DumpResourceCb);
Expand Down Expand Up @@ -170,6 +172,8 @@ bool ConfigurationParser::ParseConfig()
int errstat;
PoolMem config_path;

if (ParseConfigBeforeCb_) ParseConfigBeforeCb_(*this);

if (parser_first_run_ && (errstat = RwlInit(&res_lock_)) != 0) {
BErrNo be;
Jmsg1(nullptr, M_ABORT, 0,
Expand Down
2 changes: 2 additions & 0 deletions core/src/lib/parse_conf.h
Expand Up @@ -243,6 +243,7 @@ class ConfigurationParser {
BareosResource** res_head,
const char* config_default_filename,
const char* config_include_dir,
void (*ParseConfigBeforeCb)(ConfigurationParser&),
void (*ParseConfigReadyCb)(ConfigurationParser&),
SaveResourceCb_t SaveResourceCb,
DumpResourceCb_t DumpResourceCb,
Expand Down Expand Up @@ -336,6 +337,7 @@ class ConfigurationParser {
std::string used_config_path_; /* Config file that is used. */
std::unique_ptr<QualifiedResourceNameTypeConverter>
qualified_resource_name_type_converter_;
ParseConfigBeforeCb_t ParseConfigBeforeCb_;
ParseConfigReadyCb_t ParseConfigReadyCb_;
bool parser_first_run_;

Expand Down
1 change: 1 addition & 0 deletions core/src/lib/parse_conf_callbacks.h
Expand Up @@ -35,6 +35,7 @@ typedef void (*DumpResourceCb_t)(int type,
bool verbose);

typedef void (*FreeResourceCb_t)(BareosResource* res, int type);
typedef void (*ParseConfigBeforeCb_t)(ConfigurationParser&);
typedef void (*ParseConfigReadyCb_t)(ConfigurationParser&);

#endif /* BAREOS_LIB_PARSE_CONF_CALLBACKS_H_ */
8 changes: 5 additions & 3 deletions core/src/qt-tray-monitor/tray_conf.cc
Expand Up @@ -367,7 +367,7 @@ static bool SaveResource(int type, ResourceItem* items, int pass)
return (error == 0);
}

static void ConfigReadyCallback(ConfigurationParser& my_config)
static void ConfigBeforeCallback(ConfigurationParser& my_config)
{
std::map<int, std::string> map{
{R_MONITOR, "R_MONITOR"}, {R_DIRECTOR, "R_DIRECTOR"},
Expand All @@ -376,13 +376,15 @@ static void ConfigReadyCallback(ConfigurationParser& my_config)
my_config.InitializeQualifiedResourceNameTypeConverter(map);
}

static void ConfigReadyCallback(ConfigurationParser& my_config) {}

ConfigurationParser* InitTmonConfig(const char* configfile, int exit_code)
{
ConfigurationParser* config = new ConfigurationParser(
configfile, nullptr, nullptr, nullptr, nullptr, nullptr, exit_code,
R_FIRST, R_LAST, resources, res_head, default_config_filename.c_str(),
"tray-monitor.d", ConfigReadyCallback, SaveResource, DumpResource,
FreeResource);
"tray-monitor.d", ConfigBeforeCallback, ConfigReadyCallback, SaveResource,
DumpResource, FreeResource);
if (config) { config->r_own_ = R_MONITOR; }
return config;
}
Expand Down
10 changes: 7 additions & 3 deletions core/src/stored/stored_conf.cc
Expand Up @@ -523,7 +523,7 @@ static void MultiplyConfiguredDevices(ConfigurationParser& my_config)
}
}

static void ConfigReadyCallback(ConfigurationParser& my_config)
static void ConfigBeforeCallback(ConfigurationParser& my_config)
{
std::map<int, std::string> map{
{R_DIRECTOR, "R_DIRECTOR"},
Expand All @@ -534,6 +534,10 @@ static void ConfigReadyCallback(ConfigurationParser& my_config)
{R_DEVICE, "R_DEVICE"},
{R_AUTOCHANGER, "R_AUTOCHANGER"}};
my_config.InitializeQualifiedResourceNameTypeConverter(map);
}

static void ConfigReadyCallback(ConfigurationParser& my_config)
{
MultiplyConfiguredDevices(my_config);
}

Expand All @@ -542,8 +546,8 @@ ConfigurationParser* InitSdConfig(const char* configfile, int exit_code)
ConfigurationParser* config = new ConfigurationParser(
configfile, nullptr, nullptr, InitResourceCb, ParseConfigCb, nullptr,
exit_code, R_FIRST, R_LAST, resources, res_head,
default_config_filename.c_str(), "bareos-sd.d", ConfigReadyCallback,
SaveResource, DumpResource, FreeResource);
default_config_filename.c_str(), "bareos-sd.d", ConfigBeforeCallback,
ConfigReadyCallback, SaveResource, DumpResource, FreeResource);
if (config) { config->r_own_ = R_STORAGE; }
return config;
}
Expand Down

0 comments on commit 2433929

Please sign in to comment.