|From:||Anders Kaseorg <andersk(at)mit(dot)edu>|
|Subject:||[PATCH] Prefer getenv("HOME") to find the UNIX home directory|
|Views:||Raw Message | Whole Thread | Download mbox | Resend email|
According to getpwnam(3):
An application that wants to determine its user's home directory
should inspect the value of HOME (rather than the value
getpwuid(getuid())->pw_dir) since this allows the user to modify
their notion of "the home directory" during a login session.
This is important for systems where many users share the same UID, and for test systems that change HOME to avoid interference with the user’s real home directory. It matches what most applications do, as well as what glibc does for glob("~", GLOB_TILDE, …) and wordexp("~", …).
There was some previous discussion of this in 2016, where although there were some questions about the use case, there seemed to be general support for the concept:
Regardless of whether one thinks modifying HOME is a good idea, if we happen to find ourselves in that case, we should respect the modified HOME, so that when the user creates (say) a ~/.pgpass file, we’ll look for it at the same place the user’s editor created it. getenv() also skips the overhead of reading /etc/passwd as an added bonus.
The way I ran into this issue myself was in a test suite that runs on GitHub Actions, which automatically sets HOME=/github/home.
|Next Message||Tom Lane||2021-10-14 23:04:27||Re: [RFC] building postgres with meson|
|Previous Message||Andres Freund||2021-10-14 22:55:09||Re: [RFC] building postgres with meson|