This is the mail archive of the
mailing list for the glibc project.
Re: NSS error reporting (bug 20532)
On 08/04/2017 03:52 PM, Carlos O'Donell wrote:
> The level of the *_r functions is nss/getXXbyYY_r.c, and I don't see why
> we could not intelligently save and restore errno at that level?
> Given your example it would look like this, and some of this is defensive
> errno saving because we are going to have flawed service modules that
> set errno explicitly.
> * save errno.
> * set errno to zero
> * resolve service to nss_files
> * call nss_files low-level functions: e.g. _nss_files_getpwnam_r (nss_files/files-pwd.c)
> ... and get back NSS_STATUS_TRYAGAIN/ERANGE.
> * Since ERANGE we flag that error has occured
> * if (errno == 0) then restore errno.
How would you pass ERANGE to the caller?
For getpwnam, the sequence could be:
Get back ERANGE error.
Allocate larger buffer.
Call getpwnam_r again.
Get back result.
Return to caller with success.
If the second getpwnam_r saved and restored errno, we'll return ERANGE
(or whatever malloc set) to the caller, not the original errno value.