Thanks for the investigation. I cannot reproduce the issue, because I don't
know how you build your chroot environment. But anyway, with the details you
gave, I believe the following patch should fix the failure.


2022-06-06  Bruno Haible  <br...@clisp.org>

        getlogin, getlogin_r tests: Avoid test failure in specific environments.
        Reported by Letu Ren <fantasq...@gmail.com> in
        <https://lists.gnu.org/archive/html/bug-gnulib/2022-06/msg00001.html>.
        * modules/getlogin-tests (Depends-on): Add stdbool.
        * modules/getlogin_r-tests (Depends-on): Likewise.
        * tests/test-getlogin.h: Include stdbool.h.
        (test_getlogin_result): On Linux, skip the test if /proc/self/loginuid
        contains "-1".

Thanks for the patch.I back-ported your patch and tested in ArchLinux chroot. It still failed because the type of /proc/self/loginuid is uid_t not string. You can check it through the link to glibc source code in the original mail. I made some changes based on your patch and tested the patch under ArchLinux x86_64 chroot.


* tests/test-getlogin.h (test_getlogin_result):
According to the source code of glibc, the type of /proc/self/loginuid is
uid_t, which is unsigned int.

Signed-off-by: Letu Ren <fantasq...@gmail.com>
---
 tests/test-getlogin.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/test-getlogin.h b/tests/test-getlogin.h
index 3489e3e03..b5ed8b572 100644
--- a/tests/test-getlogin.h
+++ b/tests/test-getlogin.h
@@ -58,9 +58,9 @@ test_getlogin_result (const char *buf, int err)
       FILE *fp = fopen ("/proc/self/loginuid", "r");
       if (fp != NULL)
         {
-          char buf[3];
+          uid_t uid;
           loginuid_undefined =
-            (fread (buf, 1, 3, fp) == 2 && buf[0] == '-' && buf[1] == '1');
+            (fscanf (fp, "%u", &uid) == 1 && uid == (uid_t) -1);
           fclose (fp);
         }
       if (loginuid_undefined)
--
2.36.1

Reply via email to