When I login in Linux Suse10 machine and check for getlogin_r() through a C++ program, i get a proper result as my login name.
int main()
{
char szUserName[64] = {0};
int nGet = getlogin_r(szUserName, sizeof(szUserName)-1);
if(0 != nGet)
{
printerr();
}
printf("%s\n", szUserName);
char * szHome = getlogin();
printf("%s\n", szHome);
return 0;
}
But after using the su – name2
i have changed the login now.
But getlogin_r() still shows the older usename.
One solution is the use of geteuid(). But what is the reason of above problem
“after using
su - name2I have changed the login” – No, you haven’t. You’ve changed the user id, not the login.The man page for
susays this about the-option: “Provide an environment similar to what the user would expect had the user logged in directly.” Apparently “similar” is different than “identical to”. Specifically,su -does not store a login record in /var/run/utmp.