怎么解决getpwuid_r(): failed due to unknown user id (0)
发布网友
发布时间:2022-06-20 19:55
我来回答
共2个回答
热心网友
时间:2024-11-29 19:21
这个glibwarning提示:getpwuid_r()没有取得到user id为0的信息。
先看一下linux man page中getpwuid_r()这个函数的解释:
The getpwnam() function returns a pointer to a structure containing the broken-out fields of the record in the password database (e.g., the local password file /etc/passwd, NIS, and LDAP) that matches the username name.
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 passwd structure is defined in <pwd.h> as follows:
struct passwd {
char *pw_name; /* username */
char *pw_passwd; /* user password */
uid_t pw_uid; /* user ID */
gid_t pw_gid; /* group ID */
char *pw_gecos; /* user information */
char *pw_dir; /* home directory */
char *pw_shell; /* shell program */
};
See passwd(5) for more information about these fields.
The getpwnam_r() and getpwuid_r() functions obtain the same information as getpwnam() and getpwuid(), but store the retrieved passwd structure in the space pointed to by pwd. The string fields pointed to by the members of the passwd structure are stored in the buffer buf of size buflen. A pointer to the result (in case of success) or NULL (in case no entry was found or an error occurred) is stored in *result.
从上面的manual page中可以看到,它是用来获取/etc/passwd文件中当前登录用户的用户信息的。那么我们可以定位这个问题了:
passwd文件中的id(0)的信息没有得到,实际上user id : 0是root用户的id
可能出现这个问题的原因:
<1> passwd文件中没有root用户的信息,如下:
root:x:0:0:root:/root:/bin/bash
<2> passwd文件不能被读取到 --> 是否这个文件坏掉了或没有读取权限?
热心网友
时间:2024-11-29 19:21
跟你一起的bug,我两真背