From 81690922dc99d84720c6a9a8fda7717c958611b7 Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Thu, 9 Jan 2014 18:59:19 +0100
Subject: [PATCH] daemon: xattr: simplify the enabling of the linuxxattrs
features
Instead of enable them when having one of the two headers for it but
still checking for the HAVE_* availability of each *xattr() function
used, just enable the linuxxattrs as a whole when having any of the
needed headers (like before) and all the needed functions.
This might cause the linuxxattrs to not be available anymore on systems
without the whole set of *xattr() functions implemented, but OTOH it
simplifies the xattr.c implementations.
(cherry picked from commit 7630a7bbbdceee8e6aad08511e752f5fcb273416)
---
daemon/xattr.c | 49 +++++++++++--------------------------------------
1 file changed, 11 insertions(+), 38 deletions(-)
diff --git a/daemon/xattr.c b/daemon/xattr.c
index 7004566..2f642db 100644
--- a/daemon/xattr.c
+++ b/daemon/xattr.c
@@ -27,7 +27,15 @@
#include "actions.h"
#include "optgroups.h"
-#if defined(HAVE_ATTR_XATTR_H) || defined(HAVE_SYS_XATTR_H)
+#if (defined(HAVE_ATTR_XATTR_H) || defined(HAVE_SYS_XATTR_H)) && \
+ defined(HAVE_LISTXATTR) && defined(HAVE_LLISTXATTR) && \
+ defined(HAVE_GETXATTR) && defined(HAVE_LGETXATTR) && \
+ defined(HAVE_REMOVEXATTR) && defined(HAVE_LREMOVEXATTR) && \
+ defined(HAVE_SETXATTR) && defined(HAVE_LSETXATTR)
+# define HAVE_LINUX_XATTRS
+#endif
+
+#ifdef HAVE_LINUX_XATTRS
# ifdef HAVE_ATTR_XATTR_H
# include <attr/xattr.h>
@@ -50,67 +58,37 @@ static int _removexattr (const char *xattr, const char *path, int (*removexattr)
guestfs_int_xattr_list *
do_getxattrs (const char *path)
{
-#if defined(HAVE_LISTXATTR) && defined(HAVE_GETXATTR)
return getxattrs (path, listxattr, getxattr);
-#else
- reply_with_error ("no support for listxattr and getxattr");
- return NULL;
-#endif
}
guestfs_int_xattr_list *
do_lgetxattrs (const char *path)
{
-#if defined(HAVE_LLISTXATTR) && defined(HAVE_LGETXATTR)
return getxattrs (path, llistxattr, lgetxattr);
-#else
- reply_with_error ("no support for llistxattr and lgetxattr");
- return NULL;
-#endif
}
int
do_setxattr (const char *xattr, const char *val, int vallen, const char *path)
{
-#if defined(HAVE_SETXATTR)
return _setxattr (xattr, val, vallen, path, setxattr);
-#else
- reply_with_error ("no support for setxattr");
- return -1;
-#endif
}
int
do_lsetxattr (const char *xattr, const char *val, int vallen, const char *path)
{
-#if defined(HAVE_LSETXATTR)
return _setxattr (xattr, val, vallen, path, lsetxattr);
-#else
- reply_with_error ("no support for lsetxattr");
- return -1;
-#endif
}
int
do_removexattr (const char *xattr, const char *path)
{
-#if defined(HAVE_REMOVEXATTR)
return _removexattr (xattr, path, removexattr);
-#else
- reply_with_error ("no support for removexattr");
- return -1;
-#endif
}
int
do_lremovexattr (const char *xattr, const char *path)
{
-#if defined(HAVE_LREMOVEXATTR)
return _removexattr (xattr, path, lremovexattr);
-#else
- reply_with_error ("no support for lremovexattr");
- return -1;
-#endif
}
static guestfs_int_xattr_list *
@@ -262,7 +240,6 @@ _removexattr (const char *xattr, const char *path,
guestfs_int_xattr_list *
do_internal_lxattrlist (const char *path, char *const *names)
{
-#if defined(HAVE_LLISTXATTR) && defined(HAVE_LGETXATTR)
guestfs_int_xattr_list *ret = NULL;
size_t i, j;
size_t k, m, nr_attrs;
@@ -425,10 +402,6 @@ do_internal_lxattrlist (const char *path, char *const *names)
free (ret);
}
return NULL;
-#else
- reply_with_error ("no support for llistxattr and lgetxattr");
- return NULL;
-#endif
}
char *
@@ -527,8 +500,8 @@ do_lgetxattr (const char *path, const char *name, size_t *size_r)
return buf; /* caller frees */
}
-#else /* no xattr.h */
+#else /* no HAVE_LINUX_XATTRS */
OPTGROUP_LINUXXATTRS_NOT_AVAILABLE
-#endif /* no xattr.h */
+#endif /* no HAVE_LINUX_XATTRS */
--
1.8.5.3