當前位置:編程學習大全網 - 源碼下載 - 怎麽解決getpwuid_r(): failed due to unknown user id (0)

怎麽解決getpwuid_r(): failed due to unknown user id (0)

這個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文件不能被讀取到 --> 是否這個文件壞掉了或沒有讀取權限?

  • 上一篇:微信群如何進行群裂變?
  • 下一篇:怎麽理解腫瘤指標
  • copyright 2024編程學習大全網