Hi Cyril,

On 07/15/2014 10:45 AM, [email protected] wrote:
> What about we drop the myfanotify*() functions now since we check if
> fanotify.h exists now, use fanotify*() in the testcases and define the
> syscall wrappers only when fanotify.h is not available (see for example
> include/lapi/renameat.h)?

Attached is the updated patch which does exactly this.
 
> Otherwise it looks fine to me.

Great!

Please apply this patch. Here is the new changelog:

This patch to some degree reverts my last patch which was committed as:
  commit 5d08e164964e19be693e6e8fddf3afb82e505b4f
  Author: Helge Deller <[email protected]>
  Date:   Wed Apr 16 21:00:28 2014 +0200
  fix fanotify syscall check on compat kernel

The problem is, that fanotify_mark() uses a 64bit parameter (mask).
When calling this syscall with it's 64bit parameter on a 32bit arch it is very
architecture and compiler dependend, in which order the lower and higher 32bits
are put on the stack and thus ends up in the arguments for the Linux kernel.

So, to avoid any problems we really need to call this syscall the same way as
it's defined by glibc.

This patch drops the myfanotify*() functions and uses the fanotify*() functions 
directly from the glibc header <sys/fanotify.h> if available. If the header is
not available, it will provide wrapped syscalls as fallback.

Furthermore, in the fanotify03 testcase it will now correctly return TCONF 
instead
of TFAIL if the CONFIG_FANOTIFY_ACCESS_PERMISSIONS kernel config option has not 
been
set in the currently running Linux kernel.

Tested on the hppa/parisc 32- and 64bit architecture.

Signed-off-by: Helge Deller <[email protected]>
diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index a52093c..518d05e 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -28,27 +28,30 @@
 #ifndef	__FANOTIFY_H__
 #define	__FANOTIFY_H__
 
-#include <stdint.h>
-#include <endian.h>
-#include "lapi/abisize.h"
-#include "linux_syscall_numbers.h"
+#include "config.h"
+
+#if defined(HAVE_SYS_FANOTIFY_H)
+
+#include <sys/fanotify.h>
+
+#else /* HAVE_SYS_FANOTIFY_H */
 
 /* fanotify(7) wrappers */
 
-#define	myfanotify_init(flags, event_f_flags) \
-	syscall(__NR_fanotify_init, flags, event_f_flags)
+#include <stdint.h>
+#include "linux_syscall_numbers.h"
 
