On 01/12/14 19:31, Pádraig Brady wrote:
> On 01/12/14 18:49, Assaf Gordon wrote:
>> Hello,
>>
>> On Nov 30, 2014, at 6:09, Pádraig Brady <p...@draigbrady.com> wrote:
>>
>>> For context, gnulib-tests/test-getcwd.c is failing on Mac OS X with 
>>> exit(7)...
>>
>> I've tried forcing AT_FDCWD to zero in 'test-getcwd.c' on Mac-OS,
>> and it still fails with exit code 7, due to errno=2 (ENOENT).
>> So perhaps my initial guess about AT_FDCWD being the problem wasn't correct 
>> (at least it wasn't the only problem).
> 
> The replacement getcwd should be being used though
> which should not be giving the ENOENT.
> 
> We'd first have to confirm the replacement was being used,
> and if not why not.
> 
> If it is being used then we'd have to dig into why it's returning ENOENT.
> 
> I've asked for access to a remote OS X system,
> so fingers crossed I get that.

I just got access to remote mavericks and yosemite systems.

The attached should fix the test issue which impacts
darwin <= 13 (mavericks), though yosemite is OK as it has openat().

Pádraig.
>From ce37316b4e496e53a17bf5bad858ca3aa317bdb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Tue, 16 Dec 2014 02:35:19 +0000
Subject: [PATCH] getcwd: fix test failure on OS X 10.9

* m4/getcwd-path-max.m4: Avoid the replacement if it
won't be effective due to the PATH_MAX limitation of lstat().
(gl_cv_func_getcwd_path_max): Adjust to indicate this case.
* m4/getcwd.m4 (gl_FUNC_GETCWD): Define HAVE_GETCWD_SHORTER
for this case for use in tests, and also exclude this
case when setting REPLACE_GETCWD.
* tests/test-getcwd.c (test_long_name): Restrict the
tested path length so that lstat() will not be passed
a path greater than PATH_MAX.
Also key a test condition on HAVE_OPENAT_SUPPORT rather
than AT_FDCWD, since the latter is set unconditionally
since Sep 2009 in commit 52c658e9.
---
 ChangeLog             | 16 ++++++++++++++++
 m4/getcwd-path-max.m4 | 13 +++++++++++++
 m4/getcwd.m4          |  7 ++++++-
 tests/test-getcwd.c   |  8 +++++++-
 4 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0870a05..d654b60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2014-12-16  Pádraig Brady  <p...@draigbrady.com>
+
+	getcwd: fix test failure on OS X 10.9
+	* m4/getcwd-path-max.m4: Avoid the replacement if it
+	won't be effective due to the PATH_MAX limitation of lstat().
+	(gl_cv_func_getcwd_path_max): Adjust to indicate this case.
+	* m4/getcwd.m4 (gl_FUNC_GETCWD): Define HAVE_GETCWD_SHORTER
+	for this case for use in tests, and also exclude this
+	case when setting REPLACE_GETCWD.
+	* tests/test-getcwd.c (test_long_name): Restrict the
+	tested path length so that lstat() will not be passed
+	a path greater than PATH_MAX.
+	Also key a test condition on HAVE_OPENAT_SUPPORT rather
+	than AT_FDCWD, since the latter is set unconditionally
+	since Sep 2009 in commit 52c658e9.
+
 2014-12-14  Tim Rühsen  <tim.rueh...@gmx.de>
 
 	parse-datetime: avoid a compiler warning with byacc (trivial)
diff --git a/m4/getcwd-path-max.m4 b/m4/getcwd-path-max.m4
index 6b49f1a..8395716 100644
--- a/m4/getcwd-path-max.m4
+++ b/m4/getcwd-path-max.m4
@@ -122,6 +122,8 @@ main ()
 
       if (PATH_MAX <= cwd_len && cwd_len < PATH_MAX + DIR_NAME_SIZE)
         {
+          struct stat sb;
+
           c = getcwd (buf, PATH_MAX);
           if (!c && errno == ENOENT)
             {
@@ -138,6 +140,16 @@ main ()
               fail = 21;
               break;
             }
+
+          /* Our replacement needs to be able to stat() long ../../paths,
+             so generate a path larger than PATH_MAX to check,
+             avoiding the replacement if we can't stat().  */
+          c = getcwd (buf, cwd_len + 1);
+          if (c && !AT_FDCWD && stat (c, &sb) != 0 && is_ENAMETOOLONG (errno))
+            {
+              fail = 32;
+              break;
+            }
         }
 
       if (dotdot_max <= cwd_len - initial_cwd_len)
@@ -194,6 +206,7 @@ main ()
     [case $? in
      10|11|12) gl_cv_func_getcwd_path_max='no, but it is partly working';;
      31) gl_cv_func_getcwd_path_max='no, it has the AIX bug';;
+     32) gl_cv_func_getcwd_path_max='yes, but with shorter paths';;
      *) gl_cv_func_getcwd_path_max=no;;
      esac],
     [case "$host_os" in
diff --git a/m4/getcwd.m4 b/m4/getcwd.m4
index fc986cd..5afe0dd 100644
--- a/m4/getcwd.m4
+++ b/m4/getcwd.m4
@@ -136,11 +136,16 @@ AC_DEFUN([gl_FUNC_GETCWD],
         [Define to 1 if getcwd works, except it sometimes fails when it
          shouldn't, setting errno to ERANGE, ENAMETOOLONG, or ENOENT.])
       ;;
+    "yes, but with shorter paths")
+      AC_DEFINE([HAVE_GETCWD_SHORTER], [1],
+        [Define to 1 if getcwd works, but with shorter paths
+         than is generally tested with the replacement.])
+      ;;
   esac
 
   if { case "$gl_cv_func_getcwd_null" in *yes) false;; *) true;; esac; } \
      || test $gl_cv_func_getcwd_posix_signature != yes \
-     || test "$gl_cv_func_getcwd_path_max" != yes \
+     || { case "$gl_cv_func_getcwd_path_max" in *yes*) false;; *) true;; esac; } \
      || test $gl_abort_bug = yes; then
     REPLACE_GETCWD=1
   fi
diff --git a/tests/test-getcwd.c b/tests/test-getcwd.c
index 2ddcd20..add40ca 100644
--- a/tests/test-getcwd.c
+++ b/tests/test-getcwd.c
@@ -153,7 +153,13 @@ test_long_name (void)
 
   while (1)
     {
+# ifdef HAVE_GETCWD_SHORTER
+      /* On OS/X <= 10.9 for example, we're restricted to shorter paths
+         as lstat() doesn't support more than PATH_MAX.  */
+      size_t dotdot_max = PATH_MAX * 2;
+# else
       size_t dotdot_max = PATH_MAX * (DIR_NAME_SIZE / DOTDOTSLASH_LEN);
+# endif
       char *c = NULL;
 
       cwd_len += DIR_NAME_SIZE;
@@ -202,7 +208,7 @@ test_long_name (void)
                   fail = 6;
                   break;
                 }
-              if (AT_FDCWD || errno == ERANGE || errno == ENOENT)
+              if (HAVE_OPENAT_SUPPORT || errno == ERANGE || errno == ENOENT)
                 {
                   fail = 7;
                   break;
-- 
2.1.0

Reply via email to