Skip to contentSkip to conversation

safe_macros: Add SAFE_GETXATTR() macro

PATCH New Xiao Yang 2 participants 3 messages Sep 22, 2018 – Oct 4, 2018 Library code

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/2 safe_macros: Add SAFE_GETXATTR() macro

---
 include/tst_safe_macros.h |  5 +++++
 lib/safe_macros.c         | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+)
include/tst_safe_macros.h +5 -0
index 03657a4..413226e 100644
@@ -441,6 +441,11 @@ struct group *safe_getgrnam(const char *file, const int lineno,
 #define SAFE_GETGRNAM(name) \
 	safe_getgrnam(__FILE__, __LINE__, (name))
 
+ssize_t safe_getxattr(const char *file, const int lineno, const char *path,
+	const char *name, void *value, size_t size);
+#define SAFE_GETXATTR(path, name, value, size) \
+	safe_getxattr(__FILE__, __LINE__, (path), (name), (value), (size))
+
 int safe_setxattr(const char *file, const int lineno, const char *path,
             const char *name, const void *value, size_t size, int flags);
 #define SAFE_SETXATTR(path, name, value, size, flags) \
lib/safe_macros.c +21 -0
index 5cc80d0..9588ef5 100644
@@ -840,6 +840,27 @@ int safe_getpriority(const char *file, const int lineno, int which, id_t who)
 	return rval;
 }
 
+ssize_t safe_getxattr(const char *file, const int lineno, const char *path,
+		      const char *name, void *value, size_t size)
+{
+	ssize_t rval;
+
+	rval = getxattr(path, name, value, size);
+
+	if (rval == -1) {
+		if (errno == ENOTSUP) {
+			tst_brkm(TCONF, NULL,
+				 "%s:%d: no xattr support in fs or mounted "
+				 "without user_xattr option", file, lineno);
+		}
+
+		tst_brkm(TBROK | TERRNO, NULL, "%s:%d: getxattr() failed",
+			 file, lineno);
+	}
+
+	return rval;
+}
+
 int safe_setxattr(const char *file, const int lineno, const char *path,
 		  const char *name, const void *value, size_t size, int flags)
 {
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/2 syscalls/getxattr05: Add new regression testcase

Test POSIX Access Control Lists by getxattr(2) with/without a user namespace. The following issue is included by the new testcase and has been fixed in kernel:
'82c9a927bc5d ("getxattr: use correct xattr length")'

Fix #396

---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/getxattr/.gitignore   |   1 +
 testcases/kernel/syscalls/getxattr/Makefile     |   2 +
 testcases/kernel/syscalls/getxattr/getxattr05.c | 171 ++++++++++++++++++++++++
 4 files changed, 175 insertions(+)
 create mode 100644 testcases/kernel/syscalls/getxattr/getxattr05.c
runtest/syscalls +1 -0
index 0d0be77..bfdd450 100644
@@ -461,6 +461,7 @@ getxattr01 getxattr01
 getxattr02 getxattr02
 getxattr03 getxattr03
 getxattr04 getxattr04
+getxattr05 getxattr05
 
 #Needs tty device.
 #ioctl01 ioctl01 -D /dev/tty0
testcases/kernel/syscalls/getxattr/.gitignore +1 -0
index 3918a30..cded941 100644
@@ -2,3 +2,4 @@
 /getxattr02
 /getxattr03
 /getxattr04
+/getxattr05
testcases/kernel/syscalls/getxattr/Makefile +2 -0
index 72544c1..3f78745 100644
@@ -20,4 +20,6 @@ top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
+getxattr05: LDLIBS	+= $(ACL_LIBS)
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/getxattr/getxattr05.c new file +171 -0

171 lines not on this page · raw message

Signature · 1 line
1.8.3.1