I wrote: > Thus, on Linux systems, a correct implementation of getlogin() can not > distinguish different users with the same uid (with reasonable effort). > This applies to both glibc and the new code in gnulib.
Let me document this limitation. 2025-03-10 Bruno Haible <br...@clisp.org> getlogin, getlogin_r: Document limitation. Reported by Nicolas Boos <nicolas.b...@wanadoo.fr> in <https://lists.gnu.org/archive/html/bug-gnulib/2025-03/msg00033.html>. * doc/posix-functions/getlogin.texi: Mention the "different user names with same uid" limitation. * doc/posix-functions/getlogin_r.texi: Likewise. diff --git a/doc/posix-functions/getlogin.texi b/doc/posix-functions/getlogin.texi index 0ccce336ce..b0b8da73ae 100644 --- a/doc/posix-functions/getlogin.texi +++ b/doc/posix-functions/getlogin.texi @@ -16,7 +16,8 @@ This function is not declared unless @code{_POSIX} is defined on some platforms: mingw. @item -This function returns the value of the @env{LOGNAME} environment variable: +This function returns the value of the @env{LOGNAME} environment variable +and this therefore arbitrarily fakeable: musl libc 1.2.5. @end itemize @@ -26,4 +27,9 @@ This function returns an empty string even when standard input is a tty on some platforms: HP-UX 11.11. +@item +When there are several user names with the same user ID, +this function may return, instead of the user name that logged in, +another user name that has the same user ID, on some platforms: +Linux and others. @end itemize diff --git a/doc/posix-functions/getlogin_r.texi b/doc/posix-functions/getlogin_r.texi index df145ecfe2..0e3b7968db 100644 --- a/doc/posix-functions/getlogin_r.texi +++ b/doc/posix-functions/getlogin_r.texi @@ -21,7 +21,8 @@ @code{ERANGE}, when the buffer is not large enough, on some platforms: macOS 14. @item -This function returns the value of the @env{LOGNAME} environment variable: +This function returns the value of the @env{LOGNAME} environment variable +and this therefore arbitrarily fakeable: musl libc 1.2.5. @end itemize @@ -42,4 +43,9 @@ some platforms: @c https://dev.haiku-os.org/ticket/18349 Haiku. +@item +When there are several user names with the same user ID, +this function may return, instead of the user name that logged in, +another user name that has the same user ID, on some platforms: +Linux and others. @end itemize