getlogin() fails on glibc-2.12 and above
Pranav Kuber
pranavkuber@gmail.com
Tue Feb 8 23:03:00 GMT 2011
Hi all,
I am trying to get a simple C program running on RHEL6 x86_64 (gcc
4.4.4) and glibc (v2.12). However, I am getting a Floating Point
Exception (which is very weird for a simple API call into the library
and linking statically).
Here is the exact program -
#include<stdio.h>
#include<unistd.h>
int main(void){
char* name;
name = getlogin();
printf("name = %s\n", name);
return;
}
Compiled using this command -
gcc -static -g getlogintest.c -o getlogintest
This works fine for an older version of glibc (I used v2.3.4). I
debugged a bit and found that the call stack has changed for newer
implementations of glibc. (Earlier getlogin() used to call
ttyname_r(), and now it calls __getlogin_r_loginuid() and so on). I
tried using getlogin_r() too, but fails similarly.
Here is the bt -
(gdb) s
Program received signal SIGFPE, Arithmetic exception.
0x000000304f277d63 in _int_free () from /lib64/libc.so.6
(gdb) bt
#0 0x000000304f277d63 in _int_free () from /lib64/libc.so.6
#1 0x000000304f265e3d in fclose@@GLIBC_2.2.5 () from /lib64/libc.so.6
#2 0x00007ffff7dc9f2a in _nss_files_getpwuid_r () from /lib64/libnss_files.so.2
#3 0x00000000004366fd in getpwuid_r ()
#4 0x000000000040c962 in __getlogin_r_loginuid ()
#5 0x000000000040c673 in getlogin ()
#6 0x0000000000400449 in main () at getlogintest.c:9
Any idea?
Thanks,
-Pranav
More information about the Libc-help
mailing list