Initdb for Postgres failing with misleading error message when build on a remote system

StackOverflow https://stackoverflow.com/questions/18832624

  •  28-06-2022
  •  | 
  •  

Question

I have a build of PostgreSQL's Initdb utility that was compiled and linked on a remote build server running Fedora. On my system (Ubuntu 13.04 64-bit) when the utility is run using the command initdb -D /home/me/postgres_files/ -L /home/me/postgres_init_files/ the following is returned:

initdb: could not obtain information about current user: Success

This does not occur if I build the utility locally, only with a remote build from our build farm. I have so far managed to track the issue down to the following piece of code in initdb.c:

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

It would seem that either the call to geteuid() or getpwuid() is failing, but errno is not being set by the failing function. Unfortunately I can't easily go in and debug the utility directly as this only occurs on a remotely build version of the utility!

I would be greatly appreciative if anyone could shed some light on this.

Thanks.

Was it helpful?

Solution

Referring the "inconsistent" error message:

If getpwuid() returns NULL, this not necessarilly needs to inidicate an error.

From man getpwuid (italic emphasis by me):

The getpwuid() function returns a pointer to a structure containing the broken-out fields of the record in the password database that matches the user ID uid.

[...]

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.

From the fact that errno seems to be 0 anf those two statments above I'd conclude that the result of geteuid() simply could not be found by getpwuid().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top