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

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: coreutils; Reported by: Nicolas Boos <nicolas.boos@HIDDEN>; dated Sat, 8 Mar 2025 23:08:03 UTC; Maintainer for coreutils is bug-coreutils@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 8 Mar 2025 23:07:13 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 08 18:07:13 2025
Received: from localhost ([127.0.0.1]:57211 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1tr3GC-0005WN-BZ
	for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 18:07:13 -0500
Received: from lists.gnu.org ([2001:470:142::17]:46920)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <nicolas.boos@HIDDEN>)
 id 1tqxLS-0002k9-8s
 for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 11:48:14 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <nicolas.boos@HIDDEN>)
 id 1tqxLM-00005H-KY
 for bug-coreutils@HIDDEN; Sat, 08 Mar 2025 11:48:08 -0500
Received: from smtp-13.smtpout.orange.fr ([80.12.242.13]
 helo=smtp.smtpout.orange.fr)
 by eggs.gnu.org with esmtps (TLS1.2:RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <nicolas.boos@HIDDEN>)
 id 1tqxLK-00081l-98
 for bug-coreutils@HIDDEN; Sat, 08 Mar 2025 11:48:08 -0500
Received: from unknown ([83.113.165.223]) by smtp.orange.fr with ESMTPSA
 id qxL8tT9qdgqdOqxLCtNoaR; Sat, 08 Mar 2025 17:47:58 +0100
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr;
 s=t20230301; t=1741452478;
 bh=jKq84GpjaN5/xYpH61qdJtOs6ljneegwxSVxRb2QnHc=;
 h=Date:From:To:Subject:Message-ID:MIME-Version;
 b=qXmVsP5PZKPgKXFvquBfxTUi5J8oLCM7n1bdaFijFaXFWw94nXL02yNLDGk2v6xFI
 gXel49JCJfG2K7PhO8GKau2vOZcEYV+zIBz19I2bKdu+U7eRjBAiyP6YiB5MuHhBnk
 l7F2sNKjGyBOuUul2WWvQOnyw8EtuHpMBUHtf4oOUNDh5LilxWtEyhDVrtM+7iXzTp
 NGnPap/eM/spsn0tVOvEajgEvZ1UNnr+KPDeY5LexNFD+Ae1SS0JwTiWwJ5hnhOqzd
 iPqkOPzBTOb1mboZTug8eRU/jvKX1Z226uulRMjFtNpn6T0fCMmL3sinQRs1KqGO1b
 kNFwcMHqdDTng==
X-ME-Helo: unknown
X-ME-Auth: bmljb2xhcy5ib29zQHdhbmFkb28uZnI=
X-ME-Date: Sat, 08 Mar 2025 17:47:58 +0100
X-ME-IP: 83.113.165.223
Date: Sat, 8 Mar 2025 17:46:22 +0100
From: Nicolas Boos <nicolas.boos@HIDDEN>
To: bug-coreutils@HIDDEN
Subject: logname output is often wrong when linked with glibc
Message-ID: <20250308174622.316f583a@unknown>
X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Received-SPF: pass client-ip=80.12.242.13;
 envelope-from=nicolas.boos@HIDDEN; helo=smtp.smtpout.orange.fr
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001,
 RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,
 SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Sat, 08 Mar 2025 18:07:05 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)


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




Acknowledgement sent to Nicolas Boos <nicolas.boos@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-coreutils@HIDDEN. Full text available.
Report forwarded to bug-coreutils@HIDDEN:
bug#76876; Package coreutils. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 8 Mar 2025 23:15:02 UTC

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