我有一个PostgreSQL的Initdb实用程序的构建,该实用程序已编译并链接到运行Fedora的远程构建服务器上。在我的系统(Ubuntu 13.04 64位)上,使用命令initdb -D /home/me/postgres_files/ -L /home/me/postgres_init_files/
运行实用程序时,将返回以下内容:
initdb: could not obtain information about current user: Success
如果我在本地构建实用程序,而仅从构建服务器场进行远程构建,则不会发生这种情况。到目前为止,我设法将问题归结为
initdb.c
中的以下代码:pw = getpwuid(geteuid());
if (!pw)
{
fprintf(stderr,
_("%s: could not obtain information about current user: %s\n"),
progname, strerror(errno));
exit(1);
}
似乎对geteuid()或getpwuid()的调用都失败了,但是失败的函数未设置errno。不幸的是,我无法轻松进入并直接调试该实用程序,因为这只会在该实用程序的远程生成版本中发生!
如果有人能对此有所启发,我将不胜感激。
谢谢。
最佳答案
引用“不一致”错误消息:
如果getpwuid()
返回NULL
,则不必表示错误。
从man getpwuid
(我的斜体强调):
getpwuid()函数返回一个指向结构的指针,该结构包含密码数据库中与用户ID uid匹配的记录的细分字段。
[...]
getpwnam()和getpwuid()函数返回指向passwd结构的指针,如果找不到匹配的条目或发生错误,则返回NULL。
根据上述两个陈述中errno
似乎是0
的事实,我得出的结论是geteuid()
根本找不到getpwuid()
的结果。