On 11/09/2012 09:05 AM, Paul Eggert wrote:
I found this problem when running 'make check' with the latest
coreutils, and pushed the following patch.

---
  ChangeLog             | 7 +++++++
  tests/test-getlogin.c | 7 +++++++
  2 files changed, 14 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 7e0129e..cca6c07 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-11-09  Paul Eggert  <[email protected]>
+
+       getlogin-tests: allow errno == ENOENT
+       * tests/test-getlogin.c (main): Skip tests if getlogin fails
+       with errno == ENOENT.  This happened to me on Ubuntu 12.04.1 x86,
+       when running a test in an Emacs shell buffer.
+
  2012-11-08  Jim Meyering  <[email protected]>

        tests/nap.h: avoid warning about unused variable
diff --git a/tests/test-getlogin.c b/tests/test-getlogin.c
index 449ceaa..d86fec2 100644
--- a/tests/test-getlogin.c
+++ b/tests/test-getlogin.c
@@ -39,6 +39,13 @@ main (void)
    buf = getlogin ();
    if (buf == NULL)
      {
+      if (errno == ENOENT)
+        {
+          /* This can happen on GNU/Linux.  */
+          fprintf (stderr, "Skipping test: no entry in utmp file.\n");
+          return 77;
+        }
+
        /* getlogin() fails when stdin is not connected to a tty.  */
        ASSERT (errno == ENOTTY
                || errno == EINVAL /* seen on Linux/SPARC */


getlogin_r needs the same treatment probably.
I'll apply the attached in a while.

thanks,
Pádraig.

>From bfe5b0dfd062fb9ffbc61b27a0d750c41abc1a8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Fri, 9 Nov 2012 11:55:25 +0000
Subject: [PATCH] getlogin_r-tests: allow errno == ENXIO or ENOENT

* 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               |   10 ++++++++++
 tests/test-getlogin.c   |    1 +
 tests/test-getlogin_r.c |    8 ++++++++
 3 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cca6c07..67e0342 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-11-09  Pádraig Brady  <[email protected]>
+
+	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  <[email protected]>
 
 	getlogin-tests: allow errno == ENOENT
diff --git a/tests/test-getlogin.c b/tests/test-getlogin.c
index d86fec2..f7903ae 100644
--- a/tests/test-getlogin.c
+++ b/tests/test-getlogin.c
@@ -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));
diff --git a/tests/test-getlogin_r.c b/tests/test-getlogin_r.c
index 043aafb..45b6e7a 100644
--- a/tests/test-getlogin_r.c
+++ b/tests/test-getlogin_r.c
@@ -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));
-- 
1.7.6.4

Reply via email to