diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-05-05 16:09:31 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-05-05 16:09:31 +0000 |
commit | c7007d1848901265b9c6726e8d00543b20c9214e (patch) | |
tree | 5a2393dc601d0e4cce0918ccfafa6465edd13671 | |
parent | e845adf31f8f82cf3245f4c20b4a5d8ac4edfef0 (diff) | |
download | postgresql-c7007d1848901265b9c6726e8d00543b20c9214e.tar.gz postgresql-c7007d1848901265b9c6726e8d00543b20c9214e.zip |
Use a more portable technique for unsetting environment variables,
and unset PGCLIENTENCODING to prevent backend from dying if it's set
to something incompatible with the -E option.
-rw-r--r-- | src/bin/initdb/initdb.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index cb44f7d0ad3..1d39cbb89ea 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -43,7 +43,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * Portions taken from FreeBSD. * - * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.23 2004/03/09 04:49:02 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.24 2004/05/05 16:09:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -264,6 +264,24 @@ xstrdup(const char *s) } /* + * unsetenv() doesn't exist everywhere, so emulate it with this ugly + * but well-tested technique (borrowed from backend's variable.c). + */ +static void +pg_unsetenv(const char *varname) +{ + char *envstr = xmalloc(strlen(varname) + 2); + + /* First, override any existing setting by forcibly defining the var */ + sprintf(envstr, "%s=", varname); + putenv(envstr); + + /* Now we can clobber the variable definition this way: */ + strcpy(envstr, "="); + putenv(envstr); +} + +/* * delete a directory tree recursively * assumes path points to a valid directory * deletes everything under path @@ -1242,7 +1260,10 @@ bootstrap_template1(char *short_version) snprintf(cmd, sizeof(cmd), "LC_CTYPE=%s", lc_ctype); putenv(xstrdup(cmd)); - putenv("LC_ALL"); + pg_unsetenv("LC_ALL"); + + /* Also ensure backend isn't confused by this environment var: */ + pg_unsetenv("PGCLIENTENCODING"); snprintf(cmd, sizeof(cmd), "\"%s/postgres\" -boot -x1 %s %s template1", |