getlogin_r-tests: allow errno == ENXIO or ENOENT
authorPádraig Brady <P@draigBrady.com>
Fri, 9 Nov 2012 11:55:25 +0000 (11:55 +0000)
committerPádraig Brady <P@draigBrady.com>
Fri, 9 Nov 2012 11:58:55 +0000 (11:58 +0000)
* tests/test-getlogin.c (main): Skip tests if getlogin fails
with errno == ENXIO (No controlling tty).
* tests/test-getlogin_r.c (main): Skip tests if getlogin_r fails
with errno == ENOENT.  This was reported to happen in various
situations on GNU/Linux.

ChangeLog
tests/test-getlogin.c
tests/test-getlogin_r.c

index cca6c07..67e0342 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-11-09  Pádraig Brady  <P@draigBrady.com>
+
+       getlogin-tests: allow errno == ENXIO
+       * tests/test-getlogin.c (main): Skip tests if getlogin fails
+       with errno == ENXIO (No controlling tty).
+       getlogin_r-tests: Likewise. Also allow errno == ENOENT
+       * tests/test-getlogin_r.c (main): Skip tests if getlogin_r fails
+       with errno == ENOENT.  This was reported to happen in various
+       situations on GNU/Linux.
+
 2012-11-09  Paul Eggert  <eggert@cs.ucla.edu>
 
        getlogin-tests: allow errno == ENOENT
index d86fec2..f7903ae 100644 (file)
@@ -49,6 +49,7 @@ main (void)
       /* getlogin() fails when stdin is not connected to a tty.  */
       ASSERT (errno == ENOTTY
               || errno == EINVAL /* seen on Linux/SPARC */
+              || errno == ENXIO
              );
 #if !defined __hpux /* On HP-UX 11.11 it fails anyway.  */
       ASSERT (! isatty (0));
index 043aafb..45b6e7a 100644 (file)
@@ -40,9 +40,17 @@ main (void)
   err = getlogin_r (buf, sizeof (buf));
   if (err != 0)
     {
+      if (errno == ENOENT)
+        {
+          /* This can happen on GNU/Linux.  */
+          fprintf (stderr, "Skipping test: no entry in utmp file.\n");
+          return 77;
+        }
+
       /* getlogin_r() fails when stdin is not connected to a tty.  */
       ASSERT (err == ENOTTY
               || errno == EINVAL /* seen on Linux/SPARC */
+              || errno == ENXIO
              );
 #if !defined __hpux /* On HP-UX 11.11 it fails anyway.  */
       ASSERT (! isatty (0));