pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Use setenv() in preference to putenv().
Date: Wed, 30 Dec 2020 17:56:34 +0000
Message-ID: <E1kufi6-0003CB-4N@gemulon.postgresql.org> (raw)

Use setenv() in preference to putenv().

Since at least 2001 we've used putenv() and avoided setenv(), on the
grounds that the latter was unportable and not in POSIX.  However,
POSIX added it that same year, and by now the situation has reversed:
setenv() is probably more portable than putenv(), since POSIX now
treats the latter as not being a core function.  And setenv() has
cleaner semantics too.  So, let's reverse that old policy.

This commit adds a simple src/port/ implementation of setenv() for
any stragglers (we have one in the buildfarm, but I'd not be surprised
if that code is never used in the field).  More importantly, extend
win32env.c to also support setenv().  Then, replace usages of putenv()
with setenv(), and get rid of some ad-hoc implementations of setenv()
wannabees.

Also, adjust our src/port/ implementation of unsetenv() to follow the
POSIX spec that it returns an error indicator, rather than returning
void as per the ancient BSD convention.  I don't feel a need to make
all the call sites check for errors, but the portability stub ought
to match real-world practice.

Discussion: https://postgr.es/m/2065122.1609212051@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7ca37fb0406bc2cbbd864a2ffdbdb4479e338c0c

Modified Files
--------------
configure                                  | 19 ++++++++++-
configure.ac                               |  4 ++-
contrib/dblink/input/paths.source          |  6 ++--
contrib/dblink/output/paths.source         |  6 ++--
src/backend/utils/adt/pg_locale.c          | 31 ++---------------
src/bin/initdb/initdb.c                    | 10 +++---
src/bin/pg_ctl/pg_ctl.c                    | 12 +++----
src/bin/pg_upgrade/controldata.c           | 54 +++++++++++++++++++-----------
src/bin/pg_upgrade/option.c                |  6 ++--
src/bin/pg_upgrade/pg_upgrade.h            |  1 -
src/bin/pg_upgrade/util.c                  | 36 --------------------
src/bin/psql/command.c                     | 11 +-----
src/common/exec.c                          | 22 ++----------
src/common/restricted_token.c              |  2 +-
src/include/pg_config.h.in                 |  3 ++
src/include/port.h                         |  6 +++-
src/include/port/win32_port.h              | 10 +++---
src/interfaces/ecpg/test/pg_regress_ecpg.c |  6 ++--
src/port/setenv.c                          | 48 ++++++++++++++++++++++++++
src/port/unsetenv.c                        | 18 +++++++---
src/port/win32env.c                        | 50 +++++++++++++++++++++++----
src/test/isolation/isolation_main.c        |  6 ++--
src/test/regress/pg_regress.c              | 45 ++++++++++---------------
src/test/regress/pg_regress_main.c         |  6 ++--
src/test/regress/regress.c                 | 14 +++-----
src/tools/msvc/Solution.pm                 |  1 +
26 files changed, 234 insertions(+), 199 deletions(-)



view thread (3+ messages)  latest in thread

Message-ID: <E1kufi6-0003CB-4N@gemulon.postgresql.org>
Permalink:  ../E1kufi6-0003CB-4N@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kufi6-0003CB-4N@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Use setenv() in preference to putenv().
  In-Reply-To: <E1kufi6-0003CB-4N@gemulon.postgresql.org>
  References: <E1kufi6-0003CB-4N@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox