Re: [PATCH] Prefer getenv("HOME") to find the UNIX home directory
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Anders Kaseorg <andersk@mit.edu>
Cc: Daniel Gustafsson <daniel@yesql.se>,
Kyotaro Horiguchi <horikyota.ntt@gmail.com>, alvherre@alvh.no-ip.org,
pgsql-hackers@lists.postgresql.org
Date: 2022-01-09T18:59:02Z
Lists: pgsql-hackers
Attachments
- v2-0001-use-HOME-for-home-directory.patch (text/x-diff) patch v2-0001
Anders Kaseorg <andersk@mit.edu> writes: > On 10/20/21 04:55, Daniel Gustafsson wrote: >> Is the proposed change portable across all linux/unix systems we support? >> Reading aobut indicates that it's likely to be, but neither NetBSD nor FreeBSD >> have the upthread referenced wording in their manpages. > Since the proposed change falls back to the old behavior if HOME is > unset or empty, I assume this is a question about convention and not > literally about whether it will work on these systems. I don’t find it > surprising that this convention isn’t explicitly called out in every > system’s manpage for the wrong function, but it still applies to these > systems. Given the POSIX requirements, it's basically impossible to believe that there are interesting cases where $HOME isn't set. Thus, it seems to me that keeping the getpwuid calls will just mean carrying untestable dead code, so we should simplify matters by ripping those out and *only* consulting $HOME. The v1 patch also neglects the matter of documentation. I think the simplest and most transparent thing to do is just to explicitly mention $HOME everyplace we talk about files that are sought there, in place of our current convention to write "~". (I'm too lazy to go digging in the git history, but I have a feeling that this is undoing somebody's intentional change from a long time back.) BTW, not directly impacted by this patch but adjacent to it, I noted that on Windows psql's \cd defaults to changing to "/". That seems a bit surprising, and we definitely fail to document it. I settled for noting it in the documentation, but should we make it do something else? PFA v2 patch. regards, tom lane
Commits
-
Clean up messy API for src/port/thread.c.
- 98e93a1fc93e 15.0 landed
-
Prefer $HOME when looking up the current user's home directory.
- 376ce3e404b7 15.0 landed