in reply to Re^4: getlogin works on debian but not ubuntu?
in thread getlogin works on debian but not ubuntu?

Works for me even on Ubuntu PP:
mb@dennis ~ $ perl -E'say getlogin' mb mb@dennis ~ $ cat gl.c #include <unistd.h> #include <stdio.h> int main(void) { puts(getlogin()); return 0; } mb@dennis ~ $ gcc gl.c mb@dennis ~ $ ./a.out mb

Replies are listed 'Best First'.
Re^6: getlogin works on debian but not ubuntu?
by bcrowell2 (Friar) on Jan 07, 2013 at 04:23 UTC
    Looks like an OS or library bug.
    $ cat >gl.c #include <unistd.h> #include <stdio.h> int main(void) { puts(getlogin()); return 0; } ---- rintintin ~ $ gcc gl.c ---- rintintin ~ $ ./a.out Segmentation fault (core dumped)
    Maybe it's the same thing as this? https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/1067779
      Maybe it's the same thing as this? https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/1067779
      Strange. My netbook has the very same distribution, my /proc/self/loginuid contains UINT_MAX, but stuff still works. strace tells me that instead of reading /proc/self/loginuid (which on some Linuxes such as my Gentoo doesn't even exist) it checks the /proc/self/fd/0 link to find the terminal the program is running on and then checks /var/run/utmpx or /var/run/utmp for the user logged in on that terminal. The weird thing is that there is no trace of getutent() or something in my glibc's getlogin() implementation. I haven't found whether it gets vendor-patched in somewhere or why else that might be.