Обсуждение: pgsql: Use setenv() in preference to putenv().

Поиск
Список
Период
Сортировка

pgsql: Use setenv() in preference to putenv().

От
Tom Lane
Дата:
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(-)


Re: pgsql: Use setenv() in preference to putenv().

От
Alexander Korotkov
Дата:
Hi!

On Wed, Dec 30, 2020 at 8:56 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Use setenv() in preference to putenv().

Recent buildfarm failure on crake seems to be related to this commit.
https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=crake&dt=2020-12-31%2001%3A34%3A28

pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 193; 1255 50888 FUNCTION putenv("text") buildfarm
pg_restore: error: could not execute query: ERROR:  could not find
function "regress_putenv" in file
"/home/andrew/bf/root/saves.crake/HEAD/lib/postgresql/regress.so"
Command was: CREATE FUNCTION "public"."putenv"("text") RETURNS "void"
    LANGUAGE "c" STRICT
    AS '$libdir/regress.so', 'regress_putenv';

------
Regards,
Alexander Korotkov



Re: pgsql: Use setenv() in preference to putenv().

От
Tom Lane
Дата:
Alexander Korotkov <aekorotkov@gmail.com> writes:
> On Wed, Dec 30, 2020 at 8:56 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Use setenv() in preference to putenv().

> Recent buildfarm failure on crake seems to be related to this commit.

Yeah, see

https://www.postgresql.org/message-id/flat/2403475.1609360967%40sss.pgh.pa.us

            regards, tom lane