Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd - Mailing list pgsql-bugs

From Bruce Momjian
Subject Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd
Date
Msg-id 20131210004630.GD2119@momjian.us
Whole thread Raw
In response to Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
On Mon, Dec  9, 2013 at 04:35:56PM -0500, Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > Updated patch attached, with centralized checking for errno and more
> > consistent behavior for username lookups.
>
> This bit is not good:
>
> +     errno = 0;    /* clear errno before call */
> +     pw = getpwuid(geteuid());
> +     if (!pw)
> +     {
> +         *errstr = psprintf(_("effective user id %d lookup failure: %s"),
> +                 (int) geteuid(), errno ? strerror(errno) :
> +                 _("user does not exist"));
>
> The second call of geteuid() could clobber errno before strerror can see it.
> You should compute geteuid() just once and keep it in a variable.

Good point --- fixed.

> Also, I don't think that error message meets our style guidelines.
> Maybe "failed to look up user id %d: ..." ?

OK, updated.

Updated patch attached to Alvaro's email reply.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

pgsql-bugs by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd
Next
From: Bruce Momjian
Date:
Subject: Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd