mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Use canonicalize_path for -D, GUC paths, and paths coming in from
environment variables.
This commit is contained in:
parent
8801110b20
commit
7b0f060d54
@ -37,7 +37,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.407 2004/07/11 00:18:43 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.408 2004/07/11 21:33:59 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
*
|
*
|
||||||
@ -372,7 +372,8 @@ PostmasterMain(int argc, char *argv[])
|
|||||||
InitializeGUCOptions();
|
InitializeGUCOptions();
|
||||||
|
|
||||||
userPGDATA = getenv("PGDATA"); /* default value */
|
userPGDATA = getenv("PGDATA"); /* default value */
|
||||||
|
canonicalize_path(userPGDATA);
|
||||||
|
|
||||||
opterr = 1;
|
opterr = 1;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != -1)
|
while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != -1)
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.214 2004/07/11 00:18:44 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.215 2004/07/11 21:34:00 momjian Exp $
|
||||||
*
|
*
|
||||||
*--------------------------------------------------------------------
|
*--------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -113,6 +113,7 @@ static const char *assign_custom_variable_classes(const char *newval, bool doit,
|
|||||||
static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
|
static bool assign_stage_log_stats(bool newval, bool doit, GucSource source);
|
||||||
static bool assign_log_stats(bool newval, bool doit, GucSource source);
|
static bool assign_log_stats(bool newval, bool doit, GucSource source);
|
||||||
static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
|
static bool assign_transaction_read_only(bool newval, bool doit, GucSource source);
|
||||||
|
static const char *assign_canonical_path(const char *newval, bool doit, GucSource source);
|
||||||
|
|
||||||
static void ReadConfigFile(char *filename, GucContext context);
|
static void ReadConfigFile(char *filename, GucContext context);
|
||||||
|
|
||||||
@ -1470,7 +1471,7 @@ static struct config_string ConfigureNamesString[] =
|
|||||||
"the specified file.")
|
"the specified file.")
|
||||||
},
|
},
|
||||||
&Dynamic_library_path,
|
&Dynamic_library_path,
|
||||||
"$libdir", NULL, NULL
|
"$libdir", assign_canonical_path, NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -1556,7 +1557,7 @@ static struct config_string ConfigureNamesString[] =
|
|||||||
GUC_LIST_INPUT | GUC_LIST_QUOTE
|
GUC_LIST_INPUT | GUC_LIST_QUOTE
|
||||||
},
|
},
|
||||||
&preload_libraries_string,
|
&preload_libraries_string,
|
||||||
"", NULL, NULL
|
"", assign_canonical_path, NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -1678,7 +1679,7 @@ static struct config_string ConfigureNamesString[] =
|
|||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
&UnixSocketDir,
|
&UnixSocketDir,
|
||||||
"", NULL, NULL
|
"", assign_canonical_path, NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -1712,25 +1713,25 @@ static struct config_string ConfigureNamesString[] =
|
|||||||
{
|
{
|
||||||
{"pgdata", PGC_POSTMASTER, 0, gettext_noop("Sets the location of the data directory"), NULL},
|
{"pgdata", PGC_POSTMASTER, 0, gettext_noop("Sets the location of the data directory"), NULL},
|
||||||
&guc_pgdata,
|
&guc_pgdata,
|
||||||
NULL, NULL, NULL
|
NULL, assign_canonical_path, NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
{"hba_conf", PGC_SIGHUP, 0, gettext_noop("Sets the location of the \"hba\" configuration file"), NULL},
|
{"hba_conf", PGC_SIGHUP, 0, gettext_noop("Sets the location of the \"hba\" configuration file"), NULL},
|
||||||
&guc_hbafile,
|
&guc_hbafile,
|
||||||
NULL, NULL, NULL
|
NULL, assign_canonical_path, NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
{"ident_conf", PGC_SIGHUP, 0, gettext_noop("Sets the location of the \"ident\" configuration file"), NULL},
|
{"ident_conf", PGC_SIGHUP, 0, gettext_noop("Sets the location of the \"ident\" configuration file"), NULL},
|
||||||
&guc_identfile,
|
&guc_identfile,
|
||||||
NULL, NULL, NULL
|
NULL, assign_canonical_path, NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
{"external_pidfile", PGC_POSTMASTER, 0, gettext_noop("Writes the postmaster PID to the specified file"), NULL},
|
{"external_pidfile", PGC_POSTMASTER, 0, gettext_noop("Writes the postmaster PID to the specified file"), NULL},
|
||||||
&external_pidfile,
|
&external_pidfile,
|
||||||
NULL, NULL, NULL
|
NULL, assign_canonical_path, NULL
|
||||||
},
|
},
|
||||||
|
|
||||||
/* End-of-list marker */
|
/* End-of-list marker */
|
||||||
@ -5160,8 +5161,7 @@ assign_log_min_messages(const char *newval,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
assign_client_min_messages(const char *newval,
|
assign_client_min_messages(const char *newval, bool doit, GucSource source)
|
||||||
bool doit, GucSource source)
|
|
||||||
{
|
{
|
||||||
return (assign_msglvl(&client_min_messages, newval, doit, source));
|
return (assign_msglvl(&client_min_messages, newval, doit, source));
|
||||||
}
|
}
|
||||||
@ -5430,4 +5430,19 @@ assign_transaction_read_only(bool newval, bool doit, GucSource source)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
assign_canonical_path(const char *newval, bool doit, GucSource source)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (doit)
|
||||||
|
{
|
||||||
|
/* We have to create a new pointer to force the change */
|
||||||
|
char *canon_val = guc_strdup(FATAL, newval);
|
||||||
|
canonicalize_path(canon_val);
|
||||||
|
return canon_val;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return newval;
|
||||||
|
}
|
||||||
|
|
||||||
#include "guc-file.c"
|
#include "guc-file.c"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.119 2004/07/11 13:29:15 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.120 2004/07/11 21:34:03 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
@ -375,6 +375,7 @@ exec_command(const char *cmd,
|
|||||||
fname = psql_scan_slash_option(scan_state,
|
fname = psql_scan_slash_option(scan_state,
|
||||||
OT_NORMAL, NULL, true);
|
OT_NORMAL, NULL, true);
|
||||||
expand_tilde(&fname);
|
expand_tilde(&fname);
|
||||||
|
canonicalize_path(fname);
|
||||||
status = do_edit(fname, query_buf) ? CMD_NEWEDIT : CMD_ERROR;
|
status = do_edit(fname, query_buf) ? CMD_NEWEDIT : CMD_ERROR;
|
||||||
free(fname);
|
free(fname);
|
||||||
}
|
}
|
||||||
@ -777,8 +778,10 @@ exec_command(const char *cmd,
|
|||||||
fd = popen(&fname[1], "w");
|
fd = popen(&fname[1], "w");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
canonicalize_path(fname);
|
||||||
fd = fopen(fname, "w");
|
fd = fopen(fname, "w");
|
||||||
|
}
|
||||||
if (!fd)
|
if (!fd)
|
||||||
{
|
{
|
||||||
psql_error("%s: %s\n", fname, strerror(errno));
|
psql_error("%s: %s\n", fname, strerror(errno));
|
||||||
@ -1122,7 +1125,6 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
|
|||||||
|
|
||||||
if (filename_arg)
|
if (filename_arg)
|
||||||
fname = filename_arg;
|
fname = filename_arg;
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* make a temp file to edit */
|
/* make a temp file to edit */
|
||||||
@ -1262,6 +1264,7 @@ process_file(char *filename)
|
|||||||
if (!filename)
|
if (!filename)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
canonicalize_path(filename);
|
||||||
fd = fopen(filename, PG_BINARY_R);
|
fd = fopen(filename, PG_BINARY_R);
|
||||||
|
|
||||||
if (!fd)
|
if (!fd)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.49 2004/07/11 13:29:15 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.50 2004/07/11 21:34:03 momjian Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "copy.h"
|
#include "copy.h"
|
||||||
@ -513,6 +513,8 @@ do_copy(const char *args)
|
|||||||
appendPQExpBuffer(&query, " FORCE NOT NULL %s", options->force_notnull_list);
|
appendPQExpBuffer(&query, " FORCE NOT NULL %s", options->force_notnull_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canonicalize_path(options->file);
|
||||||
|
|
||||||
if (options->from)
|
if (options->from)
|
||||||
{
|
{
|
||||||
if (options->file)
|
if (options->file)
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/port/path.c,v 1.22 2004/07/11 02:59:42 momjian Exp $
|
* $PostgreSQL: pgsql/src/port/path.c,v 1.23 2004/07/11 21:34:04 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -33,6 +33,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
const static char *relative_path(const char *bin_path, const char *other_path);
|
const static char *relative_path(const char *bin_path, const char *other_path);
|
||||||
|
static void make_relative(const char *my_exec_path, const char *p, char *ret_path);
|
||||||
static void trim_directory(char *path);
|
static void trim_directory(char *path);
|
||||||
static void trim_trailing_separator(char *path);
|
static void trim_trailing_separator(char *path);
|
||||||
|
|
||||||
@ -43,15 +44,6 @@ static void trim_trailing_separator(char *path);
|
|||||||
(p)++; \
|
(p)++; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Macro creates a relative path */
|
|
||||||
#define MAKE_RELATIVE \
|
|
||||||
do { \
|
|
||||||
StrNCpy(path, my_exec_path, MAXPGPATH); \
|
|
||||||
trim_directory(path); \
|
|
||||||
trim_directory(path); \
|
|
||||||
snprintf(ret_path, MAXPGPATH, "%s/%s", path, p); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* first_dir_separator
|
* first_dir_separator
|
||||||
*/
|
*/
|
||||||
@ -140,13 +132,13 @@ get_progname(const char *argv0)
|
|||||||
void
|
void
|
||||||
get_share_path(const char *my_exec_path, char *ret_path)
|
get_share_path(const char *my_exec_path, char *ret_path)
|
||||||
{
|
{
|
||||||
char path[MAXPGPATH];
|
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if ((p = relative_path(PGBINDIR, PGSHAREDIR)))
|
if ((p = relative_path(PGBINDIR, PGSHAREDIR)))
|
||||||
MAKE_RELATIVE;
|
make_relative(my_exec_path, p, ret_path);
|
||||||
else
|
else
|
||||||
StrNCpy(ret_path, PGSHAREDIR, MAXPGPATH);
|
StrNCpy(ret_path, PGSHAREDIR, MAXPGPATH);
|
||||||
|
canonicalize_path(ret_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -157,13 +149,13 @@ get_share_path(const char *my_exec_path, char *ret_path)
|
|||||||
void
|
void
|
||||||
get_etc_path(const char *my_exec_path, char *ret_path)
|
get_etc_path(const char *my_exec_path, char *ret_path)
|
||||||
{
|
{
|
||||||
char path[MAXPGPATH];
|
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if ((p = relative_path(PGBINDIR, SYSCONFDIR)))
|
if ((p = relative_path(PGBINDIR, SYSCONFDIR)))
|
||||||
MAKE_RELATIVE;
|
make_relative(my_exec_path, p, ret_path);
|
||||||
else
|
else
|
||||||
StrNCpy(ret_path, SYSCONFDIR, MAXPGPATH);
|
StrNCpy(ret_path, SYSCONFDIR, MAXPGPATH);
|
||||||
|
canonicalize_path(ret_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -174,13 +166,13 @@ get_etc_path(const char *my_exec_path, char *ret_path)
|
|||||||
void
|
void
|
||||||
get_include_path(const char *my_exec_path, char *ret_path)
|
get_include_path(const char *my_exec_path, char *ret_path)
|
||||||
{
|
{
|
||||||
char path[MAXPGPATH];
|
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if ((p = relative_path(PGBINDIR, INCLUDEDIR)))
|
if ((p = relative_path(PGBINDIR, INCLUDEDIR)))
|
||||||
MAKE_RELATIVE;
|
make_relative(my_exec_path, p, ret_path);
|
||||||
else
|
else
|
||||||
StrNCpy(ret_path, INCLUDEDIR, MAXPGPATH);
|
StrNCpy(ret_path, INCLUDEDIR, MAXPGPATH);
|
||||||
|
canonicalize_path(ret_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -191,13 +183,13 @@ get_include_path(const char *my_exec_path, char *ret_path)
|
|||||||
void
|
void
|
||||||
get_pkginclude_path(const char *my_exec_path, char *ret_path)
|
get_pkginclude_path(const char *my_exec_path, char *ret_path)
|
||||||
{
|
{
|
||||||
char path[MAXPGPATH];
|
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if ((p = relative_path(PGBINDIR, PKGINCLUDEDIR)))
|
if ((p = relative_path(PGBINDIR, PKGINCLUDEDIR)))
|
||||||
MAKE_RELATIVE;
|
make_relative(my_exec_path, p, ret_path);
|
||||||
else
|
else
|
||||||
StrNCpy(ret_path, PKGINCLUDEDIR, MAXPGPATH);
|
StrNCpy(ret_path, PKGINCLUDEDIR, MAXPGPATH);
|
||||||
|
canonicalize_path(ret_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -210,13 +202,13 @@ get_pkginclude_path(const char *my_exec_path, char *ret_path)
|
|||||||
void
|
void
|
||||||
get_pkglib_path(const char *my_exec_path, char *ret_path)
|
get_pkglib_path(const char *my_exec_path, char *ret_path)
|
||||||
{
|
{
|
||||||
char path[MAXPGPATH];
|
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if ((p = relative_path(PGBINDIR, PKGLIBDIR)))
|
if ((p = relative_path(PGBINDIR, PKGLIBDIR)))
|
||||||
MAKE_RELATIVE;
|
make_relative(my_exec_path, p, ret_path);
|
||||||
else
|
else
|
||||||
StrNCpy(ret_path, PKGLIBDIR, MAXPGPATH);
|
StrNCpy(ret_path, PKGLIBDIR, MAXPGPATH);
|
||||||
|
canonicalize_path(ret_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -229,13 +221,13 @@ get_pkglib_path(const char *my_exec_path, char *ret_path)
|
|||||||
void
|
void
|
||||||
get_locale_path(const char *my_exec_path, char *ret_path)
|
get_locale_path(const char *my_exec_path, char *ret_path)
|
||||||
{
|
{
|
||||||
char path[MAXPGPATH];
|
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if ((p = relative_path(PGBINDIR, LOCALEDIR)))
|
if ((p = relative_path(PGBINDIR, LOCALEDIR)))
|
||||||
MAKE_RELATIVE;
|
make_relative(my_exec_path, p, ret_path);
|
||||||
else
|
else
|
||||||
StrNCpy(ret_path, LOCALEDIR, MAXPGPATH);
|
StrNCpy(ret_path, LOCALEDIR, MAXPGPATH);
|
||||||
|
canonicalize_path(ret_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -270,6 +262,7 @@ set_pglocale_pgservice(const char *argv0, const char *app)
|
|||||||
{
|
{
|
||||||
/* set for libpq to use */
|
/* set for libpq to use */
|
||||||
snprintf(env_path, sizeof(env_path), "PGLOCALEDIR=%s", path);
|
snprintf(env_path, sizeof(env_path), "PGLOCALEDIR=%s", path);
|
||||||
|
canonicalize_path(env_path);
|
||||||
putenv(strdup(env_path));
|
putenv(strdup(env_path));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -280,11 +273,26 @@ set_pglocale_pgservice(const char *argv0, const char *app)
|
|||||||
|
|
||||||
/* set for libpq to use */
|
/* set for libpq to use */
|
||||||
snprintf(env_path, sizeof(env_path), "PGSYSCONFDIR=%s", path);
|
snprintf(env_path, sizeof(env_path), "PGSYSCONFDIR=%s", path);
|
||||||
|
canonicalize_path(env_path);
|
||||||
putenv(strdup(env_path));
|
putenv(strdup(env_path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* make_relative - adjust path to be relative to bin/
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
make_relative(const char *my_exec_path, const char *p, char *ret_path)
|
||||||
|
{
|
||||||
|
char path[MAXPGPATH];
|
||||||
|
|
||||||
|
StrNCpy(path, my_exec_path, MAXPGPATH);
|
||||||
|
trim_directory(path);
|
||||||
|
trim_directory(path);
|
||||||
|
snprintf(ret_path, MAXPGPATH, "%s/%s", path, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* relative_path
|
* relative_path
|
||||||
@ -391,7 +399,10 @@ trim_trailing_separator(char *path)
|
|||||||
char *p = path + strlen(path);
|
char *p = path + strlen(path);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
/* Skip over network and drive specifiers for win32 */
|
/*
|
||||||
|
* Skip over network and drive specifiers for win32.
|
||||||
|
* Set 'path' to point to the last character to keep.
|
||||||
|
*/
|
||||||
if (strlen(path) >= 2)
|
if (strlen(path) >= 2)
|
||||||
{
|
{
|
||||||
if (IS_DIR_SEP(path[0]) && IS_DIR_SEP(path[1]))
|
if (IS_DIR_SEP(path[0]) && IS_DIR_SEP(path[1]))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user