Commit 68708433 authored by Bruce Momjian's avatar Bruce Momjian

Add PGETC (for pg_service.conf) and PGLOCALE (for locale dir)

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.
parent 70f5a87e
<!--
$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">
......@@ -3582,6 +3582,24 @@ sets the default mode for the genetic query optimizer.
(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>
......
......@@ -13,7 +13,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -152,7 +152,7 @@ main(int argc, char *argv[])
* allow startup error messages to be localized.
*/
set_pglocale(argv[0], "postgres");
set_pglocale_pgservice(argv[0], "postgres");
#ifdef WIN32
......
......@@ -39,7 +39,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -1788,7 +1788,7 @@ main(int argc, char *argv[])
{"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)
{
......
......@@ -6,7 +6,7 @@
* 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"
......@@ -77,7 +77,7 @@ main(int argc, char *argv[])
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]);
......
......@@ -4,7 +4,7 @@
*
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -824,7 +824,7 @@ main(int argc, char **argv)
#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
......
......@@ -12,7 +12,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -242,7 +242,7 @@ main(int argc, char **argv)
};
int optindex;
set_pglocale(argv[0], "pg_dump");
set_pglocale_pgservice(argv[0], "pg_dump");
g_verbose = false;
......
......@@ -6,7 +6,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -101,7 +101,7 @@ main(int argc, char *argv[])
int optindex;
set_pglocale(argv[0], "pg_dump");
set_pglocale_pgservice(argv[0], "pg_dump");
progname = get_progname(argv[0]);
......
......@@ -34,7 +34,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -121,7 +121,7 @@ main(int argc, char **argv)
{NULL, 0, NULL, 0}
};
set_pglocale(argv[0], "pg_dump");
set_pglocale_pgservice(argv[0], "pg_dump");
opts = NewRestoreOptions();
......
......@@ -23,7 +23,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -102,7 +102,7 @@ main(int argc, char *argv[])
int fd;
char path[MAXPGPATH];
set_pglocale(argv[0], "pg_resetxlog");
set_pglocale_pgservice(argv[0], "pg_resetxlog");
progname = get_progname(argv[0]);
......
......@@ -3,7 +3,7 @@
*
* 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"
......@@ -102,7 +102,7 @@ main(int argc, char *argv[])
char *password = NULL;
bool need_pass;
set_pglocale(argv[0], "psql");
set_pglocale_pgservice(argv[0], "psql");
pset.progname = get_progname(argv[0]);
......
......@@ -4,7 +4,7 @@
*
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -58,7 +58,7 @@ main(int argc, char *argv[])
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);
......
......@@ -5,7 +5,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -60,7 +60,7 @@ main(int argc, char *argv[])
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);
......
......@@ -5,7 +5,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -61,7 +61,7 @@ main(int argc, char *argv[])
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);
......
......@@ -5,7 +5,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -63,7 +63,7 @@ main(int argc, char *argv[])
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);
......
......@@ -5,7 +5,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -51,7 +51,7 @@ main(int argc, char *argv[])
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);
......
......@@ -5,7 +5,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -61,7 +61,7 @@ main(int argc, char *argv[])
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);
......
......@@ -5,7 +5,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -51,7 +51,7 @@ main(int argc, char *argv[])
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);
......
......@@ -5,7 +5,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -66,7 +66,7 @@ main(int argc, char *argv[])
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);
......
......@@ -6,7 +6,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -32,7 +32,7 @@ extern void get_include_path(const char *my_exec_path, char *ret_path);
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
......
......@@ -8,7 +8,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -2363,17 +2363,13 @@ pqPacketSend(PGconn *conn, char pack_type,
#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;
......@@ -2386,6 +2382,13 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
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;
......
......@@ -23,7 +23,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -1132,7 +1132,7 @@ libpq_gettext(const char *msgid)
{
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);
......
......@@ -8,7 +8,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -222,32 +222,47 @@ get_locale_path(const char *my_exec_path, char *ret_path)
/*
* 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);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment