Browse Source

[core] prefer getxattr() instead of get_attr()

(when lighttpd is built ./configure --with-attr)
personal/stbuehler/ci-build
Glenn Strauss 2 years ago
parent
commit
455dc03778
  1. 9
      configure.ac
  2. 2
      src/CMakeLists.txt
  3. 11
      src/meson.build
  4. 12
      src/stat_cache.c

9
configure.ac

@ -503,6 +503,15 @@ if test "$WITH_ATTR" != no; then
])
AC_SUBST([ATTR_LIB])
# Linux getxattr
AC_CHECK_FUNC([getxattr], [
AC_CHECK_HEADERS([sys/xattr.h], [
AC_DEFINE([HAVE_XATTR], [1], [Linux extended attributes])
AC_DEFINE([HAVE_SYS_XATTR_H], [1])
have_xattr=yes
])
])
# (Free)BSD extattr
AC_CHECK_FUNC([extattr_get_file], [
AC_CHECK_HEADERS([sys/extattr.h], [

2
src/CMakeLists.txt

@ -248,6 +248,8 @@ macro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
endmacro(XCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
if(WITH_XATTR)
check_include_files("sys/types.h;sys/xattr.h" HAVE_SYS_XATTR_H)
check_function_exists(getxattr HAVE_XATTR)
check_include_files("sys/types.h;attr/attributes.h" HAVE_ATTR_ATTRIBUTES_H)
if(HAVE_ATTR_ATTRIBUTES_H)
check_library_exists(attr attr_get "" HAVE_XATTR)

11
src/meson.build

@ -557,6 +557,16 @@ endif
libattr = []
if get_option('with_xattr')
if compiler.has_function('getxattr',
args: defs,
prefix: '''
#include <sys/types.h>
#include <sys/xattr.h>
'''
)
conf_data.set('HAVE_SYS_XATTR_H', true)
conf_data.set('HAVE_XATTR', true)
else
libattr = [ compiler.find_library('attr') ]
if not(compiler.has_function('attr_get',
args: defs,
@ -570,6 +580,7 @@ if get_option('with_xattr')
endif
conf_data.set('HAVE_ATTR_ATTRIBUTES_H', true)
conf_data.set('HAVE_XATTR', true)
endif
endif
libz = []

12
src/stat_cache.c

@ -15,7 +15,9 @@
#include <unistd.h>
#include <fcntl.h>
#ifdef HAVE_ATTR_ATTRIBUTES_H
#if defined(HAVE_SYS_XATTR_H)
# include <sys/xattr.h>
#elif defined(HAVE_ATTR_ATTRIBUTES_H)
# include <attr/attributes.h>
#endif
@ -555,10 +557,16 @@ static const char *attrname = "Content-Type";
static char attrval[128];
static buffer attrb = { attrval, 0, 0 };
static int stat_cache_attr_get(char *name) {
static int stat_cache_attr_get(const char *name) {
#if defined(HAVE_XATTR)
#if defined(HAVE_SYS_XATTR_H)
ssize_t attrlen;
if (0 < (attrlen = getxattr(name, attrname,
attrval, sizeof(attrval)-1)))
#else
int attrlen = sizeof(attrval)-1;
if (0 == attr_get(name, attrname, attrval, &attrlen, 0))
#endif
#elif defined(HAVE_EXTATTR)
ssize_t attrlen;
if (0 < (attrlen = extattr_get_file(name, EXTATTR_NAMESPACE_USER, attrname,

Loading…
Cancel
Save