-long myfanotify_mark(int fd, unsigned int flags, uint64_t mask,
+static int fanotify_init(unsigned int flags, unsigned int event_f_flags)
+{
+	return syscall(__NR_fanotify_init, flags, event_f_flags);
+}
+
+static long fanotify_mark(int fd, unsigned int flags, uint64_t mask,
                      int dfd, const char *pathname)
 {
-#if LTP_USE_64_ABI
-	return ltp_syscall(__NR_fanotify_mark, fd, flags, mask, dfd, pathname);
-#else
-	return ltp_syscall(__NR_fanotify_mark, fd, flags,
-			 __LONG_LONG_PAIR((unsigned long) (mask >> 32),
-					  (unsigned long) mask),
-			 dfd, (unsigned long) pathname);
-#endif
+	return syscall(__NR_fanotify_mark, fd, flags, mask, dfd, pathname);
 }
 
+#endif /* HAVE_SYS_FANOTIFY_H */
+
 #endif /* __FANOTIFY_H__ */
diff --git a/testcases/kernel/syscalls/fanotify/fanotify01.c b/testcases/kernel/syscalls/fanotify/fanotify01.c
index 5d6e0b9..7a2b5be 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify01.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify01.c
@@ -79,7 +79,7 @@ int main(int ac, char **av)
 
 		tst_count = 0;
 
-		if (myfanotify_mark(fd_notify, FAN_MARK_ADD, FAN_ACCESS | FAN_MODIFY |
+		if (fanotify_mark(fd_notify, FAN_MARK_ADD, FAN_ACCESS | FAN_MODIFY |
 				    FAN_CLOSE | FAN_OPEN, AT_FDCWD, fname) < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
 			    "fanotify_mark (%d, FAN_MARK_ADD, FAN_ACCESS | "
@@ -133,7 +133,7 @@ int main(int ac, char **av)
 		 */
 
 		/* Ignore access events */
-		if (myfanotify_mark(fd_notify,
+		if (fanotify_mark(fd_notify,
 				    FAN_MARK_ADD | FAN_MARK_IGNORED_MASK,
 				    FAN_ACCESS, AT_FDCWD, fname) < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
@@ -183,7 +183,7 @@ int main(int ac, char **av)
 		 * Now ignore open & close events regardless of file
 		 * modifications
 		 */
-		if (myfanotify_mark(fd_notify,
+		if (fanotify_mark(fd_notify,
 				    FAN_MARK_ADD | FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY,
 				    FAN_OPEN | FAN_CLOSE, AT_FDCWD, fname) < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
@@ -213,7 +213,7 @@ int main(int ac, char **av)
 		len += ret;
 
 		/* Now remove open and close from ignored mask */
-		if (myfanotify_mark(fd_notify,
+		if (fanotify_mark(fd_notify,
 				    FAN_MARK_REMOVE | FAN_MARK_IGNORED_MASK,
 				    FAN_OPEN | FAN_CLOSE, AT_FDCWD, fname) < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
@@ -315,7 +315,7 @@ pass:
 
 		}
 		/* Remove mark to clear FAN_MARK_IGNORED_SURV_MODIFY */
-		if (myfanotify_mark(fd_notify, FAN_MARK_REMOVE, FAN_ACCESS | FAN_MODIFY |
+		if (fanotify_mark(fd_notify, FAN_MARK_REMOVE, FAN_ACCESS | FAN_MODIFY |
 				    FAN_CLOSE | FAN_OPEN, AT_FDCWD, fname) < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
 			    "fanotify_mark (%d, FAN_MARK_REMOVE, FAN_ACCESS | "
@@ -344,7 +344,7 @@ static void setup(void)
 	/* close the file we have open */
 	SAFE_CLOSE(cleanup, fd);
 
-	if ((fd_notify = myfanotify_init(FAN_CLASS_NOTIF, O_RDONLY)) < 0) {
+	if ((fd_notify = fanotify_init(FAN_CLASS_NOTIF, O_RDONLY)) < 0) {
 		if (errno == ENOSYS) {
 			tst_brkm(TCONF, cleanup,
 				 "fanotify is not configured in this kernel.");
diff --git a/testcases/kernel/syscalls/fanotify/fanotify02.c b/testcases/kernel/syscalls/fanotify/fanotify02.c
index 13711f0..6dcd8cf 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify02.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify02.c
@@ -79,7 +79,7 @@ int main(int ac, char **av)
 
 		tst_count = 0;
 
-		if (myfanotify_mark(fd_notify, FAN_MARK_ADD, FAN_ACCESS |
+		if (fanotify_mark(fd_notify, FAN_MARK_ADD, FAN_ACCESS |
 				    FAN_MODIFY | FAN_CLOSE | FAN_OPEN |
 				    FAN_EVENT_ON_CHILD, AT_FDCWD, ".") < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
@@ -134,7 +134,7 @@ int main(int ac, char **av)
 		/*
 		 * now remove child mark
 		 */
-		if (myfanotify_mark(fd_notify, FAN_MARK_REMOVE,
+		if (fanotify_mark(fd_notify, FAN_MARK_REMOVE,
 				    FAN_EVENT_ON_CHILD, AT_FDCWD, ".") < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
 			    "fanotify_mark (%d, FAN_MARK REMOVE, "
@@ -232,7 +232,7 @@ static void setup(void)
 	tst_tmpdir();
 	sprintf(fname, "fname_%d", getpid());
 
-	if ((fd_notify = myfanotify_init(FAN_CLASS_NOTIF, O_RDONLY)) < 0) {
+	if ((fd_notify = fanotify_init(FAN_CLASS_NOTIF, O_RDONLY)) < 0) {
 		if (errno == ENOSYS) {
 			tst_brkm(TCONF, cleanup,
 				 "fanotify is not configured in this kernel.");
diff --git a/testcases/kernel/syscalls/fanotify/fanotify03.c b/testcases/kernel/syscalls/fanotify/fanotify03.c
index 0ed0244..dfe5915 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify03.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify03.c
@@ -282,7 +282,7 @@ static void setup(void)
 	SAFE_WRITE(cleanup, 1, fd, fname, 1);
 	SAFE_CLOSE(cleanup, fd);
 
-	if ((fd_notify = myfanotify_init(FAN_CLASS_CONTENT, O_RDONLY)) < 0) {
+	if ((fd_notify = fanotify_init(FAN_CLASS_CONTENT, O_RDONLY)) < 0) {
 		if (errno == ENOSYS) {
 			tst_brkm(TCONF, cleanup,
 				 "fanotify is not configured in this kernel.");
@@ -292,13 +292,17 @@ static void setup(void)
 		}
 	}
 
-	if (myfanotify_mark(fd_notify, FAN_MARK_ADD, FAN_ACCESS_PERM |
+	if (fanotify_mark(fd_notify, FAN_MARK_ADD, FAN_ACCESS_PERM |
 			    FAN_OPEN_PERM, AT_FDCWD, fname) < 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "fanotify_mark (%d, FAN_MARK_ADD, FAN_ACCESS_PERM | "
-			 "FAN_OPEN_PERM, AT_FDCWD, %s) failed. "
-			 "CONFIG_FANOTIFY_ACCESS_PERMISSIONS not "
-			 "configured in kernel?", fd_notify, fname);
+		if (errno == EINVAL) {
+			tst_brkm(TCONF | TERRNO, cleanup,
+				 "CONFIG_FANOTIFY_ACCESS_PERMISSIONS not "
+				 "configured in kernel?");
+		} else {
+			tst_brkm(TBROK | TERRNO, cleanup,
+				 "fanotify_mark (%d, FAN_MARK_ADD, FAN_ACCESS_PERM | "
+				 "FAN_OPEN_PERM, AT_FDCWD, %s) failed.", fd_notify, fname);
+		}
 	}
 
 }
diff --git a/testcases/kernel/syscalls/fanotify/fanotify04.c b/testcases/kernel/syscalls/fanotify/fanotify04.c
index eae4812..e9ada38 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify04.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify04.c
@@ -81,7 +81,7 @@ static char *expect_str_pass(int expect)
 static void check_mark(char *file, unsigned long long flag, char *flagstr,
 		       int expect, void (*test_event)(char *))
 {
-	if (myfanotify_mark(fd_notify, FAN_MARK_ADD | flag, FAN_OPEN, AT_FDCWD,
+	if (fanotify_mark(fd_notify, FAN_MARK_ADD | flag, FAN_OPEN, AT_FDCWD,
 			    file) != expect) {
 		tst_resm(TFAIL,
 		    "fanotify_mark (%d, FAN_MARK_ADD | %s, FAN_OPEN, AT_FDCWD, "
@@ -98,7 +98,7 @@ static void check_mark(char *file, unsigned long long flag, char *flagstr,
 		if (test_event)
 			test_event(file);
 
-		if (myfanotify_mark(fd_notify, FAN_MARK_REMOVE | flag,
+		if (fanotify_mark(fd_notify, FAN_MARK_REMOVE | flag,
 				    FAN_OPEN, AT_FDCWD, file) < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
 			    "fanotify_mark (%d, FAN_MARK_REMOVE | %s, "
@@ -223,13 +223,13 @@ int main(int ac, char **av)
 		CHECK_MARK(sname, 0, 0, test_open_file);
 
 		/* Verify FAN_MARK_FLUSH destroys all inode marks */
-		if (myfanotify_mark(fd_notify, FAN_MARK_ADD,
+		if (fanotify_mark(fd_notify, FAN_MARK_ADD,
 				    FAN_OPEN, AT_FDCWD, fname) < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
 			    "fanotify_mark (%d, FAN_MARK_ADD, FAN_OPEN, "
 			    "AT_FDCWD, '%s') failed", fd_notify, fname);
 		}
-		if (myfanotify_mark(fd_notify, FAN_MARK_ADD,
+		if (fanotify_mark(fd_notify, FAN_MARK_ADD,
 				    FAN_OPEN | FAN_ONDIR, AT_FDCWD, dir) < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
 			    "fanotify_mark (%d, FAN_MARK_ADD, FAN_OPEN | "
@@ -240,7 +240,7 @@ int main(int ac, char **av)
 		verify_event(S_IFREG);
 		open_dir(dir);
 		verify_event(S_IFDIR);
-		if (myfanotify_mark(fd_notify, FAN_MARK_FLUSH,
+		if (fanotify_mark(fd_notify, FAN_MARK_FLUSH,
 				    0, AT_FDCWD, ".") < 0) {
 			tst_brkm(TBROK | TERRNO, cleanup,
 			    "fanotify_mark (%d, FAN_MARK_FLUSH, 0, "
@@ -274,7 +274,7 @@ static void setup(void)
 	sprintf(dir, "dir_%d", getpid());
 	SAFE_MKDIR(cleanup, dir, 0755);
 
-	if ((fd_notify = myfanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK,
+	if ((fd_notify = fanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK,
 					 O_RDONLY)) < 0) {
 		if (errno == ENOSYS) {
 			tst_brkm(TCONF, cleanup,
diff --git a/testcases/kernel/syscalls/fanotify/fanotify05.c b/testcases/kernel/syscalls/fanotify/fanotify05.c
index fe84512..4e64b27 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify05.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify05.c
@@ -142,7 +142,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	fd_notify = myfanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK, O_RDONLY);
+	fd_notify = fanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK, O_RDONLY);
 	if (fd_notify < 0) {
 		if (errno == ENOSYS) {
 			tst_brkm(TCONF, cleanup,
@@ -153,7 +153,7 @@ static void setup(void)
 		}
 	}
 
-	if (myfanotify_mark(fd_notify, FAN_MARK_MOUNT | FAN_MARK_ADD, FAN_OPEN,
+	if (fanotify_mark(fd_notify, FAN_MARK_MOUNT | FAN_MARK_ADD, FAN_OPEN,
 			    AT_FDCWD, ".") < 0) {
 		tst_brkm(TBROK | TERRNO, cleanup,
 			 "fanotify_mark (%d, FAN_MARK_MOUNT | FAN_MARK_ADD, "
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to