>From 7ca6af1aa16e6a682bd5ce77a83ab4fb4c16fee7 Mon Sep 17 00:00:00 2001
From: Pavel Raiskup
Date: Wed, 17 Jun 2015 15:37:12 +0200
Subject: [PATCH 2/2] xattrs: better ./configure check for xattr calls
Be careful to define HAVE_XATTRS when not all needed xattr-related
functions are properly defined either in libc or libattr.
Reported firstly by Dominyk Tiller:
http://lists.gnu.org/archive/html/bug-tar/2014-08/msg00001.html
* acinclude.m4 (TAR_HEADERS_ATTR_XATTR_H): De-duplicate a bit.
Don't use AC_CHECK_FUNCS macro with "list" of xattrs functions
because the 'action-if-found' there is evaluated for *any*
available function from the list -- and thus this previously
defined HAVE_XATTRS even though not all handlers were available.
Use rather AC_SEARCH_LIBS for each function separately. This
change allowed us to remove AC_CHECK_LIB call (used previously
just to enhance $LIBS variable to satisfy following
AC_CHECK_FUNCS macro).
Remove also redundant AM_CONDITIONAL because TAR_LIB_ATTR
conditional was used just to to complement LIBS with '-lattr',
which was redundant anyway (AC_CHECK_LIB done that before,
AC_SEARCH_LIBS does it now).
* lib/xattr-at.c: Move the guarding macro a bit "up" to compile
less code.
* src/Makefile.am: Remove redundant -lattr from tar_LDADD.
---
acinclude.m4 | 42 ++++++++++++++----------------------------
lib/xattr-at.c | 4 ++--
src/Makefile.am | 4 ----
3 files changed, 16 insertions(+), 34 deletions(-)
diff --git a/acinclude.m4 b/acinclude.m4
index 3b28b3b..db0bbc7 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -40,37 +40,23 @@ AC_DEFUN([TAR_HEADERS_ATTR_XATTR_H],
# First check for
AC_CHECK_HEADERS([sys/xattr.h])
AM_CONDITIONAL([TAR_COND_XATTR_H],[test "$ac_cv_header_sys_xattr_h" = yes])
- AM_CONDITIONAL([TAR_LIB_ATTR],[false])
- if test "$ac_cv_header_sys_xattr_h" = yes; then
- AC_CHECK_FUNCS(getxattr fgetxattr lgetxattr \
- setxattr fsetxattr lsetxattr \
- listxattr flistxattr llistxattr,
- # only when functions are present
- AC_DEFINE([HAVE_SYS_XATTR_H], [1],
- [define to 1 if we have header])
- if test "$with_xattrs" != no; then
- AC_DEFINE([HAVE_XATTRS],,[Define when we have working linux xattrs.])
- fi
- )
- fi
-
- # If is not found, then check for
if test "$ac_cv_header_sys_xattr_h" != yes; then
AC_CHECK_HEADERS([attr/xattr.h])
AM_CONDITIONAL([TAR_COND_XATTR_H],[test "$ac_cv_header_attr_xattr_h" = yes])
- AC_CHECK_LIB([attr],[fgetxattr])
- AM_CONDITIONAL([TAR_LIB_ATTR],[test "$ac_cv_lib_attr_fgetxattr" = 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 header])
- if test "$with_xattrs" != no; then
- AC_DEFINE([HAVE_XATTRS],,[Define when we have working linux xattrs.])
- fi
- )
+ fi
+
+ if test "$with_xattrs" != no; then
+ for i in getxattr fgetxattr lgetxattr \
+ setxattr fsetxattr lsetxattr \
+ listxattr flistxattr llistxattr
+ do
+ AC_SEARCH_LIBS($i, attr)
+ eval found=\$ac_cv_search_$i
+ test "$found" = "no" && break
+ done
+
+ if test "$found" != no; then
+ AC_DEFINE([HAVE_XATTRS],,[Define when we have working linux xattrs.])
fi
fi
])
diff --git a/lib/xattr-at.c b/lib/xattr-at.c
index 66427e9..8f59609 100644
--- a/lib/xattr-at.c
+++ b/lib/xattr-at.c
@@ -16,6 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
+#ifdef HAVE_XATTRS
+
#include
#include "xattr-at.h"
@@ -31,8 +33,6 @@
#include "openat-priv.h"
-#ifdef HAVE_XATTRS
-
/* setxattrat */
#define AT_FUNC_NAME setxattrat
#define AT_FUNC_F1 setxattr
diff --git a/src/Makefile.am b/src/Makefile.am
index 82b2d46..42daaef 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,7 +52,3 @@ AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
LDADD = ../lib/libtar.a ../gnu/libgnu.a $(LIBINTL) $(LIBICONV)
tar_LDADD = $(LIBS) $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_EACCESS) $(LIB_SELINUX)
-
-if TAR_LIB_ATTR
-tar_LDADD += -lattr
-endif
--
2.1.0