Skip to content

Commit

Permalink
Merge branch 'dev/franku/master/configparser' into bareos-18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Jun 26, 2018
2 parents 1c20996 + 3c4543e commit 7efb64e
Show file tree
Hide file tree
Showing 30 changed files with 223 additions and 265 deletions.
19 changes: 7 additions & 12 deletions core/src/console/console.cc
Expand Up @@ -51,13 +51,10 @@

/* Exported variables */
ConsoleResource *me = NULL; /* Our Global resource */
ConfigurationParser *my_config = NULL; /* Our Global config */
ConfigurationParser *my_config = nullptr; /* Our Global config */

//extern int rl_catch_signals;

/* Imported functions */
extern bool ParseConsConfig(ConfigurationParser *config, const char *configfile, int exit_code);

/* Forward referenced functions */
static void TerminateConsole(int sig);
static int CheckResources();
Expand Down Expand Up @@ -1251,15 +1248,14 @@ int main(int argc, char *argv[])
if (export_config_schema) {
PoolMem buffer;

my_config = new_config_parser();
InitConsConfig(my_config, configfile, M_ERROR_TERM);
my_config = InitConsConfig(configfile, M_ERROR_TERM);
PrintConfigSchemaJson(buffer);
printf("%s\n", buffer.c_str());
exit(0);
}

my_config = new_config_parser();
ParseConsConfig(my_config, configfile, M_ERROR_TERM);
my_config = InitConsConfig(configfile, M_ERROR_TERM);
my_config->ParseConfig();

if (export_config) {
my_config->DumpResources(PrintMessage, NULL);
Expand All @@ -1271,7 +1267,7 @@ int main(int argc, char *argv[])
}

if (!CheckResources()) {
Emsg1(M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), my_config->get_base_config_path());
Emsg1(M_ERROR_TERM, 0, _("Please correct configuration file: %s\n"), my_config->get_base_config_path().c_str());
}

if (!no_conio) {
Expand Down Expand Up @@ -1413,8 +1409,7 @@ static void TerminateConsole(int sig)
}
already_here = true;
StopWatchdog();
my_config->FreeResources();
free(my_config);
delete my_config;
my_config = NULL;
CleanupCrypto();
FreePoolMemory(args);
Expand Down Expand Up @@ -1447,7 +1442,7 @@ static int CheckResources()

if (numdir == 0) {
Emsg1(M_FATAL, 0, _("No Director resource defined in %s\n"
"Without that I don't how to speak to the Director :-(\n"), my_config->get_base_config_path());
"Without that I don't how to speak to the Director :-(\n"), my_config->get_base_config_path().c_str());
OK = false;
}

Expand Down
27 changes: 11 additions & 16 deletions core/src/console/console_conf.cc
Expand Up @@ -354,29 +354,24 @@ bool SaveResource(int type, ResourceItem *items, int pass)
return (error == 0);
}

