GNU bug report logs - #76876
logname output is often wrong when linked with glibc

Previous Next

Package: coreutils;

Reported by: Nicolas Boos <nicolas.boos <at> wanadoo.fr>

Date: Sat, 8 Mar 2025 23:08:03 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Nicolas Boos <nicolas.boos <at> wanadoo.fr>
To: bug-coreutils <at> gnu.org
Subject: logname output is often wrong when linked with glibc
Date: Sat, 8 Mar 2025 17:46:22 +0100
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




This bug report was last modified 118 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.