environment variable processing to libpq.
The patch also adds code to our client apps so we set the environment
variable directly based on our binary location, unless it is already
set. This will allow our applications to emit proper locale messages
that are generated in libpq.
<!--
-$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.155 2004/05/14 18:04:02 neilc Exp $
+$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.156 2004/06/03 00:07:35 momjian Exp $
-->
<chapter id="libpq">
(Equivalent to <literal>SET geqo TO ...</literal>.)
</para>
</listitem>
+<listitem>
+<para>
+<indexterm>
+ <primary><envar>PGETC</envar></primary>
+</indexterm>
+<envar>PGETC</envar>
+sets the directory containing the <filename>pg_service.conf</> file.
+</para>
+</listitem>
+<listitem>
+<para>
+<indexterm>
+ <primary><envar>PGLOCALE</envar></primary>
+</indexterm>
+<envar>PGLOCALE</envar>
+sets the directory containing the <literal>locale</> files.
+</para>
+</listitem>
</itemizedlist>
Refer to the <acronym>SQL</acronym> command <command>SET</command>
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/main/main.c,v 1.85 2004/05/29 22:48:19 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/main/main.c,v 1.86 2004/06/03 00:07:36 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* allow startup error messages to be localized.
*/
- set_pglocale(argv[0], "postgres");
+ set_pglocale_pgservice(argv[0], "postgres");
#ifdef WIN32
* Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD.
*
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.34 2004/06/01 02:53:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.35 2004/06/03 00:07:36 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{"global", "pg_xlog", "pg_clog", "base", "base/1"};
progname = get_progname(argv[0]);
- set_pglocale(argv[0], "initdb");
+ set_pglocale_pgservice(argv[0], "initdb");
if (argc > 1)
{
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
* licence: BSD
*
- * $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.16 2004/05/25 01:00:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.17 2004/06/03 00:07:36 momjian Exp $
*/
#include "postgres.h"
char *strftime_fmt = "%c";
const char *progname;
- set_pglocale(argv[0], "pg_controldata");
+ set_pglocale_pgservice(argv[0], "pg_controldata");
progname = get_progname(argv[0]);
*
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.5 2004/06/01 22:03:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.6 2004/06/03 00:07:36 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#endif
progname = get_progname(argv[0]);
- set_pglocale(argv[0], "pg_ctl");
+ set_pglocale_pgservice(argv[0], "pg_ctl");
/*
* save argv[0] so do_start() can look for the postmaster if
* by PostgreSQL
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.372 2004/05/26 18:24:22 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.373 2004/06/03 00:07:36 momjian Exp $
*
*-------------------------------------------------------------------------
*/
};
int optindex;
- set_pglocale(argv[0], "pg_dump");
+ set_pglocale_pgservice(argv[0], "pg_dump");
g_verbose = false;
* Portions Copyright (c) 1994, Regents of the University of California
*
*
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.35 2004/05/25 01:00:24 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.36 2004/06/03 00:07:36 momjian Exp $
*
*-------------------------------------------------------------------------
*/
int optindex;
- set_pglocale(argv[0], "pg_dump");
+ set_pglocale_pgservice(argv[0], "pg_dump");
progname = get_progname(argv[0]);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.57 2004/05/25 01:00:24 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.58 2004/06/03 00:07:37 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{NULL, 0, NULL, 0}
};
- set_pglocale(argv[0], "pg_dump");
+ set_pglocale_pgservice(argv[0], "pg_dump");
opts = NewRestoreOptions();
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.19 2004/05/25 01:00:25 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.20 2004/06/03 00:07:37 momjian Exp $
*
*-------------------------------------------------------------------------
*/
int fd;
char path[MAXPGPATH];
- set_pglocale(argv[0], "pg_resetxlog");
+ set_pglocale_pgservice(argv[0], "pg_resetxlog");
progname = get_progname(argv[0]);
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.94 2004/05/25 01:00:26 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.95 2004/06/03 00:07:37 momjian Exp $
*/
#include "postgres_fe.h"
char *password = NULL;
bool need_pass;
- set_pglocale(argv[0], "psql");
+ set_pglocale_pgservice(argv[0], "psql");
pset.progname = get_progname(argv[0]);
*
* Portions Copyright (c) 2002-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.8 2004/06/01 02:54:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/clusterdb.c,v 1.9 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
char *table = NULL;
progname = get_progname(argv[0]);
- set_pglocale(argv[0], "pgscripts");
+ set_pglocale_pgservice(argv[0], "pgscripts");
handle_help_version_opts(argc, argv, "clusterdb", help);
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.10 2004/06/01 02:54:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.11 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
PGresult *result;
progname = get_progname(argv[0]);
- set_pglocale(argv[0], "pgscripts");
+ set_pglocale_pgservice(argv[0], "pgscripts");
handle_help_version_opts(argc, argv, "createdb", help);
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/createlang.c,v 1.11 2004/06/01 02:54:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/createlang.c,v 1.12 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
PGresult *result;
progname = get_progname(argv[0]);
- set_pglocale(argv[0], "pgscripts");
+ set_pglocale_pgservice(argv[0], "pgscripts");
handle_help_version_opts(argc, argv, "createlang", help);
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.12 2004/06/01 02:54:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/createuser.c,v 1.13 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
PGresult *result;
progname = get_progname(argv[0]);
- set_pglocale(argv[0], "pgscripts");
+ set_pglocale_pgservice(argv[0], "pgscripts");
handle_help_version_opts(argc, argv, "createuser", help);
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.11 2004/06/01 02:54:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/dropdb.c,v 1.12 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
PGresult *result;
progname = get_progname(argv[0]);
- set_pglocale(argv[0], "pgscripts");
+ set_pglocale_pgservice(argv[0], "pgscripts");
handle_help_version_opts(argc, argv, "dropdb", help);
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/droplang.c,v 1.10 2004/06/01 02:54:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/droplang.c,v 1.11 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
PGresult *result;
progname = get_progname(argv[0]);
- set_pglocale(argv[0], "pgscripts");
+ set_pglocale_pgservice(argv[0], "pgscripts");
handle_help_version_opts(argc, argv, "droplang", help);
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.10 2004/06/01 02:54:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/dropuser.c,v 1.11 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
PGresult *result;
progname = get_progname(argv[0]);
- set_pglocale(argv[0], "pgscripts");
+ set_pglocale_pgservice(argv[0], "pgscripts");
handle_help_version_opts(argc, argv, "dropuser", help);
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.8 2004/06/01 02:54:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/vacuumdb.c,v 1.9 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
bool verbose = false;
progname = get_progname(argv[0]);
- set_pglocale(argv[0], "pgscripts");
+ set_pglocale_pgservice(argv[0], "pgscripts");
handle_help_version_opts(argc, argv, "vacuumdb", help);
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/port.h,v 1.39 2004/05/27 14:39:32 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.40 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
extern void get_pkginclude_path(const char *my_exec_path, char *ret_path);
extern void get_pkglib_path(const char *my_exec_path, char *ret_path);
extern void get_locale_path(const char *my_exec_path, char *ret_path);
-extern void set_pglocale(const char *argv0, const char *app);
+extern void set_pglocale_pgservice(const char *argv0, const char *app);
/*
* is_absolute_path
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.271 2004/05/26 18:35:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.272 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
-#ifndef SYSCONFDIR
-#error "You must compile this file with SYSCONFDIR defined."
-#endif
-
#define MAXBUFSIZE 256
static int
parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
{
char *service = conninfo_getval(options, "service");
- char *serviceFile = SYSCONFDIR "/pg_service.conf";
+ char serviceFile[MAXPGPATH];
bool group_found = false;
int linenr = 0,
i;
if (service == NULL)
service = getenv("PGSERVICE");
+ /*
+ * This could be used by any application so we can't use the binary
+ * location to find our config files.
+ */
+ snprintf(serviceFile, MAXPGPATH, "%s/pg_service.conf",
+ getenv("PGETC") ? getenv("PGETC") : SYSCONFDIR);
+
if (service != NULL)
{
FILE *f;
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.106 2004/05/25 01:00:29 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.107 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
already_bound = 1;
/* No relocatable lookup here because the binary could be anywhere */
- bindtextdomain("libpq", LOCALEDIR);
+ bindtextdomain("libpq", getenv("PGLOCALE") ? getenv("PGLOCALE") : LOCALEDIR);
}
return dgettext("libpq", msgid);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/path.c,v 1.16 2004/05/26 19:00:31 momjian Exp $
+ * $PostgreSQL: pgsql/src/port/path.c,v 1.17 2004/06/03 00:07:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/*
- * set_pglocale
+ * set_pglocale_pgservice
*
- * Set application-specific locale
+ * Set application-specific locale and service directory
*
* This function takes an argv[0] rather than a full path.
*/
void
-set_pglocale(const char *argv0, const char *app)
+set_pglocale_pgservice(const char *argv0, const char *app)
{
-#ifdef ENABLE_NLS
char path[MAXPGPATH];
char my_exec_path[MAXPGPATH];
-#endif
+ char env_path[MAXPGPATH + strlen("PGLOCALE=")]; /* longer than PGETC */
/* don't set LC_ALL in the backend */
if (strcmp(app, "postgres") != 0)
setlocale(LC_ALL, "");
-#ifdef ENABLE_NLS
if (find_my_exec(argv0, my_exec_path) < 0)
return;
+#ifdef ENABLE_NLS
get_locale_path(my_exec_path, path);
bindtextdomain(app, path);
textdomain(app);
+
+ if (!getenv("PGLOCALE"))
+ {
+ /* set for libpq to use */
+ sprintf(env_path, "PGLOCALE=%s", path);
+ putenv(env_path);
+ }
#endif
+
+ if (!getenv("PGETC"))
+ {
+ get_etc_path(my_exec_path, path);
+
+ /* set for libpq to use */
+ sprintf(env_path, "PGETC=%s", path);
+ putenv(env_path);
+ }
}