thread-safety: getpwuid_r()

Peter Eisentraut <peter@eisentraut.org>

From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2024-08-24T08:42:53Z
Lists: pgsql-hackers

Attachments

Here is a patch to replace a getpwuid() call in the backend, for 
thread-safety.

This is AFAICT the only call in the getpw*() family that needs to be 
dealt with.

(There is also a getgrnam() call, but that is called very early in the 
postmaster, before multiprocessing, so we can leave that as is.)

The solution here is actually quite attractive: We can replace the 
getpwuid() call by the existing wrapper function pg_get_user_name(), 
which internally uses getpwuid_r().  This also makes the code a bit 
simpler.  The same function is already used in libpq for a purpose that 
mirrors the backend use, so it's also nicer to use the same function for 
consistency.

Commits

  1. More use of getpwuid_r() directly