From: | Anders Kaseorg <andersk(at)mit(dot)edu> |
---|---|
To: | "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | [PATCH] Prefer getenv("HOME") to find the UNIX home directory |
Date: | 2021-10-14 23:04:14 |
Message-ID: | 1634252654444.90107@mit.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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.
Anders
Attachment | Content-Type | Size |
---|---|---|
v1-0001-Prefer-getenv-HOME-to-find-the-UNIX-home-director.patch | text/x-patch | 3.8 KB |
From | Date | Subject | |
---|---|---|---|
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 |