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

From Tom Lane
Subject Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd
Date
Msg-id 296.1367950228@sss.pgh.pa.us
Whole thread Raw
In response to BUG #8139: initdb: Misleading error message when current user not in /etc/passwd  (nicolas@marchildon.net)
Responses Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-bugs
nicolas@marchildon.net writes:
> "initdb: could not obtain information about current user: Success"

> The misleading part is the "Success". This comes from errno:

>         pw = getpwuid(geteuid());
>         if (!pw)
>         {
>                 fprintf(stderr,
>                           _("%s: could not obtain information about current
> user: %s\n"),
>                                 progname, strerror(errno));
>                 exit(1);
>         }

> The man page says:

> RETURN VALUE
>        The  getpwnam()  and  getpwuid() functions return a pointer to a
> passwd
>        structure, or NULL if the matching entry  is  not  found  or  an
> error
>        occurs.   If an error occurs, errno is set appropriately.  If one
> wants
>        to check errno after the call, it should be  set  to  zero  before
> the
>        call.

AFAICS, getpwuid is not honoring its specification here: it failed to
set errno.  I don't see that suppressing the strerror result would add
anything much.

            regards, tom lane

pgsql-bugs by date:

Previous
From: nicolas@marchildon.net
Date:
Subject: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd
Next
From: Alvaro Herrera
Date:
Subject: Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd