<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 5, 2019 at 3:22 PM Petr Vorel <<a href="mailto:pvorel@suse.cz">pvorel@suse.cz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Signed-off-by: Petr Vorel <<a href="mailto:pvorel@suse.cz" target="_blank">pvorel@suse.cz</a>><br>
---<br>
Hi,<br>
<br>
with reap_wd defined in inotify.h there could be also SAFE_MYINOTIFY_RM_WATCH().<br>
<br>
Kind regards,<br>
Petr<br>
---<br>
 testcases/kernel/syscalls/inotify/inotify.h   | 13 +++++++++++++<br>
 testcases/kernel/syscalls/inotify/inotify01.c |  9 ++-------<br>
 testcases/kernel/syscalls/inotify/inotify02.c |  9 ++-------<br>
 testcases/kernel/syscalls/inotify/inotify03.c |  7 +------<br>
 testcases/kernel/syscalls/inotify/inotify04.c | 13 ++-----------<br>
 testcases/kernel/syscalls/inotify/inotify05.c |  8 +-------<br>
 testcases/kernel/syscalls/inotify/inotify07.c |  8 ++------<br>
 testcases/kernel/syscalls/inotify/inotify08.c | 11 +++--------<br>
 testcases/kernel/syscalls/inotify/inotify09.c |  4 +---<br>
 9 files changed, 27 insertions(+), 55 deletions(-)<br>
<br>
diff --git a/testcases/kernel/syscalls/inotify/inotify.h b/testcases/kernel/syscalls/inotify/inotify.h<br>
index c82a7e75e..57669bc15 100644<br>
--- a/testcases/kernel/syscalls/inotify/inotify.h<br>
+++ b/testcases/kernel/syscalls/inotify/inotify.h<br>
@@ -50,4 +50,17 @@ static inline int safe_myinotify_init(const char *file, const int lineno, int fd<br>
 #define SAFE_MYINOTIFY_INIT1(flags) \<br>
        safe_myinotify_init(__FILE__, __LINE__, myinotify_init1(flags))<br>
<br>
+static inline int safe_myinotify_watch(const char *file, const int lineno, int wd, int fd, const char* fname, const char* mask)<br>
+{<br>
+       if (wd < 0) {<br>
+               tst_brk(TBROK | TERRNO,<br>
+                       "%s:%d: inotify_add_watch (%d, %s, %s) failed.",<br>
+                       file, lineno, fd, fname, mask);<br>
+       }<br>
+       return wd;<br>
+}<br>
+<br>
+#define SAFE_MYINOTIFY_ADD_WATCH(fd, pathname, mask)   \<br>
+       safe_myinotify_watch(__FILE__, __LINE__, myinotify_add_watch(fd, pathname, mask), fd, pathname, #mask)<br>
+<br>
 #endif /* _INOTIFY_H */<br>
diff --git a/testcases/kernel/syscalls/inotify/inotify01.c b/testcases/kernel/syscalls/inotify/inotify01.c<br>
index f08a75dcf..eee98b4fa 100644<br>
--- a/testcases/kernel/syscalls/inotify/inotify01.c<br>
+++ b/testcases/kernel/syscalls/inotify/inotify01.c<br>
@@ -169,13 +169,8 @@ static void setup(void)<br>
<br>
        fd_notify = SAFE_MYINOTIFY_INIT();<br>
<br>
-       if ((wd = myinotify_add_watch(fd_notify, fname, IN_ALL_EVENTS)) < 0) {<br>
-               tst_brk(TBROK | TERRNO,<br>
-                       "inotify_add_watch (%d, %s, IN_ALL_EVENTS) failed",<br>
-                       fd_notify, fname);<br>
-               reap_wd = 1;<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">If test exit with TBROK the reap_wd will never get a chance to set as 1, and the cleanup() also make no sense in tst_brk() calling.</div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
-       };</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
-<br>
+       wd = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, fname, IN_ALL_EVENTS);<br>
+       reap_wd = 1;<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">Even wrap into safe macro the problem is still there, the 'reap_wd = 1;' make no sense to the whole test.</div><div class="gmail_default" style="font-size:small"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
 }<br>
<br>
 static void cleanup(void)<br>
