Let's start using setenv()
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2020-12-29T03:20:51Z
Lists: pgsql-hackers
Attachments
- support-using-setenv-1.patch (text/x-diff) patch
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
Commits
-
Use setenv() in preference to putenv().
- 7ca37fb0406b 14.0 landed