Bugzilla – Bug 476026
POSIX function getlogin() returns null for an existing user
Last modified: 2010-01-19 02:03:24 UTC
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6) Gecko/2009012700 SUSE/3.0.6-0.1.2 Firefox/3.0.6 In C the posix function getlogin() is returning null. perror is saying something about 'file not found' Reproducible: Always Steps to Reproduce: here is code to reproduce the problem: #include <unistd.h> #include <stdio.h> int main() { char* login = getlogin(); if (login != NULL) { printf("login not null [login=%s]\n", login); } else { perror("getlogin failed"); } return 0; } Actual Results: null Expected Results: my username
this may or may not be related, but I just noticed the "logname" command returns "logname: no login name"
The POSIX standard says: Upon successful completion, getlogin ( ) shall return a pointer to the login name or a null pointer if the user’s login name cannot be found. Otherwise, it shall return a null pointer and set errno to indicate the error. So the result of the getlogin call is correct. The question is, why getlogin can't find your login name. What is the output of calling id?
the output from running 'id' on the command line: qbproger@linux-3r1v:~> id uid=1000(qbproger) gid=100(users) groups=16(dialout),33(video),100(users)
I'm sorry I couldn't get to this bug earlier due to my workload. Does this still happen to you? Can you please try to strace your program and post the output?
I'm on ubuntu now (but plan on moving back to openSuSE now that 11.2 is out), and the computer that had the problem doesn't work anymore. When I switch back to opensuse (within 2 or 3 weeks), I can test it again, but it is different hardware.
Thank you for your time anyway, please reopen if you will still want to investigate the issue.