bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] openat: test for fstatat (AT_FDCWD, ..., 0) bug


From: Paul Eggert
Subject: [PATCH] openat: test for fstatat (AT_FDCWD, ..., 0) bug
Date: Sat, 03 Sep 2011 10:09:01 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.21) Gecko/20110831 Thunderbird/3.1.13

Further testing with tar has revealed a bug with AIX 7.1's
implementation of fstatat (this time for real, I think :-).
I'm installing this patch into gnulib so that it can propagate
into tar.

openat: test for fstatat (AT_FDCWD, ..., 0) bug
This tests for another fstatat bug on AIX 7.1:
fstatat (AT_FDCWD, ..., 0) does not work.  See
<http://lists.gnu.org/archive/html/bug-tar/2011-09/msg00015.html>.
* lib/fstatat.c (FSTATAT_AT_FDCWD_0_BROKEN)
(LSTAT_FOLLOWS_SLASHED_SYMLINK): Default to 0.
(rpl_fstatat): Adjust so that it works around either (or both)
bugs if present.
* m4/openat.m4 (gl_FUNC_FSTATAT): Test for this fstatat bug.
diff --git a/lib/fstatat.c b/lib/fstatat.c
index a904e43..f1bed73 100644
--- a/lib/fstatat.c
+++ b/lib/fstatat.c
@@ -46,19 +46,33 @@ orig_fstatat (int fd, char const *filename, struct stat 
*buf, int flags)

 # undef fstatat

+# ifndef FSTATAT_AT_FDCWD_0_BROKEN
+#  define FSTATAT_AT_FDCWD_0_BROKEN 0
+# endif
+
+# ifndef LSTAT_FOLLOWS_SLASHED_SYMLINK
+#  define LSTAT_FOLLOWS_SLASHED_SYMLINK 0
+# endif
+
 /* fstatat should always follow symbolic links that end in /, but on
    Solaris 9 it doesn't if AT_SYMLINK_NOFOLLOW is specified.
    Likewise, trailing slash on a non-directory should be an error.
    These are the same problems that lstat.c and stat.c address, so
-   solve it in a similar way.  */
+   solve it in a similar way.
+
+   AIX 7.1 fstatat (AT_FDCWD, ..., 0) always fails, which is a bug.
+   Work around this bug if FSTATAT_AT_FDCWD_0_BROKEN is nonzero.  */

 int
 rpl_fstatat (int fd, char const *file, struct stat *st, int flag)
 {
-  int result = orig_fstatat (fd, file, st, flag);
+  int result =
+    (FSTATAT_AT_FDCWD_0_BROKEN && fd == AT_FDCWD && flag == 0
+     ? stat (file, st)
+     : orig_fstatat (fd, file, st, flag));
   size_t len;

-  if (result != 0)
+  if (LSTAT_FOLLOWS_SLASHED_SYMLINK || result != 0)
     return result;
   len = strlen (file);
   if (flag & AT_SYMLINK_NOFOLLOW)
diff --git a/m4/openat.m4 b/m4/openat.m4
index 5683650..149b864 100644
--- a/m4/openat.m4
+++ b/m4/openat.m4
@@ -1,4 +1,4 @@
-# serial 35
+# serial 36
 # See if we need to use our replacement for Solaris' openat et al functions.

 dnl Copyright (C) 2004-2011 Free Software Foundation, Inc.
@@ -164,8 +164,37 @@ AC_DEFUN([gl_FUNC_FSTATAT],

   if test $ac_cv_func_fstatat = no; then
     HAVE_FSTATAT=0
-  elif test $gl_cv_func_lstat_dereferences_slashed_symlink != yes; then
-    REPLACE_FSTATAT=1
+  else
+    dnl Test for an AIX 7.1 bug; see
+    dnl <http://lists.gnu.org/archive/html/bug-tar/2011-09/msg00015.html>.
+    AC_CACHE_CHECK([whether fstatat (AT_FDCWD, ..., 0) works],
+      [gl_cv_func_fstatat_AT_FDCWD_0],
+      [gl_cv_func_fstatat_AT_FDCWD_0=no
+       echo xxx >conftest.file
+       AC_RUN_IFELSE(
+         [AC_LANG_SOURCE(
+            [[
+              #include <fcntl.h>
+              #include <sys/stat.h>
+              int
+              main (void)
+              {
+                struct stat a;
+                return fstatat (AT_FDCWD, "conftest.file", &a, 0) != 0;
+              }
+            ]])],
+         [gl_cv_func_fstatat_AT_FDCWD_0=yes])])
+
+    case 
$gl_cv_func_fstatat_AT_FDCWD_0+$gl_cv_func_lstat_dereferences_slashed_symlink in
+    yes+yes) ;;
+    *) REPLACE_FSTATAT=1
+       if test $gl_cv_func_fstatat_AT_FDCWD_0 != yes; then
+         AC_DEFINE([FSTATAT_AT_FDCWD_0_BROKEN], [1],
+           [Define to 1 if fstatat (AT_FDCWD, ..., 0) does not work,
+            as in AIX 7.1.])
+       fi
+       ;;
+    esac
   fi
 ])




reply via email to

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