Re: thread-safety: getpwuid_r()

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: thread-safety: getpwuid_r()
Date: 2024-08-26 17:54:13
Message-ID: 564be42e-f77b-4ba7-b726-a241a8e3a6ed@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 26/08/2024 20:38, Peter Eisentraut wrote:
> On 24.08.24 15:55, Heikki Linnakangas wrote:
>> Come to think of it, the pg_get_user_name() function is just a thin
>> wrapper around getpwuid_r(). It doesn't provide a lot of value.
>> Perhaps we should remove pg_get_user_name() and pg_get_user_home_dir()
>> altogether and call getpwuid_r() directly.
>
> Yeah, that seems better.  These functions are somewhat strangely
> designed and as you described have faulty error handling.  By calling
> getpwuid_r() directly, we can handle the errors better and the code
> becomes more transparent.  (There used to be a lot more interesting
> portability complications in that file, but those are long gone.)

New patch looks good to me, thanks!

> I tried to be overly correct by using sysconf(_SC_GETPW_R_SIZE_MAX) to
> get the buffer size, but that doesn't work on FreeBSD.  All the OS where
> I could find the source code internally use 1024 as the suggested buffer
> size, so I just ended up hardcoding that.  This should be no worse than
> what the code is currently handling.

Maybe add a brief comment on that.

--
Heikki Linnakangas
Neon (https://neon.tech)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrei Lepikhov 2024-08-26 18:00:54 Re: allowing extensions to control planner behavior
Previous Message Euler Taveira 2024-08-26 17:47:43 Re: Proposal to have INCLUDE/EXCLUDE options for altering option values