diff --git a/testcases/kernel/syscalls/inotify/inotify02.c b/testcases/kernel/syscalls/inotify/inotify02.c<br>
index ca70b4e9e..21e7fb3e8 100644<br>
--- a/testcases/kernel/syscalls/inotify/inotify02.c<br>
+++ b/testcases/kernel/syscalls/inotify/inotify02.c<br>
@@ -236,12 +236,8 @@ static void setup(void)<br>
 {<br>
        fd_notify = SAFE_MYINOTIFY_INIT();<br>
<br>
-       if ((wd = myinotify_add_watch(fd_notify, ".", IN_ALL_EVENTS)) < 0) {<br>
-               tst_brk(TBROK | TERRNO,<br>
-                        "inotify_add_watch (%d, \".\", IN_ALL_EVENTS) failed",<br>
-                        fd_notify);<br>
-               reap_wd = 1;</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
-       };<br>
+       wd = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, ".", IN_ALL_EVENTS);<br>
+       reap_wd = 1;</blockquote><div><br></div><div class="gmail_default" style="font-size:small">here as well.</div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
 }<br>
<br>
 static void cleanup(void)<br>
@@ -249,7 +245,6 @@ static void cleanup(void)<br>
        if (reap_wd && myinotify_rm_watch(fd_notify, wd) < 0) {<br>
                tst_res(TWARN,<br>
                        "inotify_rm_watch (%d, %d) failed,", fd_notify, wd);<br>
-<br>
        }<br>
<br>
        if (fd_notify > 0)<br>
diff --git a/testcases/kernel/syscalls/inotify/inotify03.c b/testcases/kernel/syscalls/inotify/inotify03.c<br>
index 772623125..7363df01b 100644<br>
--- a/testcases/kernel/syscalls/inotify/inotify03.c<br>
+++ b/testcases/kernel/syscalls/inotify/inotify03.c<br>
@@ -77,12 +77,7 @@ void verify_inotify(void)<br>
        SAFE_MOUNT(tst_device->dev, mntpoint, tst_device->fs_type, 0, NULL);<br>
        mount_flag = 1;<br>
<br>
-       wd = myinotify_add_watch(fd_notify, fname, IN_ALL_EVENTS);<br>
-       if (wd < 0) {<br>
-               tst_brk(TBROK | TERRNO,<br>
-                       "inotify_add_watch (%d, %s, IN_ALL_EVENTS) failed.",<br>
-                       fd_notify, fname);<br>
-       }<br>
+       wd = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, fname, IN_ALL_EVENTS);<br>
<br>
        event_set[test_cnt] = IN_UNMOUNT;<br>
        test_cnt++;<br>
diff --git a/testcases/kernel/syscalls/inotify/inotify04.c b/testcases/kernel/syscalls/inotify/inotify04.c<br>
index 6adb41701..2cc20fb61 100644<br>
--- a/testcases/kernel/syscalls/inotify/inotify04.c<br>
+++ b/testcases/kernel/syscalls/inotify/inotify04.c<br>
@@ -106,19 +106,10 @@ void verify_inotify(void)<br>
        SAFE_MKDIR(TEST_DIR, 00700);<br>
        close(SAFE_CREAT(TEST_FILE, 00600));<br>
<br>
-       wd_dir = myinotify_add_watch(fd_notify, TEST_DIR, IN_ALL_EVENTS);<br>
-       if (wd_dir == -1) {<br>
-               tst_brk(TBROK | TERRNO,<br>
-                       "inotify_add_watch(%d, \"%s\", IN_ALL_EVENTS) [1] failed",<br>
-                       fd_notify, TEST_DIR);<br>
-       }<br>
+       wd_dir = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, TEST_DIR, IN_ALL_EVENTS);<br>
        reap_wd_dir = 1;<br>
<br>
-       wd_file = myinotify_add_watch(fd_notify, TEST_FILE, IN_ALL_EVENTS);<br>
-       if (wd_file == -1)<br>
-               tst_brk(TBROK | TERRNO,<br>
-                       "inotify_add_watch(%d, \"%s\", IN_ALL_EVENTS) [2] failed",<br>
-                       fd_notify, TEST_FILE);<br>
+       wd_file = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, TEST_FILE, IN_ALL_EVENTS);<br>
        reap_wd_file = 1;<br>
<br>
        SAFE_RMDIR(TEST_DIR);<br>
diff --git a/testcases/kernel/syscalls/inotify/inotify05.c b/testcases/kernel/syscalls/inotify/inotify05.c<br>
index b5813b25b..fa45d09bf 100644<br>
--- a/testcases/kernel/syscalls/inotify/inotify05.c<br>
+++ b/testcases/kernel/syscalls/inotify/inotify05.c<br>
@@ -145,12 +145,7 @@ static void setup(void)<br>
<br>
        fd_notify = SAFE_MYINOTIFY_INIT1(O_NONBLOCK);<br>
