I wrote:
> The same failure also occurs on Arch Linux 24.04.
> Reproducible as
>   $ unshare -U src/logname
>   bruno
> Both of these distros use glibc version 2.39.

Here are the results of "unshare -U logname" in various distros with
various glibc versions:

glibc   Distro       GUI/Console   unshare -U logname        unshare -U logname 
< /dev/null
                 (KDE/GNOME/Mate/LXQt/Pantheon)

2.24    ubuntu1704              K  bruno                     logname: no login 
name
2.26    Fedora27                G  logname: no login name
2.26    opensuse152             K  bruno                     logname: no login 
name
2.26    ubuntu1710              K  bruno                     logname: no login 
name
2.27    ElementaryOS50          P  logname: no login name
2.27    ubuntu1804              K  bruno                     logname: no login 
name
2.28    centos8-64              G  logname: no login name
2.30    arch1911                C  logname: no login name
2.31    opensuse155             K  logname: no login name
2.32    ubuntu2010              K  logname: no login name
2.33    slackware15             C  logname: no login name
2.33    guix14                  M  logname: no login name
2.34    alma9                   G  logname: no login name
2.34    centos9                 G  logname: no login name
2.34    ubuntu2110              K  logname: no login name
2.35    ubuntu2204              K  logname: no login name
2.35    popos2204               G  logname: no login name
2.36    Fedora37                G  logname: no login name
2.36    ubuntu2210              K  logname: no login name
2.36    debian12                G  logname: no login name
2.37    ubuntu2304              K  logname: no login name
2.38    ubuntu2310              K  logname: no login name
2.38    openeuler2403           C  bruno                     logname: no login 
name
2.39    arch2404                C  bruno                     logname: no login 
name
2.39    manjaro23               K  bruno                     logname: no login 
name
2.39    ubuntu2404              K  logname: no login name
2.39    openmandriva50          K  bruno                     logname: no login 
name
2.39    alma10                  G  logname: no login name
2.40    openmamba               L  logname: no login name
2.40    opensuse160             K  logname: no login name
2.41    Fedora42                K  bruno                     logname: no login 
name
2.41    ubuntu2504              G  logname: no login name
2.42    Fedora43                C  bruno                     logname: no login 
name

In summary:
1) The problem of "unshare -U logname" returning the previous user name
   existed in glibc < 2.28 and starts again in glibc 2.38.
2) 'strace' shows that glibc determines this previous user name by
   resolving the /proc/self/fd/0 link to a tty, then doing some lookup
   in the utmp / utmpx database.
3) Therefore "unshare -U logname </dev/null" provides a workaround.
4) The difference between distros (openeuler, arch, manjaro, openmandriva,
   Fedora on one side, Ubuntu, openSUSE, RHEL, openmamba on the other side)
   in glibc >= 2.38 is probably due to differences in the utmp / utmpx lookup.
   I cannot find glibc patches regarding getlogin in Fedora nor Ubuntu.

> > If so, perhaps our replacement is falling back to a method that works.
> 
> It could be related to this glibc bug from 2023:
> https://sourceware.org/bugzilla/show_bug.cgi?id=30235
> https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=0d83b349fa7340475406b2fe933c7467e4584091

Indeed:
The change between glibc 2.27 and 2.28
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=cc8a1620eb97ccddd337d157263c13c57b39ab71
unintentionally broke the old behaviour, and
the change between glibc 2.37 and 2.38
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=0d83b349fa7340475406b2fe933c7467e4584091
restored it.

> > I'll comment out the problematic part of the test for now.

The attached proposed patch restores the test in a way that succeeds.
Tested on Manjaro 23.

>From 8a1d0541e9f437c52f9919ed10d20314b50a6f65 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Fri, 17 Apr 2026 15:46:19 +0200
Subject: [PATCH] tests: Reenable test that was disabled yesterday

* tests/misc/user.sh: Modify the "unshare -U logname" test, so that it
does not fail on glibc versions (< 2.28, >= 2.38) that do a fallback
lookup based on the tty.
---
 tests/misc/user.sh | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tests/misc/user.sh b/tests/misc/user.sh
index 8385d1058..931287e41 100755
--- a/tests/misc/user.sh
+++ b/tests/misc/user.sh
@@ -25,8 +25,9 @@ overflow_uid=$(cat /proc/sys/kernel/overflowuid) ||
 
 test "$(unshare -U whoami)" = "$(id -un $overflow_uid)" || fail=1
 
-# FIXME: Fails with Manjaro Linux
-#returns_ 1 unshare -U logname 2>err || fail=1
-#test "$(cat err)" = "logname: no login name" || fail=1
+# The "</dev/null" disables a fallback lookup via utmp/utmpx,
+# that existed in glibc < 2.28 and exists again in glibc >= 2.38.
+returns_ 1 unshare -U logname </dev/null 2>err || fail=1
+test "$(cat err)" = "logname: no login name" || fail=1
 
 Exit $fail
-- 
2.52.0

Reply via email to