bug-tar
[Top][All Lists]
Advanced

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

[Bug-tar] [PATCH] Fix build with xattr support


From: Anthony G. Basile
Subject: [Bug-tar] [PATCH] Fix build with xattr support
Date: Mon, 16 Dec 2013 18:04:59 -0500

From: "Anthony G. Basile" <address@hidden>

The build system searches for <attr/xattr.h> and doesn't bother
looking to see if setxattr(), getxattr() and friends are provided
by the system libc.  Worse, on successfully finding <attr/xattr.h>
it then proceeds to include it but then links against libc for
the *xattr() functions.

This patch has the build system look for <sys/xattr.h> first and
if it success, links against libc.  On failing to find <sys/xattr.h>,
it then search for <attr/xattr.h> and links against libattr.so.  This
can happen, for instance, on a uClibc system where UCLIBC_HAS_XATTR
is not set, but libattr.so is present.  Then the *xattr() functions
must be provided by libattr.so.

X-Gentoo-Bug: 489170
X-Gentoo-Bug-URL: https://bugs.gentoo.org/489170
---
 acinclude.m4   | 35 ++++++++++++++++++++++-------------
 lib/xattr-at.h | 10 +++++++++-
 2 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index d48c881..7b9c13f 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -37,18 +37,27 @@ AC_DEFUN([TAR_HEADERS_ATTR_XATTR_H],
     [], [with_xattrs=maybe]
   )
 
-  AC_CHECK_HEADERS([attr/xattr.h])
-  AM_CONDITIONAL([TAR_COND_XATTR_H],[test "$ac_cv_header_attr_xattr_h" = yes])
-  if test "$ac_cv_header_attr_xattr_h" = yes; then
-    AC_CHECK_FUNCS(getxattr  fgetxattr  lgetxattr \
-                   setxattr  fsetxattr  lsetxattr \
-                   listxattr flistxattr llistxattr,
-        # only when functions are present
-        AC_DEFINE([HAVE_ATTR_XATTR_H], [1],
-                    [define to 1 if we have <attr/xattr.h> header])
-        if test "$with_xattrs" != no; then
-          AC_DEFINE([HAVE_XATTRS],,[Define when we have working linux xattrs.])
-        fi
-    )
+  AC_CHECK_HEADERS([sys/xattr.h attr/xattr.h])
+  AM_CONDITIONAL([TAR_COND_XATTR_H],
+    [test "$ac_cv_header_sys_xattr_h" = yes -o "$ac_cv_header_attr_xattr_h" = 
yes])
+
+  if test "$with_xattrs" != no; then
+    # If <sys/xattr.h> doesn't exist and <attr/xattr.h> does,
+    # then link against libattr.so and not libc
+    if test "$ac_cv_header_sys_xattr_h" = no -a "$ac_cv_header_attr_xattr_h" = 
yes; then
+      AC_CHECK_LIB([attr],[fgetxattr])
+    fi
+    have_functions=yes
+    for xattr_func in getxattr  fgetxattr  lgetxattr \
+                      setxattr  fsetxattr  lsetxattr \
+                      listxattr flistxattr llistxattr; do \
+      AC_SEARCH_LIBS([$xattr_func], [attr],, [have_functions=no])
+      test $have_functions = no && break
+    done
+    if test $have_functions = yes; then
+      AC_DEFINE([HAVE_XATTRS],[1],[Define when we have working linux xattrs.])
+    else
+      test "$with_xattrs" = yes && AC_MSG_ERROR([xattr support requested but 
not found.])
+    fi
   fi
 ])
diff --git a/lib/xattr-at.h b/lib/xattr-at.h
index 2981771..1f517d0 100644
--- a/lib/xattr-at.h
+++ b/lib/xattr-at.h
@@ -20,7 +20,15 @@
 #define XATTRS_AT_H
 
 #include <sys/types.h>
-#include <attr/xattr.h>
+#if defined(HAVE_SYS_XATTR_H)
+# include <sys/xattr.h>
+#elif defined(HAVE_ATTR_XATTR_H)
+# include <attr/xattr.h>
+#endif
+
+#ifndef ENOATTR
+# define ENOATTR ENODATA        /* No such attribute */
+#endif
 
 /* These are the dir-fd-relative variants of the functions without the
    "at" suffix.  For example, setxattrat (AT_FDCWD, path, name, value, size,
-- 
1.8.3.2




reply via email to

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