<br>
-       wd = myinotify_add_watch(fd_notify, fname, IN_ALL_EVENTS);<br>
-       if (wd < 0) {<br>
-               tst_brk(TBROK | TERRNO,<br>
-                       "inotify_add_watch (%d, %s, IN_ALL_EVENTS) failed",<br>
-                       fd_notify, fname);<br>
-       };<br>
+       wd = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, fname, IN_ALL_EVENTS);<br>
<br>
        SAFE_FILE_SCANF("/proc/sys/fs/inotify/max_queued_events",<br>
                        "%d", &max_events);<br>
@@ -161,7 +156,6 @@ static void cleanup(void)<br>
        if (fd_notify > 0 && myinotify_rm_watch(fd_notify, wd) == -1) {<br>
                tst_res(TWARN | TERRNO, "inotify_rm_watch (%d, %d) failed",<br>
                        fd_notify, wd);<br>
-<br>
        }<br>
<br>
        if (fd_notify > 0)<br>
diff --git a/testcases/kernel/syscalls/inotify/inotify07.c b/testcases/kernel/syscalls/inotify/inotify07.c<br>
index 1111b43bf..7099e8dbf 100644<br>
--- a/testcases/kernel/syscalls/inotify/inotify07.c<br>
+++ b/testcases/kernel/syscalls/inotify/inotify07.c<br>
@@ -168,12 +168,8 @@ static void setup(void)<br>
        fd_notify = SAFE_MYINOTIFY_INIT1(O_NONBLOCK);<br>
<br>
        /* Setup a watch on an overlayfs lower directory */<br>
-       if ((wd = myinotify_add_watch(fd_notify, DIR_PATH, IN_ALL_EVENTS)) < 0) {<br>
-               tst_brk(TBROK | TERRNO,<br>
-                       "inotify_add_watch (%d, " DIR_PATH ", IN_ALL_EVENTS) failed",<br>
-                       fd_notify);<br>
-               reap_wd = 1;<br>
-       };<br>
+       wd = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, DIR_PATH, IN_ALL_EVENTS);<br>
+       reap_wd = 1;<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">here as well.</div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
        SAFE_STAT(DIR_PATH, &buf);<br>
        tst_res(TINFO, DIR_PATH " ino=%lu", buf.st_ino);<br>
diff --git a/testcases/kernel/syscalls/inotify/inotify08.c b/testcases/kernel/syscalls/inotify/inotify08.c<br>
index ee8e44fe1..73fdf497f 100644<br>
--- a/testcases/kernel/syscalls/inotify/inotify08.c<br>
+++ b/testcases/kernel/syscalls/inotify/inotify08.c<br>
@@ -160,14 +160,9 @@ static void setup(void)<br>
        fd_notify = SAFE_MYINOTIFY_INIT1(O_NONBLOCK);<br>
<br>
        /* Setup a watch on an overlayfs lower file */<br>
-       if ((wd = myinotify_add_watch(fd_notify, FILE_PATH,<br>
-                               IN_ATTRIB | IN_OPEN | IN_CLOSE_WRITE)) < 0) {<br>
-               tst_brk(TBROK | TERRNO,<br>
-                       "inotify_add_watch (%d, " FILE_PATH ", "<br>
-                       "IN_ATTRIB | IN_OPEN | IN_CLOSE_WRITE) failed",<br>
-                       fd_notify);<br>
-               reap_wd = 1;<br>
-       };<br>
+       wd = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, FILE_PATH,<br>
+                               IN_ATTRIB | IN_OPEN | IN_CLOSE_WRITE);<br>
+       reap_wd = 1;<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">and here.</div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
        SAFE_STAT(FILE_PATH, &buf);<br>
        tst_res(TINFO, FILE_PATH " ino=%lu, dev=%u:%u", buf.st_ino,<br>
diff --git a/testcases/kernel/syscalls/inotify/inotify09.c b/testcases/kernel/syscalls/inotify/inotify09.c<br>
index cf2d38f27..e6fed7d9d 100644<br>
--- a/testcases/kernel/syscalls/inotify/inotify09.c<br>
+++ b/testcases/kernel/syscalls/inotify/inotify09.c<br>
@@ -89,9 +89,7 @@ static void verify_inotify(void)<br>
<br>
        tst_fzsync_pair_reset(&fzsync_pair, write_seek);<br>
        while (tst_fzsync_run_a(&fzsync_pair)) {<br>
-               wd = myinotify_add_watch(inotify_fd, FNAME, IN_MODIFY);<br>
-               if (wd < 0)<br>
-                       tst_brk(TBROK | TERRNO, "inotify_add_watch() failed.");<br>
+               wd = SAFE_MYINOTIFY_ADD_WATCH(inotify_fd, FNAME, IN_MODIFY);<br>
<br>
                tst_fzsync_start_race_a(&fzsync_pair);<br>
                wd = myinotify_rm_watch(inotify_fd, wd);<br>
-- <br>
2.21.0<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>