void InitConsConfig(ConfigurationParser *config, const char *configfile, int exit_code)
ConfigurationParser *InitConsConfig(const char *configfile, int exit_code)
{
config->init(configfile,
NULL,
NULL,
NULL,
NULL,
NULL,
return new ConfigurationParser (
configfile,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
exit_code,
(void *)&res_all,
res_all_size,
R_FIRST,
R_LAST,
resources,
res_head);
config->SetDefaultConfigFilename(CONFIG_FILE);
config->SetConfigIncludeDir("bconsole.d");
}

bool ParseConsConfig(ConfigurationParser *config, const char *configfile, int exit_code)
{
InitConsConfig(config, configfile, exit_code);
return config->ParseConfig();
res_head,
CONFIG_FILE,
"bconsole.d");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/console/console_conf.h
Expand Up @@ -90,5 +90,5 @@ union UnionOfResources {
extern ConsoleResource *me; /* "Global" Client resource */
extern ConfigurationParser *my_config; /* Our Global config */

void InitConsConfig(ConfigurationParser *config, const char *configfile, int exit_code);
ConfigurationParser *InitConsConfig(const char *configfile, int exit_code);
bool PrintConfigSchemaJson(PoolMem &buffer);
8 changes: 4 additions & 4 deletions core/src/dird/dbcheck.cc
Expand Up @@ -34,7 +34,7 @@
#include "dird/dird_conf.h"
#include "lib/edit.h"

extern bool ParseDirConfig(ConfigurationParser *config, const char *configfile, int exit_code);
extern bool ParseDirConfig(const char *configfile, int exit_code);

typedef struct s_id_ctx {
int64_t *Id; /* ids to be modified */
Expand Down Expand Up @@ -68,7 +68,7 @@ static const char *backend_directory = _PATH_BAREOS_BACKENDDIR;
#endif

DirectorResource *me = NULL; /* Our Global resource */
ConfigurationParser *my_config = NULL; /* Our Global config */
ConfigurationParser *my_config = nullptr; /* Our Global config */

#define MAX_ID_LIST_LEN 10000000

Expand Down Expand Up @@ -1236,8 +1236,8 @@ int main (int argc, char *argv[])
if (argc > 0) {
Pmsg0(0, _("Warning skipping the additional parameters for working directory/dbname/user/password/host.\n"));
}
my_config = new_config_parser();
ParseDirConfig(my_config, configfile, M_ERROR_TERM);
my_config = InitDirConfig(configfile, M_ERROR_TERM);
my_config->ParseConfig();
LockRes();
foreach_res(catalog, R_CATALOG) {
if (catalogname && bstrcmp(catalog->hdr.name, catalogname)) {
Expand Down
28 changes: 14 additions & 14 deletions core/src/dird/dird.cc
Expand Up @@ -70,7 +70,7 @@ static bool InitSighandlerSighup();
/* Exported subroutines */
extern bool DoReloadConfig();
extern void InvalidateSchedules();
extern bool ParseDirConfig(ConfigurationParser *config, const char *configfile, int exit_code);
extern bool ParseDirConfig(const char *configfile, int exit_code);
extern void PrintMessage(void *sock, const char *fmt, ...);

/* Imported subroutines */
Expand All @@ -90,7 +90,7 @@ static alist *reload_table = NULL;

/* Globals Exported */
DirectorResource *me = NULL; /* Our Global resource */
ConfigurationParser *my_config = NULL; /* Our Global config */
ConfigurationParser *my_config = nullptr; /* Our Global config */
char *configfile = NULL;
void *start_heap;

Expand Down Expand Up @@ -344,15 +344,14 @@ int main (int argc, char *argv[])
if (export_config_schema) {
PoolMem buffer;

my_config = new_config_parser();
InitDirConfig(my_config, configfile, M_ERROR_TERM);
my_config = InitDirConfig(configfile, M_ERROR_TERM);
PrintConfigSchemaJson(buffer);
printf("%s\n", buffer.c_str());
goto bail_out;
}

my_config = new_config_parser();
ParseDirConfig(my_config, configfile, M_ERROR_TERM);
my_config = InitDirConfig(configfile, M_ERROR_TERM);
my_config->ParseConfig();

if (export_config) {
my_config->DumpResources(PrintMessage, NULL);
Expand All @@ -372,7 +371,7 @@ int main (int argc, char *argv[])
}

if (!CheckResources()) {
Jmsg((JobControlRecord *)NULL, M_ERROR_TERM, 0, _("Please correct the configuration in %s\n"), my_config->get_base_config_path());
Jmsg((JobControlRecord *)NULL, M_ERROR_TERM, 0, _("Please correct the configuration in %s\n"), my_config->get_base_config_path().c_str());
goto bail_out;
}

Expand Down Expand Up @@ -406,7 +405,7 @@ int main (int argc, char *argv[])
mode = (test_config) ? CHECK_CONNECTION : UPDATE_AND_FIX;

if (!CheckCatalog(mode)) {
Jmsg((JobControlRecord *)NULL, M_ERROR_TERM, 0, _("Please correct the configuration in %s\n"), my_config->get_base_config_path());
Jmsg((JobControlRecord *)NULL, M_ERROR_TERM, 0, _("Please correct the configuration in %s\n"), my_config->get_base_config_path().c_str());
goto bail_out;
}

Expand All @@ -415,7 +414,7 @@ int main (int argc, char *argv[])
}

if (!InitializeSqlPooling()) {
Jmsg((JobControlRecord *)NULL, M_ERROR_TERM, 0, _("Please correct the configuration in %s\n"), my_config->get_base_config_path());
Jmsg((JobControlRecord *)NULL, M_ERROR_TERM, 0, _("Please correct the configuration in %s\n"), my_config->get_base_config_path().c_str());
goto bail_out;
}

Expand Down Expand Up @@ -505,8 +504,7 @@ void TerminateDird(int sig)
PrintMemoryPoolStats();
}
if (my_config) {
my_config->FreeResources();
free(my_config);
delete my_config;
my_config = NULL;
}

Expand Down Expand Up @@ -595,11 +593,13 @@ bool DoReloadConfig()
prev_config.JobCount = 0;

Dmsg0(100, "Reloading config file\n");
bool ok = ParseDirConfig(my_config, configfile, M_ERROR);

my_config->err_type_ = M_ERROR;
bool ok = my_config->ParseConfig();

if (!ok || !CheckResources() || !CheckCatalog(UPDATE_CATALOG) || !InitializeSqlPooling()) {

Jmsg(NULL, M_ERROR, 0, _("Please correct the configuration in %s\n"), my_config->get_base_config_path());
Jmsg(NULL, M_ERROR, 0, _("Please correct the configuration in %s\n"), my_config->get_base_config_path().c_str());
Jmsg(NULL, M_ERROR, 0, _("Resetting to previous configuration.\n"));

resource_table_reference temp_config;
Expand Down Expand Up @@ -773,7 +773,7 @@ static bool CheckResources()
bool OK = true;
JobResource *job;
bool need_tls;
const char *configfile = my_config->get_base_config_path();
const char *configfile = my_config->get_base_config_path().c_str();

LockRes();

Expand Down
22 changes: 8 additions & 14 deletions core/src/dird/dird_conf.cc
Expand Up @@ -4395,11 +4395,12 @@ static void PrintConfigCb(ResourceItem *items, int i, PoolMem &cfg_str, bool hid
}
}

void InitDirConfig(ConfigurationParser *config, const char *configfile, int exit_code)
ConfigurationParser *InitDirConfig(const char *configfile, int exit_code)
{
config->init(configfile,
NULL,
NULL,
return new ConfigurationParser (
configfile,
nullptr,
nullptr,
InitResourceCb,
ParseConfigCb,
PrintConfigCb,
Expand All @@ -4409,14 +4410,7 @@ void InitDirConfig(ConfigurationParser *config, const char *configfile, int exit
R_FIRST,
R_LAST,
resources,
res_head);
config->SetDefaultConfigFilename(CONFIG_FILE);
config->SetConfigIncludeDir("bareos-dir.d");
}

bool ParseDirConfig(ConfigurationParser *config, const char *configfile, int exit_code)
{
InitDirConfig(config, configfile, exit_code);

return config->ParseConfig();
res_head,
CONFIG_FILE,
"bareos-dir.d");
}
2 changes: 1 addition & 1 deletion core/src/dird/dird_conf.h
Expand Up @@ -646,7 +646,7 @@ union UnionOfResources {
~UnionOfResources() {}
};

void InitDirConfig(ConfigurationParser *config, const char *configfile, int exit_code);
ConfigurationParser *InitDirConfig(const char *configfile, int exit_code);
bool PropagateJobdefs(int res_type, JobResource *res);
bool ValidateResource(int type, ResourceItem *items, BareosResource *res);

Expand Down
11 changes: 5 additions & 6 deletions core/src/dird/testfind.cc
Expand Up @@ -39,7 +39,7 @@

/* Dummy functions */
void GeneratePluginEvent(JobControlRecord *jcr, bEventType eventType, void *value) { }
extern bool ParseDirConfig(ConfigurationParser *config, const char *configfile, int exit_code);
extern bool ParseDirConfig(const char *configfile, int exit_code);

/* Global variables */
static int num_files = 0;
Expand All @@ -50,7 +50,7 @@ static int trunc_path = 0;
static int attrs = 0;

DirectorResource *me = NULL; /* Our Global resource */
ConfigurationParser *my_config = NULL; /* Our Global config */
ConfigurationParser *my_config = nullptr; /* Our Global config */

static JobControlRecord *jcr;

Expand Down Expand Up @@ -133,8 +133,8 @@ main (int argc, char *const *argv)
argc -= optind;
argv += optind;

my_config = new_config_parser();
ParseDirConfig(my_config, configfile, M_ERROR_TERM);
my_config = InitDirConfig(configfile, M_ERROR_TERM);
my_config->ParseConfig();

MessagesResource *msg;

Expand Down Expand Up @@ -168,8 +168,7 @@ main (int argc, char *const *argv)

FreeJcr(jcr);
if (my_config) {
my_config->FreeResources();
free(my_config);
delete my_config;
my_config = NULL;
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/dird/ua_configure.cc
Expand Up @@ -306,7 +306,8 @@ static inline bool ConfigureAddResource(UaContext *ua, int first_parameter, Reso
return false;
}

if (!my_config->ParseConfigFile(filename_tmp.c_str(), ua, ConfigureLexErrorHandler, NULL, M_ERROR)) {
my_config->err_type_ = M_ERROR;
if (!my_config->ParseConfigFile(filename_tmp.c_str(), ua, ConfigureLexErrorHandler, NULL)) {
unlink(filename_tmp.c_str());
my_config->RemoveResource(res_table->rcode, name.c_str());
return false;
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ua_restore.cc
Expand Up @@ -184,7 +184,7 @@ bool RestoreCmd(UaContext *ua, const char *cmd)
ua->ErrorMsg(_(
"No Restore Job Resource found in %s.\n"
"You must create at least one before running this command.\n"),
my_config->get_base_config_path());
my_config->get_base_config_path().c_str());
goto bail_out;
}

Expand Down

0 comments on commit 7efb64e

Please sign in to comment.