diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index 2eaa4da341..be669715c0 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -1,5 +1,5 @@ @@ -3582,6 +3582,24 @@ sets the default mode for the genetic query optimizer. (Equivalent to SET geqo TO ....) + + + + PGETC + +PGETC +sets the directory containing the pg_service.conf file. + + + + + + PGLOCALE + +PGLOCALE +sets the directory containing the locale files. + + Refer to the SQL command SET diff --git a/src/backend/main/main.c b/src/backend/main/main.c index aee2da0731..c9c377e1e9 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -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 diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 3a93931fe2..951d103f57 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -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) { diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c index c7d28d11ee..91abe8cfa7 100644 --- a/src/bin/pg_controldata/pg_controldata.c +++ b/src/bin/pg_controldata/pg_controldata.c @@ -6,7 +6,7 @@ * copyright (c) Oliver Elphick , 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]); diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index f0426dad9b..9b817ea490 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -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 diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index b95aba5e2f..f71abb7da9 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -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; diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 872416b64f..986313846b 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -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]); diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index de44b583d1..9b0dd312da 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -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(); diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c index 6f2ed53161..41b81ea894 100644 --- a/src/bin/pg_resetxlog/pg_resetxlog.c +++ b/src/bin/pg_resetxlog/pg_resetxlog.c @@ -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]); diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 1d45105bd4..e0f55c536d 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -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]); diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index 47eab33661..ca0b46ee24 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -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); diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c index 59bf2ad96b..02acf60f98 100644 --- a/src/bin/scripts/createdb.c +++ b/src/bin/scripts/createdb.c @@ -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); diff --git a/src/bin/scripts/createlang.c b/src/bin/scripts/createlang.c index 4c7a41e4d0..3e3fa762f5 100644 --- a/src/bin/scripts/createlang.c +++ b/src/bin/scripts/createlang.c @@ -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); diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c index 0d6e7bae35..e181d72cad 100644 --- a/src/bin/scripts/createuser.c +++ b/src/bin/scripts/createuser.c @@ -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); diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c index 535285f60f..cfd1031903 100644 --- a/src/bin/scripts/dropdb.c +++ b/src/bin/scripts/dropdb.c @@ -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); diff --git a/src/bin/scripts/droplang.c b/src/bin/scripts/droplang.c index 5e2d8f4459..209ec6d435 100644 --- a/src/bin/scripts/droplang.c +++ b/src/bin/scripts/droplang.c @@ -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); diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c index 6c8bcf4427..f043e15b62 100644 --- a/src/bin/scripts/dropuser.c +++ b/src/bin/scripts/dropuser.c @@ -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); diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index 22dee1df0a..6965c669e1 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -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); diff --git a/src/include/port.h b/src/include/port.h index 907fb20a43..7ee0a138cd 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -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 diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 1cfc6808c5..1e3379ef65 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -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; diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index abf2111a50..1d1a279560 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -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); diff --git a/src/port/path.c b/src/port/path.c index edd4371bc9..1256b09a50 100644 --- a/src/port/path.c +++ b/src/port/path.c @@ -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); + } }