Skip to content

Commit c7007d1

Browse files
committed
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.
1 parent e845adf commit c7007d1

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/bin/initdb/initdb.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* Portions Copyright (c) 1994, Regents of the University of California
4444
* Portions taken from FreeBSD.
4545
*
46-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.23 2004/03/09 04:49:02 momjian Exp $
46+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.24 2004/05/05 16:09:31 tgl Exp $
4747
*
4848
*-------------------------------------------------------------------------
4949
*/
@@ -263,6 +263,24 @@ xstrdup(const char *s)
263263
return result;
264264
}
265265

266+
/*
267+
* unsetenv() doesn't exist everywhere, so emulate it with this ugly
268+
* but well-tested technique (borrowed from backend's variable.c).
269+
*/
270+
static void
271+
pg_unsetenv(const char *varname)
272+
{
273+
char *envstr = xmalloc(strlen(varname) + 2);
274+
275+
/* First, override any existing setting by forcibly defining the var */
276+
sprintf(envstr, "%s=", varname);
277+
putenv(envstr);
278+
279+
/* Now we can clobber the variable definition this way: */
280+
strcpy(envstr, "=");
281+
putenv(envstr);
282+
}
283+
266284
/*
267285
* delete a directory tree recursively
268286
* assumes path points to a valid directory
@@ -1242,7 +1260,10 @@ bootstrap_template1(char *short_version)
12421260
snprintf(cmd, sizeof(cmd), "LC_CTYPE=%s", lc_ctype);
12431261
putenv(xstrdup(cmd));
12441262

1245-
putenv("LC_ALL");
1263+
pg_unsetenv("LC_ALL");
1264+
1265+
/* Also ensure backend isn't confused by this environment var: */
1266+
pg_unsetenv("PGCLIENTENCODING");
12461267

12471268
snprintf(cmd, sizeof(cmd),
12481269
"\"%s/postgres\" -boot -x1 %s %s template1",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy