mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Prevent relative configuration file path being stored in the repmgr metadata
The configuration file path is stored to make remote execution of repmgr (e.g. during "repmgr standby switchover") simpler, so relative paths make no sense. Addresses GitHub #332
This commit is contained in:
54
configfile.c
54
configfile.c
@@ -73,6 +73,59 @@ load_config(const char *config_file, bool verbose, bool terse, t_configuration_o
|
||||
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)
|
||||
{
|
||||
appendPQExpBuffer(&fullpath,
|
||||
"%s", 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);
|
||||
}
|
||||
|
||||
appendPQExpBuffer(&fullpath,
|
||||
"%s",
|
||||
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: %s"),
|
||||
@@ -81,6 +134,7 @@ load_config(const char *config_file, bool verbose, bool terse, t_configuration_o
|
||||
exit(ERR_BAD_CONFIG);
|
||||
}
|
||||
|
||||
|
||||
if (verbose == true)
|
||||
{
|
||||
log_notice(_("using provided configuration file \"%s\""), config_file);
|
||||
|
||||
@@ -48,4 +48,17 @@
|
||||
reading the wrong configuraton file.
|
||||
</para>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
If providing the configuration file location with <literal>-f/--config-file</literal>,
|
||||
avoid using a relative path, particularly when executing <xref linkend="repmgr-primary-register">
|
||||
and <xref linkend="repmgr-standby-register">, as &repmgr; stores the configuration file location
|
||||
in the repmgr metadata for use when &repmgr; is executed remotely (e.g. during
|
||||
<xref linkend="repmgr-standby-switchover">). &repmgr; will attempt to convert the
|
||||
a relative path into an absolute one, but this may not be the same as the path you
|
||||
would explicitly provide (e.g. <filename>./repmgr.conf</filename> might be converted
|
||||
to <filename>/path/to/./repmgr.conf</filename>, whereas you'd normally write
|
||||
<filename>/path/to/repmgr.conf</filename>).
|
||||
</para>
|
||||
</note>
|
||||
</sect1>
|
||||
|
||||
@@ -15,4 +15,18 @@
|
||||
<command>repmgr master register</command> can be used as an alias for
|
||||
<command>repmgr primary register</command>.
|
||||
</para>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
If providing the configuration file location with <literal>-f/--config-file</literal>,
|
||||
avoid using a relative path, as &repmgr; stores the configuration file location
|
||||
in the repmgr metadata for use when &repmgr; is executed remotely (e.g. during
|
||||
<xref linkend="repmgr-standby-switchover">). &repmgr; will attempt to convert the
|
||||
a relative path into an absolute one, but this may not be the same as the path you
|
||||
would explicitly provide (e.g. <filename>./repmgr.conf</filename> might be converted
|
||||
to <filename>/path/to/./repmgr.conf</filename>, whereas you'd normally write
|
||||
<filename>/path/to/repmgr.conf</filename>).
|
||||
</para>
|
||||
</note>
|
||||
|
||||
</chapter>
|
||||
|
||||
@@ -10,6 +10,19 @@
|
||||
standby.
|
||||
</para>
|
||||
|
||||
<note>
|
||||
<para>
|
||||
If providing the configuration file location with <literal>-f/--config-file</literal>,
|
||||
avoid using a relative path, as &repmgr; stores the configuration file location
|
||||
in the repmgr metadata for use when &repmgr; is executed remotely (e.g. during
|
||||
<xref linkend="repmgr-standby-switchover">). &repmgr; will attempt to convert the
|
||||
a relative path into an absolute one, but this may not be the same as the path you
|
||||
would explicitly provide (e.g. <filename>./repmgr.conf</filename> might be converted
|
||||
to <filename>/path/to/./repmgr.conf</filename>, whereas you'd normally write
|
||||
<filename>/path/to/repmgr.conf</filename>).
|
||||
</para>
|
||||
</note>
|
||||
|
||||
<sect1 id="repmgr-standby-register-wait" xreflabel="repmgr standby register --wait">
|
||||
<title>Waiting for the registration to propagate to the standby</title>
|
||||
<para>
|
||||
|
||||
Reference in New Issue
Block a user