mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
"retire" old configuration handling code
This commit is contained in:
@@ -40,11 +40,11 @@ static sigjmp_buf *CONF_flex_fatal_jmp;
|
|||||||
static char *CONF_scanstr(const char *s);
|
static char *CONF_scanstr(const char *s);
|
||||||
static int CONF_flex_fatal(const char *msg);
|
static int CONF_flex_fatal(const char *msg);
|
||||||
|
|
||||||
static bool ProcessConfigFile(const char *base_dir, const char *config_file, const char *calling_file, bool strict, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *options2, ItemList *error_list, ItemList *warning_list);
|
static bool ProcessConfigFile(const char *base_dir, const char *config_file, const char *calling_file, bool strict, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *settings, ItemList *error_list, ItemList *warning_list);
|
||||||
|
|
||||||
static bool ProcessConfigFp(FILE *fp, const char *config_file, const char *calling_file, const char *base_dir, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *options2, ItemList *error_list, ItemList *warning_list);
|
static bool ProcessConfigFp(FILE *fp, const char *config_file, const char *calling_file, const char *base_dir, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *settings, ItemList *error_list, ItemList *warning_list);
|
||||||
|
|
||||||
static bool ProcessConfigDirectory(const char *base_dir, const char *includedir, const char *calling_file, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *options2, ItemList *error_list, ItemList *warning_list);
|
static bool ProcessConfigDirectory(const char *base_dir, const char *includedir, const char *calling_file, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *settings, ItemList *error_list, ItemList *warning_list);
|
||||||
|
|
||||||
static char *AbsoluteConfigLocation(const char *base_dir, const char *location, const char *calling_file);
|
static char *AbsoluteConfigLocation(const char *base_dir, const char *location, const char *calling_file);
|
||||||
|
|
||||||
@@ -99,13 +99,13 @@ STRING \'([^'\\\n]|\\.|\'\')*\'
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
extern bool
|
extern bool
|
||||||
ProcessRepmgrConfigFile(const char *config_file, const char *base_dir, t_configuration_options *options, ItemList *error_list, ItemList *warning_list)
|
ProcessRepmgrConfigFileOld(const char *config_file, const char *base_dir, t_configuration_options *options, ItemList *error_list, ItemList *warning_list)
|
||||||
{
|
{
|
||||||
return ProcessConfigFile(base_dir, config_file, NULL, true, NULL, options, NULL, error_list, warning_list);
|
return ProcessConfigFile(base_dir, config_file, NULL, true, NULL, options, NULL, error_list, warning_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern bool
|
extern bool
|
||||||
ProcessRepmgrConfigFile2(const char *config_file, const char *base_dir, ItemList *error_list, ItemList *warning_list)
|
ProcessRepmgrConfigFile(const char *config_file, const char *base_dir, ItemList *error_list, ItemList *warning_list)
|
||||||
{
|
{
|
||||||
return ProcessConfigFile(base_dir, config_file, NULL, true, NULL, NULL, NULL, error_list, warning_list);
|
return ProcessConfigFile(base_dir, config_file, NULL, true, NULL, NULL, NULL, error_list, warning_list);
|
||||||
}
|
}
|
||||||
@@ -120,7 +120,7 @@ ProcessPostgresConfigFile(const char *config_file, const char *base_dir, KeyValu
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ProcessConfigFile(const char *base_dir, const char *config_file, const char *calling_file, bool strict, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *options2, ItemList *error_list, ItemList *warning_list)
|
ProcessConfigFile(const char *base_dir, const char *config_file, const char *calling_file, bool strict, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *settings, ItemList *error_list, ItemList *warning_list)
|
||||||
{
|
{
|
||||||
char *abs_path;
|
char *abs_path;
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@@ -159,7 +159,7 @@ ProcessConfigFile(const char *base_dir, const char *config_file, const char *cal
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
success = ProcessConfigFp(fp, abs_path, calling_file, base_dir, contents, options, options2, error_list, warning_list);
|
success = ProcessConfigFp(fp, abs_path, calling_file, base_dir, contents, options, settings, error_list, warning_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(abs_path);
|
free(abs_path);
|
||||||
@@ -168,7 +168,7 @@ ProcessConfigFile(const char *base_dir, const char *config_file, const char *cal
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ProcessConfigFp(FILE *fp, const char *config_file, const char *calling_file, const char *base_dir, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *options2, ItemList *error_list, ItemList *warning_list)
|
ProcessConfigFp(FILE *fp, const char *config_file, const char *calling_file, const char *base_dir, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *settings, ItemList *error_list, ItemList *warning_list)
|
||||||
{
|
{
|
||||||
volatile bool OK = true;
|
volatile bool OK = true;
|
||||||
volatile YY_BUFFER_STATE lex_buffer = NULL;
|
volatile YY_BUFFER_STATE lex_buffer = NULL;
|
||||||
@@ -252,7 +252,7 @@ ProcessConfigFp(FILE *fp, const char *config_file, const char *calling_file, con
|
|||||||
* processed immediately.
|
* processed immediately.
|
||||||
*/
|
*/
|
||||||
if (!ProcessConfigDirectory(base_dir, opt_value, config_file,
|
if (!ProcessConfigDirectory(base_dir, opt_value, config_file,
|
||||||
contents, options, options2,
|
contents, options, settings,
|
||||||
error_list, warning_list))
|
error_list, warning_list))
|
||||||
OK = false;
|
OK = false;
|
||||||
yy_switch_to_buffer(lex_buffer);
|
yy_switch_to_buffer(lex_buffer);
|
||||||
@@ -262,7 +262,7 @@ ProcessConfigFp(FILE *fp, const char *config_file, const char *calling_file, con
|
|||||||
else if (base_dir != NULL && strcasecmp(opt_name, "include_if_exists") == 0)
|
else if (base_dir != NULL && strcasecmp(opt_name, "include_if_exists") == 0)
|
||||||
{
|
{
|
||||||
if (!ProcessConfigFile(base_dir, opt_value, config_file,
|
if (!ProcessConfigFile(base_dir, opt_value, config_file,
|
||||||
false, contents, options, options2,
|
false, contents, options, settings,
|
||||||
error_list, warning_list))
|
error_list, warning_list))
|
||||||
OK = false;
|
OK = false;
|
||||||
|
|
||||||
@@ -273,7 +273,7 @@ ProcessConfigFp(FILE *fp, const char *config_file, const char *calling_file, con
|
|||||||
else if (base_dir != NULL && strcasecmp(opt_name, "include") == 0)
|
else if (base_dir != NULL && strcasecmp(opt_name, "include") == 0)
|
||||||
{
|
{
|
||||||
if (!ProcessConfigFile(base_dir, opt_value, config_file,
|
if (!ProcessConfigFile(base_dir, opt_value, config_file,
|
||||||
true, contents, options, options2,
|
true, contents, options, settings,
|
||||||
error_list, warning_list))
|
error_list, warning_list))
|
||||||
OK = false;
|
OK = false;
|
||||||
|
|
||||||
@@ -293,16 +293,16 @@ ProcessConfigFp(FILE *fp, const char *config_file, const char *calling_file, con
|
|||||||
|
|
||||||
if (options != NULL)
|
if (options != NULL)
|
||||||
{
|
{
|
||||||
parse_configuration_item(options,
|
parse_configuration_item_old(options,
|
||||||
error_list,
|
error_list,
|
||||||
warning_list,
|
warning_list,
|
||||||
opt_name,
|
opt_name,
|
||||||
opt_value);
|
opt_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (1)
|
if (1) //options == NULL && contents == NULL)
|
||||||
{
|
{
|
||||||
parse_configuration_item2(error_list,
|
parse_configuration_item(error_list,
|
||||||
warning_list,
|
warning_list,
|
||||||
opt_name,
|
opt_name,
|
||||||
opt_value);
|
opt_value);
|
||||||
@@ -376,7 +376,7 @@ cleanup:
|
|||||||
* See ProcessConfigFp for further details.
|
* See ProcessConfigFp for further details.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
ProcessConfigDirectory(const char *base_dir, const char *includedir, const char *calling_file, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *options2, ItemList *error_list, ItemList *warning_list)
|
ProcessConfigDirectory(const char *base_dir, const char *includedir, const char *calling_file, KeyValueList *contents, t_configuration_options *options, ConfigFileSetting *settings, ItemList *error_list, ItemList *warning_list)
|
||||||
{
|
{
|
||||||
char *directory;
|
char *directory;
|
||||||
DIR *d;
|
DIR *d;
|
||||||
@@ -477,7 +477,7 @@ ProcessConfigDirectory(const char *base_dir, const char *includedir, const char
|
|||||||
for (i = 0; i < num_filenames; i++)
|
for (i = 0; i < num_filenames; i++)
|
||||||
{
|
{
|
||||||
if (!ProcessConfigFile(base_dir, filenames[i], calling_file,
|
if (!ProcessConfigFile(base_dir, filenames[i], calling_file,
|
||||||
true, contents, options, options2,
|
true, contents, options, settings,
|
||||||
error_list, warning_list))
|
error_list, warning_list))
|
||||||
{
|
{
|
||||||
status = false;
|
status = false;
|
||||||
|
|||||||
417
configfile.c
417
configfile.c
@@ -35,11 +35,11 @@ static bool config_file_provided = false;
|
|||||||
bool config_file_found = false;
|
bool config_file_found = false;
|
||||||
|
|
||||||
|
|
||||||
|
static void parse_config_old(bool terse);
|
||||||
static void parse_config(bool terse);
|
static void parse_config(bool terse);
|
||||||
static void parse_config2(bool terse);
|
|
||||||
|
|
||||||
static void _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *warning_list);
|
static void _parse_config_old(t_configuration_options *options, ItemList *error_list, ItemList *warning_list);
|
||||||
static void _parse_config2(ItemList *error_list, ItemList *warning_list);
|
static void _parse_config(ItemList *error_list, ItemList *warning_list);
|
||||||
|
|
||||||
static void _parse_line(char *buf, char *name, char *value);
|
static void _parse_line(char *buf, char *name, char *value);
|
||||||
static void parse_event_notifications_list(EventNotificationList *event_notifications, const char *arg);
|
static void parse_event_notifications_list(EventNotificationList *event_notifications, const char *arg);
|
||||||
@@ -67,7 +67,187 @@ progname(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
load_config(const char *config_file, bool verbose, bool terse, t_configuration_options *options, char *argv0)
|
load_config_old(const char *config_file, bool verbose, bool terse, t_configuration_options *options, char *argv0)
|
||||||
|
{
|
||||||
|
struct stat stat_config;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If a configuration file was provided, check it exists, otherwise emit
|
||||||
|
* an error and terminate. We assume that if a user explicitly provides a
|
||||||
|
* configuration file, they'll want to make sure it's used and not fall
|
||||||
|
* back to any of the defaults.
|
||||||
|
*/
|
||||||
|
if (config_file != NULL && config_file[0] != '\0')
|
||||||
|
{
|
||||||
|
strncpy(config_file_path, config_file, MAXPGPATH);
|
||||||
|
canonicalize_path(config_file_path);
|
||||||
|
|
||||||
|
/* relative path supplied - convert to absolute path */
|
||||||
|
if (config_file_path[0] != '/')
|
||||||
|
{
|
||||||
|
PQExpBufferData fullpath;
|
||||||
|
char *pwd = NULL;
|
||||||
|
|
||||||
|
initPQExpBuffer(&fullpath);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we'll attempt to use $PWD to derive the effective path; getcwd()
|
||||||
|
* will likely resolve symlinks, which may result in a path which
|
||||||
|
* isn't permanent (e.g. if filesystem mountpoints change).
|
||||||
|
*/
|
||||||
|
pwd = getenv("PWD");
|
||||||
|
|
||||||
|
if (pwd != NULL)
|
||||||
|
{
|
||||||
|
appendPQExpBufferStr(&fullpath, pwd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* $PWD not available - fall back to getcwd() */
|
||||||
|
char cwd[MAXPGPATH] = "";
|
||||||
|
|
||||||
|
if (getcwd(cwd, MAXPGPATH) == NULL)
|
||||||
|
{
|
||||||
|
log_error(_("unable to execute getcwd()"));
|
||||||
|
log_detail("%s", strerror(errno));
|
||||||
|
|
||||||
|
termPQExpBuffer(&fullpath);
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
|
appendPQExpBufferStr(&fullpath, cwd);
|
||||||
|
}
|
||||||
|
|
||||||
|
appendPQExpBuffer(&fullpath,
|
||||||
|
"/%s", config_file_path);
|
||||||
|
|
||||||
|
log_debug("relative configuration file converted to:\n \"%s\"",
|
||||||
|
fullpath.data);
|
||||||
|
|
||||||
|
strncpy(config_file_path, fullpath.data, MAXPGPATH);
|
||||||
|
|
||||||
|
termPQExpBuffer(&fullpath);
|
||||||
|
|
||||||
|
canonicalize_path(config_file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (stat(config_file_path, &stat_config) != 0)
|
||||||
|
{
|
||||||
|
log_error(_("provided configuration file \"%s\" not found"),
|
||||||
|
config_file);
|
||||||
|
log_detail("%s", strerror(errno));
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (verbose == true)
|
||||||
|
{
|
||||||
|
log_notice(_("using provided configuration file \"%s\""), config_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
config_file_provided = true;
|
||||||
|
config_file_found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------
|
||||||
|
* If no configuration file was provided, attempt to find a default file
|
||||||
|
* in this order:
|
||||||
|
* - location provided by packager
|
||||||
|
* - current directory
|
||||||
|
* - /etc/repmgr.conf
|
||||||
|
* - default sysconfdir
|
||||||
|
*
|
||||||
|
* here we just check for the existence of the file; parse_config() will
|
||||||
|
* handle read errors etc.
|
||||||
|
*
|
||||||
|
*-----------
|
||||||
|
*/
|
||||||
|
if (config_file_provided == false)
|
||||||
|
{
|
||||||
|
/* packagers: if feasible, patch configuration file path into "package_conf_file" */
|
||||||
|
char package_conf_file[MAXPGPATH] = "";
|
||||||
|
char my_exec_path[MAXPGPATH] = "";
|
||||||
|
char sysconf_etc_path[MAXPGPATH] = "";
|
||||||
|
|
||||||
|
/* 1. location provided by packager */
|
||||||
|
if (package_conf_file[0] != '\0')
|
||||||
|
{
|
||||||
|
if (verbose == true)
|
||||||
|
fprintf(stdout, _("INFO: checking for package configuration file \"%s\"\n"), package_conf_file);
|
||||||
|
|
||||||
|
if (stat(package_conf_file, &stat_config) == 0)
|
||||||
|
{
|
||||||
|
strncpy(config_file_path, package_conf_file, MAXPGPATH);
|
||||||
|
config_file_found = true;
|
||||||
|
goto end_search;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 2 "./repmgr.conf" */
|
||||||
|
log_verbose(LOG_INFO, _("looking for configuration file in current directory\n"));
|
||||||
|
|
||||||
|
maxpath_snprintf(config_file_path, "./%s", CONFIG_FILE_NAME);
|
||||||
|
canonicalize_path(config_file_path);
|
||||||
|
|
||||||
|
if (stat(config_file_path, &stat_config) == 0)
|
||||||
|
{
|
||||||
|
config_file_found = true;
|
||||||
|
goto end_search;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 3. "/etc/repmgr.conf" */
|
||||||
|
if (verbose == true)
|
||||||
|
fprintf(stdout, _("INFO: looking for configuration file in /etc\n"));
|
||||||
|
|
||||||
|
maxpath_snprintf(config_file_path, "/etc/%s", CONFIG_FILE_NAME);
|
||||||
|
if (stat(config_file_path, &stat_config) == 0)
|
||||||
|
{
|
||||||
|
config_file_found = true;
|
||||||
|
goto end_search;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 4. default sysconfdir */
|
||||||
|
if (find_my_exec(argv0, my_exec_path) < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("ERROR: %s: could not find own program executable\n"), argv0);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
get_etc_path(my_exec_path, sysconf_etc_path);
|
||||||
|
|
||||||
|
if (verbose == true)
|
||||||
|
fprintf(stdout, _("INFO: looking for configuration file in \"%s\"\n"), sysconf_etc_path);
|
||||||
|
|
||||||
|
maxpath_snprintf(config_file_path, "%s/%s", sysconf_etc_path, CONFIG_FILE_NAME);
|
||||||
|
if (stat(config_file_path, &stat_config) == 0)
|
||||||
|
{
|
||||||
|
config_file_found = true;
|
||||||
|
goto end_search;
|
||||||
|
}
|
||||||
|
|
||||||
|
end_search:
|
||||||
|
if (verbose == true)
|
||||||
|
{
|
||||||
|
if (config_file_found == true)
|
||||||
|
{
|
||||||
|
fprintf(stdout, _("INFO: configuration file found at: \"%s\"\n"), config_file_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stdout, _("INFO: no configuration file provided or found\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parse_config_old(terse);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
load_config(const char *config_file, bool verbose, bool terse, char *argv0)
|
||||||
{
|
{
|
||||||
struct stat stat_config;
|
struct stat stat_config;
|
||||||
|
|
||||||
@@ -246,187 +426,34 @@ end_search:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
load_config2(const char *config_file, bool verbose, bool terse, char *argv0)
|
static void
|
||||||
|
parse_config_old(bool terse)
|
||||||
{
|
{
|
||||||
struct stat stat_config;
|
/* Collate configuration file errors here for friendlier reporting */
|
||||||
|
static ItemList config_errors = {NULL, NULL};
|
||||||
|
static ItemList config_warnings = {NULL, NULL};
|
||||||
|
|
||||||
/*
|
_parse_config_old(&config_file_options, &config_errors, &config_warnings);
|
||||||
* If a configuration file was provided, check it exists, otherwise emit
|
|
||||||
* an error and terminate. We assume that if a user explicitly provides a
|
/* errors found - exit after printing details, and any warnings */
|
||||||
* configuration file, they'll want to make sure it's used and not fall
|
if (config_errors.head != NULL)
|
||||||
* back to any of the defaults.
|
|
||||||
*/
|
|
||||||
if (config_file != NULL && config_file[0] != '\0')
|
|
||||||
{
|
{
|
||||||
strncpy(config_file_path, config_file, MAXPGPATH);
|
exit_with_config_file_errors(&config_errors, &config_warnings, terse);
|
||||||
canonicalize_path(config_file_path);
|
|
||||||
|
|
||||||
/* relative path supplied - convert to absolute path */
|
|
||||||
if (config_file_path[0] != '/')
|
|
||||||
{
|
|
||||||
PQExpBufferData fullpath;
|
|
||||||
char *pwd = NULL;
|
|
||||||
|
|
||||||
initPQExpBuffer(&fullpath);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* we'll attempt to use $PWD to derive the effective path; getcwd()
|
|
||||||
* will likely resolve symlinks, which may result in a path which
|
|
||||||
* isn't permanent (e.g. if filesystem mountpoints change).
|
|
||||||
*/
|
|
||||||
pwd = getenv("PWD");
|
|
||||||
|
|
||||||
if (pwd != NULL)
|
|
||||||
{
|
|
||||||
appendPQExpBufferStr(&fullpath, pwd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* $PWD not available - fall back to getcwd() */
|
|
||||||
char cwd[MAXPGPATH] = "";
|
|
||||||
|
|
||||||
if (getcwd(cwd, MAXPGPATH) == NULL)
|
|
||||||
{
|
|
||||||
log_error(_("unable to execute getcwd()"));
|
|
||||||
log_detail("%s", strerror(errno));
|
|
||||||
|
|
||||||
termPQExpBuffer(&fullpath);
|
|
||||||
exit(ERR_BAD_CONFIG);
|
|
||||||
}
|
|
||||||
|
|
||||||
appendPQExpBufferStr(&fullpath, cwd);
|
|
||||||
}
|
|
||||||
|
|
||||||
appendPQExpBuffer(&fullpath,
|
|
||||||
"/%s", config_file_path);
|
|
||||||
|
|
||||||
log_debug("relative configuration file converted to:\n \"%s\"",
|
|
||||||
fullpath.data);
|
|
||||||
|
|
||||||
strncpy(config_file_path, fullpath.data, MAXPGPATH);
|
|
||||||
|
|
||||||
termPQExpBuffer(&fullpath);
|
|
||||||
|
|
||||||
canonicalize_path(config_file_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (stat(config_file_path, &stat_config) != 0)
|
|
||||||
{
|
|
||||||
log_error(_("provided configuration file \"%s\" not found"),
|
|
||||||
config_file);
|
|
||||||
log_detail("%s", strerror(errno));
|
|
||||||
exit(ERR_BAD_CONFIG);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (verbose == true)
|
|
||||||
{
|
|
||||||
log_notice(_("using provided configuration file \"%s\""), config_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
config_file_provided = true;
|
|
||||||
config_file_found = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (terse == false && config_warnings.head != NULL)
|
||||||
/*-----------
|
|
||||||
* If no configuration file was provided, attempt to find a default file
|
|
||||||
* in this order:
|
|
||||||
* - location provided by packager
|
|
||||||
* - current directory
|
|
||||||
* - /etc/repmgr.conf
|
|
||||||
* - default sysconfdir
|
|
||||||
*
|
|
||||||
* here we just check for the existence of the file; parse_config() will
|
|
||||||
* handle read errors etc.
|
|
||||||
*
|
|
||||||
*-----------
|
|
||||||
*/
|
|
||||||
if (config_file_provided == false)
|
|
||||||
{
|
{
|
||||||
/* packagers: if feasible, patch configuration file path into "package_conf_file" */
|
log_warning(_("the following problems were found in the configuration file:"));
|
||||||
char package_conf_file[MAXPGPATH] = "";
|
|
||||||
char my_exec_path[MAXPGPATH] = "";
|
|
||||||
char sysconf_etc_path[MAXPGPATH] = "";
|
|
||||||
|
|
||||||
/* 1. location provided by packager */
|
print_item_list(&config_warnings);
|
||||||
if (package_conf_file[0] != '\0')
|
|
||||||
{
|
|
||||||
if (verbose == true)
|
|
||||||
fprintf(stdout, _("INFO: checking for package configuration file \"%s\"\n"), package_conf_file);
|
|
||||||
|
|
||||||
if (stat(package_conf_file, &stat_config) == 0)
|
|
||||||
{
|
|
||||||
strncpy(config_file_path, package_conf_file, MAXPGPATH);
|
|
||||||
config_file_found = true;
|
|
||||||
goto end_search;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 2 "./repmgr.conf" */
|
|
||||||
log_verbose(LOG_INFO, _("looking for configuration file in current directory\n"));
|
|
||||||
|
|
||||||
maxpath_snprintf(config_file_path, "./%s", CONFIG_FILE_NAME);
|
|
||||||
canonicalize_path(config_file_path);
|
|
||||||
|
|
||||||
if (stat(config_file_path, &stat_config) == 0)
|
|
||||||
{
|
|
||||||
config_file_found = true;
|
|
||||||
goto end_search;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 3. "/etc/repmgr.conf" */
|
|
||||||
if (verbose == true)
|
|
||||||
fprintf(stdout, _("INFO: looking for configuration file in /etc\n"));
|
|
||||||
|
|
||||||
maxpath_snprintf(config_file_path, "/etc/%s", CONFIG_FILE_NAME);
|
|
||||||
if (stat(config_file_path, &stat_config) == 0)
|
|
||||||
{
|
|
||||||
config_file_found = true;
|
|
||||||
goto end_search;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 4. default sysconfdir */
|
|
||||||
if (find_my_exec(argv0, my_exec_path) < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, _("ERROR: %s: could not find own program executable\n"), argv0);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
get_etc_path(my_exec_path, sysconf_etc_path);
|
|
||||||
|
|
||||||
if (verbose == true)
|
|
||||||
fprintf(stdout, _("INFO: looking for configuration file in \"%s\"\n"), sysconf_etc_path);
|
|
||||||
|
|
||||||
maxpath_snprintf(config_file_path, "%s/%s", sysconf_etc_path, CONFIG_FILE_NAME);
|
|
||||||
if (stat(config_file_path, &stat_config) == 0)
|
|
||||||
{
|
|
||||||
config_file_found = true;
|
|
||||||
goto end_search;
|
|
||||||
}
|
|
||||||
|
|
||||||
end_search:
|
|
||||||
if (verbose == true)
|
|
||||||
{
|
|
||||||
if (config_file_found == true)
|
|
||||||
{
|
|
||||||
fprintf(stdout, _("INFO: configuration file found at: \"%s\"\n"), config_file_path);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stdout, _("INFO: no configuration file provided or found\n"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_config2(terse);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_config(bool terse)
|
parse_config(bool terse)
|
||||||
{
|
{
|
||||||
@@ -434,34 +461,7 @@ parse_config(bool terse)
|
|||||||
static ItemList config_errors = {NULL, NULL};
|
static ItemList config_errors = {NULL, NULL};
|
||||||
static ItemList config_warnings = {NULL, NULL};
|
static ItemList config_warnings = {NULL, NULL};
|
||||||
|
|
||||||
_parse_config(&config_file_options, &config_errors, &config_warnings);
|
_parse_config(&config_errors, &config_warnings);
|
||||||
|
|
||||||
/* errors found - exit after printing details, and any warnings */
|
|
||||||
if (config_errors.head != NULL)
|
|
||||||
{
|
|
||||||
exit_with_config_file_errors(&config_errors, &config_warnings, terse);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (terse == false && config_warnings.head != NULL)
|
|
||||||
{
|
|
||||||
log_warning(_("the following problems were found in the configuration file:"));
|
|
||||||
|
|
||||||
print_item_list(&config_warnings);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
parse_config2(bool terse)
|
|
||||||
{
|
|
||||||
/* Collate configuration file errors here for friendlier reporting */
|
|
||||||
static ItemList config_errors = {NULL, NULL};
|
|
||||||
static ItemList config_warnings = {NULL, NULL};
|
|
||||||
|
|
||||||
_parse_config2(&config_errors, &config_warnings);
|
|
||||||
|
|
||||||
/* errors found - exit after printing details, and any warnings */
|
/* errors found - exit after printing details, and any warnings */
|
||||||
if (config_errors.head != NULL)
|
if (config_errors.head != NULL)
|
||||||
@@ -481,7 +481,7 @@ parse_config2(bool terse)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_parse_config2(ItemList *error_list, ItemList *warning_list)
|
_parse_config(ItemList *error_list, ItemList *warning_list)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char base_directory[MAXPGPATH];
|
char base_directory[MAXPGPATH];
|
||||||
@@ -532,7 +532,8 @@ _parse_config2(ItemList *error_list, ItemList *warning_list)
|
|||||||
get_parent_directory(base_directory);
|
get_parent_directory(base_directory);
|
||||||
|
|
||||||
// XXX fail here if processing issue found
|
// XXX fail here if processing issue found
|
||||||
(void) ProcessRepmgrConfigFile2(config_file_path, base_directory, error_list, warning_list);
|
(void) ProcessRepmgrConfigFile(config_file_path, base_directory, error_list, warning_list);
|
||||||
|
|
||||||
|
|
||||||
/* check required parameters */
|
/* check required parameters */
|
||||||
// ...
|
// ...
|
||||||
@@ -587,11 +588,10 @@ _parse_config2(ItemList *error_list, ItemList *warning_list)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_configuration_item2(ItemList *error_list, ItemList *warning_list, const char *name, const char *value)
|
parse_configuration_item(ItemList *error_list, ItemList *warning_list, const char *name, const char *value)
|
||||||
{
|
{
|
||||||
ConfigFileSetting *setting = &config_file_settings[0];
|
ConfigFileSetting *setting = &config_file_settings[0];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (strcmp(name, setting->name) == 0)
|
if (strcmp(name, setting->name) == 0)
|
||||||
{
|
{
|
||||||
@@ -766,7 +766,7 @@ parse_configuration_item2(ItemList *error_list, ItemList *warning_list, const ch
|
|||||||
* by the caller.
|
* by the caller.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
_parse_config(t_configuration_options *options, ItemList *error_list, ItemList *warning_list)
|
_parse_config_old(t_configuration_options *options, ItemList *error_list, ItemList *warning_list)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char base_directory[MAXPGPATH];
|
char base_directory[MAXPGPATH];
|
||||||
@@ -994,8 +994,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
|
|||||||
get_parent_directory(base_directory);
|
get_parent_directory(base_directory);
|
||||||
|
|
||||||
// XXX fail here if processing issue found
|
// XXX fail here if processing issue found
|
||||||
(void) ProcessRepmgrConfigFile(config_file_path, base_directory, options, error_list, warning_list);
|
(void) ProcessRepmgrConfigFileOld(config_file_path, base_directory, options, error_list, warning_list);
|
||||||
|
|
||||||
|
|
||||||
/* check required parameters */
|
/* check required parameters */
|
||||||
if (options->node_id == UNKNOWN_NODE_ID)
|
if (options->node_id == UNKNOWN_NODE_ID)
|
||||||
@@ -1085,7 +1084,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_configuration_item(t_configuration_options *options, ItemList *error_list, ItemList *warning_list, const char *name, const char *value)
|
parse_configuration_item_old(t_configuration_options *options, ItemList *error_list, ItemList *warning_list, const char *name, const char *value)
|
||||||
{
|
{
|
||||||
if (strcmp(name, "node_id") == 0)
|
if (strcmp(name, "node_id") == 0)
|
||||||
{
|
{
|
||||||
@@ -1669,7 +1668,7 @@ reload_config(t_server_type server_type)
|
|||||||
* checks here. We do still need to check for repmgrd-specific
|
* checks here. We do still need to check for repmgrd-specific
|
||||||
* requirements.
|
* requirements.
|
||||||
*/
|
*/
|
||||||
_parse_config(&config_file_options, &config_errors, &config_warnings);
|
_parse_config(&config_errors, &config_warnings);
|
||||||
|
|
||||||
if (config_file_options.failover == FAILOVER_AUTOMATIC
|
if (config_file_options.failover == FAILOVER_AUTOMATIC
|
||||||
&& (server_type == PRIMARY || server_type == STANDBY))
|
&& (server_type == PRIMARY || server_type == STANDBY))
|
||||||
|
|||||||
12
configfile.h
12
configfile.h
@@ -369,13 +369,13 @@ typedef struct
|
|||||||
void set_progname(const char *argv0);
|
void set_progname(const char *argv0);
|
||||||
const char *progname(void);
|
const char *progname(void);
|
||||||
|
|
||||||
void load_config(const char *config_file, bool verbose, bool terse, t_configuration_options *options, char *argv0);
|
void load_config_old(const char *config_file, bool verbose, bool terse, t_configuration_options *options, char *argv0);
|
||||||
void load_config2(const char *config_file, bool verbose, bool terse, char *argv0);
|
void load_config(const char *config_file, bool verbose, bool terse, char *argv0);
|
||||||
|
|
||||||
bool reload_config(t_server_type server_type);
|
bool reload_config(t_server_type server_type);
|
||||||
|
|
||||||
void parse_configuration_item(t_configuration_options *options, ItemList *error_list, ItemList *warning_list, const char *name, const char *value);
|
void parse_configuration_item_old(t_configuration_options *options, ItemList *error_list, ItemList *warning_list, const char *name, const char *value);
|
||||||
void parse_configuration_item2(ItemList *error_list, ItemList *warning_list, const char *name, const char *value);
|
void parse_configuration_item(ItemList *error_list, ItemList *warning_list, const char *name, const char *value);
|
||||||
|
|
||||||
bool parse_recovery_conf(const char *data_dir, t_recovery_conf *conf);
|
bool parse_recovery_conf(const char *data_dir, t_recovery_conf *conf);
|
||||||
|
|
||||||
@@ -409,9 +409,9 @@ char *print_event_notification_list(EventNotificationList *list);
|
|||||||
|
|
||||||
extern bool modify_auto_conf(const char *data_dir, KeyValueList *items);
|
extern bool modify_auto_conf(const char *data_dir, KeyValueList *items);
|
||||||
|
|
||||||
extern bool ProcessRepmgrConfigFile(const char *config_file, const char *base_dir, t_configuration_options *options, ItemList *error_list, ItemList *warning_list);
|
extern bool ProcessRepmgrConfigFileOld(const char *config_file, const char *base_dir, t_configuration_options *options, ItemList *error_list, ItemList *warning_list);
|
||||||
|
|
||||||
extern bool ProcessRepmgrConfigFile2(const char *config_file, const char *base_dir, ItemList *error_list, ItemList *warning_list);
|
extern bool ProcessRepmgrConfigFile(const char *config_file, const char *base_dir, ItemList *error_list, ItemList *warning_list);
|
||||||
|
|
||||||
extern bool ProcessPostgresConfigFile(const char *config_file, const char *base_dir, KeyValueList *contents, ItemList *error_list, ItemList *warning_list);
|
extern bool ProcessPostgresConfigFile(const char *config_file, const char *base_dir, KeyValueList *contents, ItemList *error_list, ItemList *warning_list);
|
||||||
|
|
||||||
|
|||||||
@@ -1074,11 +1074,12 @@ main(int argc, char **argv)
|
|||||||
* clone'), however if available we'll parse it anyway for options like
|
* clone'), however if available we'll parse it anyway for options like
|
||||||
* 'log_level', 'use_replication_slots' etc.
|
* 'log_level', 'use_replication_slots' etc.
|
||||||
*/
|
*/
|
||||||
load_config2(runtime_options.config_file,
|
load_config(runtime_options.config_file,
|
||||||
runtime_options.verbose,
|
runtime_options.verbose,
|
||||||
runtime_options.terse,
|
runtime_options.terse,
|
||||||
argv[0]);
|
argv[0]);
|
||||||
exit(0);
|
|
||||||
|
//exit(0);
|
||||||
check_cli_parameters(action);
|
check_cli_parameters(action);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ main(int argc, char **argv)
|
|||||||
* locations). If no conifguration file is available, or it can't be parsed
|
* locations). If no conifguration file is available, or it can't be parsed
|
||||||
* parse_config() will abort anyway, with an appropriate message.
|
* parse_config() will abort anyway, with an appropriate message.
|
||||||
*/
|
*/
|
||||||
load_config(config_file, verbose, false, &config_file_options, argv[0]);
|
load_config(config_file, verbose, false, argv[0]);
|
||||||
|
|
||||||
/* Determine pid file location, unless --no-pid-file supplied */
|
/* Determine pid file location, unless --no-pid-file supplied */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user