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.
This commit is contained in:
Pino Toscano
2014-01-09 18:59:19 +01:00
parent 746a0b1f19
commit 7630a7bbbd

View File

@@ -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 int
@@ -277,7 +255,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;
@@ -443,10 +420,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 *
@@ -545,8 +518,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 */