bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Test suite failure in clean chroot of ArchLinux


From: Bruno Haible
Subject: Re: Test suite failure in clean chroot of ArchLinux
Date: Mon, 06 Jun 2022 12:18:40 +0200

Hi,

Letu Ren wrote:
> I just rebuilt the coreutils package of ArchLinux and the package
> failed to build due to one failure of the gnulib test suite as
> follows.
> 
> FAIL: test-getlogin
> ===================
> 
> test-getlogin.h:51: assertion '! isatty (0)' failed
> FAIL test-getlogin (exit status: 134)
> 
> There is a bug report in ArchLinux about the same issue which has been
> closed because that issue should be reported to upstream. Ref:
> https://bugs.archlinux.org/task/66506
> 
> I have investigated the cause of this issue. The loginuid in the clean
> chroot when building packages is -1. And getlogin function of glibc
> checks /proc/self/loginuid, if it is -1, then sets errno to ENXIO and
> returns NULL according to
> https://elixir.bootlin.com/glibc/glibc-2.35/source/sysdeps/unix/sysv/linux/getlogin_r.c#L61
> . In tests/test-getlogin.h, test_getlogin_result asserts stdin is not
> a tty, which makes the test fail. I wonder whether we can enhance the
> tests to skip if loginuid is -1.

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  <bruno@clisp.org>

        getlogin, getlogin_r tests: Avoid test failure in specific environments.
        Reported by Letu Ren <fantasquex@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".

diff --git a/tests/test-getlogin.h b/tests/test-getlogin.h
index a11b80e4a3..3489e3e03d 100644
--- a/tests/test-getlogin.h
+++ b/tests/test-getlogin.h
@@ -18,6 +18,7 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -42,11 +43,34 @@ test_getlogin_result (const char *buf, int err)
           exit (77);
         }
 
-      /* It fails when stdin is not connected to a tty.  */
       ASSERT (err == ENOTTY
               || err == EINVAL /* seen on Linux/SPARC */
               || err == ENXIO
              );
+
+#if defined __linux__
+      /* On Linux, it is possible to set up a chroot environment in such a way
+         that stdin is connected to a tty and nervertheless /proc/self/loginuid
+         contains "-1".  In this situation, getlogin() and getlogin_r() fail;
+         this is expected.  */
+      bool loginuid_undefined = false;
+      /* Does the special file /proc/self/loginuid contain "-1"?  */
+      FILE *fp = fopen ("/proc/self/loginuid", "r");
+      if (fp != NULL)
+        {
+          char buf[3];
+          loginuid_undefined =
+            (fread (buf, 1, 3, fp) == 2 && buf[0] == '-' && buf[1] == '1');
+          fclose (fp);
+        }
+      if (loginuid_undefined)
+        {
+          fprintf (stderr, "Skipping test: loginuid is undefined.\n");
+          exit (77);
+        }
+#endif
+
+      /* It fails when stdin is not connected to a tty.  */
 #if !defined __hpux /* On HP-UX 11.11 it fails anyway.  */
       ASSERT (! isatty (0));
 #endif
@@ -63,8 +87,10 @@ test_getlogin_result (const char *buf, int err)
 
     if (!isatty (STDIN_FILENO))
       {
-         fprintf (stderr, "Skipping test: stdin is not a tty.\n");
-         exit (77);
+        /* We get here, for example, when running under 'nohup' or as part of a
+           non-interactive ssh command.  */
+        fprintf (stderr, "Skipping test: stdin is not a tty.\n");
+        exit (77);
       }
 
     ASSERT (fstat (STDIN_FILENO, &stat_buf) == 0);
diff --git a/modules/getlogin-tests b/modules/getlogin-tests
index 0ccd2ebb71..5056a9ca47 100644
--- a/modules/getlogin-tests
+++ b/modules/getlogin-tests
@@ -5,6 +5,7 @@ tests/signature.h
 tests/macros.h
 
 Depends-on:
+stdbool
 
 configure.ac:
 
diff --git a/modules/getlogin_r-tests b/modules/getlogin_r-tests
index 190bc9148d..7918ebd183 100644
--- a/modules/getlogin_r-tests
+++ b/modules/getlogin_r-tests
@@ -5,6 +5,7 @@ tests/signature.h
 tests/macros.h
 
 Depends-on:
+stdbool
 
 configure.ac:
 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]