Prefer $HOME when looking up the current user's home directory.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 10 Jan 2022 00:19:02 +0000 (19:19 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 10 Jan 2022 00:19:02 +0000 (19:19 -0500)
commit376ce3e404b75d267089c4bc6dc7c18d0b38728b
tree197a5ab6a9a66e7ada4fd1d027e1e5e5147c717a
parent6867f963e319934cbdafeb4bd5beaea5797c7be2
Prefer $HOME when looking up the current user's home directory.

When we need to identify the home directory on non-Windows, first
consult getenv("HOME").  If that's empty or unset, fall back
on our previous method of checking the <pwd.h> database.

Preferring $HOME allows the user to intentionally point at some
other directory, and it seems to be in line with the behavior of
most other utilities.  However, we shouldn't rely on it completely,
as $HOME is likely to be unset when running as a daemon.

Anders Kaseorg

Discussion: https://postgr.es/m/1634252654444.90107@mit.edu
src/bin/psql/command.c
src/interfaces/libpq/fe-connect.c
src/port/path.c