]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/replace: prefer <sys/xattr.h> over <attr/xattr.h>
authorRalph Boehme <slow@samba.org>
Sat, 14 Dec 2019 17:35:51 +0000 (18:35 +0100)
committerBjörn Baumbach <bb@sernet.de>
Wed, 18 Dec 2019 10:13:41 +0000 (10:13 +0000)
This prevents the following compile error that may happens if "system/filesys.h"
is included before "system/capability.h" on Ubuntu 16.04:

  [1802/4407] Compiling source3/lib/system.c
  In file included from ../../lib/replace/system/filesys.h:112:0,
                   from ../../source3/include/vfs.h:29,
                   from ../../source3/include/smb.h:150,
                   from ../../source3/include/includes.h:284,
                   from ../../source3/lib/system.c:23:
  /usr/include/x86_64-linux-gnu/sys/xattr.h:32:3: error: expected identifier before numeric constant
     XATTR_CREATE = 1, /* set value, fail if attr already exists.  */
     ^

The above error is from compiling a source tree which includes a change that
adds an include "system/filesys.h" to the top of "source3/include/vfs.h".

"source3/lib/system.c" has the following includes:

  #include "includes.h"
  #include "system/syslog.h"
  #include "system/capability.h"
  #include "system/passwd.h"
  #include "system/filesys.h"
  #include "../lib/util/setid.h"

The first include of "includes.h" pulls in "vfs.h" which will pull in
"system/filesys.h" with the mentioned change. "system/filesys.h" pulls in
<attr/xattr.h> which has this define

  #define XATTR_CREATE  0x1

Later in "source3/lib/system.c" "system/capability.h" is included which includes
<sys/xattr.h> on Ubuntu 16.04 (not in later versions of glibc). This defines the
XATTR_* values as an enum:

  enum {
    XATTR_CREATE = 1,     /* set value, fail if attr already exists.  */
    XATTR_REPLACE = 2     /* set value, fail if attr does not exist.  */
  };

The previous define of XATTR_CREATE as 1 makes this

  enum {
    1 = 1,     /* set value, fail if attr already exists.  */
    2 = 2     /* set value, fail if attr does not exist.  */
  };

which is invalid C. The compiler error diagnostic is a bit confusing, as it
prints the original enum from the include file.

See also:

<https://bugs.freedesktop.org/show_bug.cgi?id=78741>
<https://bugs.launchpad.net/ubuntu/+source/attr/+bug/1288091>
<https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=756097>

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Björn Baumbach <bb@samba.org>
lib/replace/system/filesys.h

index afde4eacb39f4b492ab9d0cd8c14c548e2fc04f0..976b2aeec5ea3656e6ed0611ff51e77e7732bb14 100644 (file)
 #endif
 
 /* mutually exclusive (SuSE 8.2) */
-#if defined(HAVE_ATTR_XATTR_H)
-#include <attr/xattr.h>
-#elif defined(HAVE_SYS_XATTR_H)
+#if defined(HAVE_SYS_XATTR_H)
 #include <sys/xattr.h>
+#elif defined(HAVE_ATTR_XATTR_H)
+#include <attr/xattr.h>
 #elif defined(HAVE_SYS_ATTRIBUTES_H)
 #include <sys/attributes.h>
 #elif defined(HAVE_ATTR_ATTRIBUTES_H)