Let's start using setenv()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Let's start using setenv()
Date: 2020-12-29 03:20:51
Message-ID: 2065122.1609212051@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Back in 2001 we decided to prefer putenv() over setenv() because the
latter wasn't in POSIX (SUSv2) at the time. That decision has been
overtaken by events: more recent editions of POSIX not only provide
setenv() but recommend it over putenv(). So I think it's time to
change our policy and prefer setenv(). We've had previous discussions
about that but nobody did the legwork yet.

The attached patch provides the infrastructure to allow using setenv().
I added a src/port/ implementation of setenv() for any machines that
haven't caught up with POSIX lately. (I've tested that code on my old
dinosaur gaur, and I would not be surprised if that is the only machine
anywhere that ever runs it. But I could be wrong.) I also extended
win32env.c to support setenv().

I haven't made any serious effort to expunge all uses of putenv() in this
version of the patch; I just wanted to exercise setenv() in both backend
and frontend. Seeing that POSIX considers putenv() to be semi-deprecated,
maybe we should try to eliminate all calls outside the (un)setenv
implementations, but first it'd be good to see if win32env.c works.

I also changed our unsetenv() emulations to make them return an int
error indicator, as per POSIX. I have no desire to change the call
sites to check for errors, but it seemed like our compatibility stubs
should be compatible with the spec. (Note: I think that unsetenv()
did return void in old BSD versions, before POSIX standardized it.
So that might be a real reason not to change the callers.)

regards, tom lane

Attachment Content-Type Size
support-using-setenv-1.patch text/x-diff 13.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2020-12-29 04:32:26 Re: Let's start using setenv()
Previous Message Thomas Munro 2020-12-29 02:28:12 Re: Parallel Full Hash Join