Subject: bug#76876: closed (Re: bug#76876: logname output is often wrong when linked with glibc)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 09 Mar 2025 12:50:02 +0000

Your bug report

#76876: logname output is often wrong when linked with glibc

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
76876: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76876
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#76876: logname output is often wrong when linked with glibc
From: Pádraig Brady <[email-masked]>
To: Bruno Haible <[email-masked]>, Nicolas Boos <[email-masked]>, [email-masked], Paul Eggert <[email-masked]>
Cc: [email-masked]
Date: Sun, 9 Mar 2025 12:48:49 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

On 09/03/2025 11:08, Bruno Haible via Gnulib discussion list wrote:
> I wrote:
>> With this, coreutils should be fine, since it already imports the 'getlogin'
>> module from gnulib.
> 
> Verified by comparing coreutils-9.5 with coreutils-HEAD on Alpine Linux 3.20:
> 
> With coreutils-9.5:
> 
> $ logname
> bruno
> $ su -
> Password:
> # logname
> root
> 
> Now:
> 
> $ logname
> bruno
> $ su -
> Password:
> # logname
> bruno
> 
> Paul, Pádraig: How about adding a coreutils/NEWS entry for this bug fix?

I pushed an update to coreutils NEWS mentioning the fix.
Marking this as done.

thanks!
Pádraig.

Subject: logname output is often wrong when linked with glibc
From: Nicolas Boos <[email-masked]>
To: [email-masked]
Date: Sat, 8 Mar 2025 17:46:22 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

First test case with logname 9.1 and glibc 2.36:
$ echo $LOGNAME
nicolas
$ logname
nicolas
$ su --login root
$ echo $LOGNAME
root
$ logname
nicolas
$ logname (musl)
root
$ logname (uclibc)
root

Second test case, with a minimal chroot, no /proc and busybox login:
$ echo $LOGNAME
nicolas
$ logname
logname: no login name
$ busybox logname
logname: getlogin: No such file or directory
$ logname (musl)
nicolas
$ logname (uclibc)
nicolas

It seems getlogin() is malfunctioning only with glibc.

The following patch with "equivalent code" fixes the issue:
--- logname.c.orig
+++ logname.c
@@ -71,7 +71,11 @@
 
   /* POSIX requires using getlogin (or equivalent code) and prohibits
      using a fallback technique.  */
-  cp = getlogin ();
+  #if __GLIBC__
+    cp = getenv ("LOGNAME");
+  #else
+    cp = getlogin ();
+  #endif
   if (! cp)
     error (EXIT_FAILURE, 0, _("no login name"));

Adding a permanent fix to gnulib/getlogin.c code might be a better solution.

NB