[LTP] [PATCH v4 1/3] lib: add helper SAFE_FANOTIFY_INIT

Xiong Zhou xzhou@redhat.com
Wed Aug 16 09:15:35 CEST 2017


Signed-off-by: Xiong Zhou <xzhou@redhat.com>
---
 include/tst_safe_macros.h |  5 +++++
 lib/tst_safe_macros.c     | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 8245b68..f23f765 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -438,4 +438,9 @@ int safe_mknod(const char *file, const int lineno, const char *pathname,
 #define SAFE_MKNOD(pathname, mode, dev) \
 	safe_mknod(__FILE__, __LINE__, (pathname), (mode), (dev))
 
+int safe_fanotify_init(const char *file, const int lineno,
+	unsigned int flags, unsigned int event_f_flags);
+#define SAFE_FANOTIFY_INIT(fan, mode)  \
+	safe_fanotify_init(__FILE__, __LINE__, (fan), (mode))
+
 #endif /* SAFE_MACROS_H__ */
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index e7f5095..ecd39f8 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -17,6 +17,7 @@
 
 #define _GNU_SOURCE
 #include <unistd.h>
+#include <errno.h>
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
 #include "tst_safe_macros.h"
@@ -47,3 +48,23 @@ pid_t safe_getpgid(const char *file, const int lineno, pid_t pid)
 
 	return pgid;
 }
+
+int safe_fanotify_init(const char *file, const int lineno,
+	unsigned int flags, unsigned int event_f_flags)
+{
+	int rval;
+
+	rval = fanotify_init(flags, event_f_flags);
+
+	if (rval == -1) {
+
+		if (errno == ENOSYS) {
+			tst_brk(TCONF,
+				"fanotify is not configured in this kernel.");
+		}
+		tst_brk(TBROK | TERRNO,
+			"%s:%d: fanotify_init() failed", file, lineno);
+	}
+
+	return rval;
+}
-- 
1.8.3.1



More information about the ltp mailing list