static void cleanup(void) { if (reap_wd_dir && myinotify_rm_watch(fd_notify, wd_dir) == -1) tst_resm(TWARN, "inotify_rm_watch(%d, %d) [1] failed", fd_notify, wd_dir); if (reap_wd_file && myinotify_rm_watch(fd_notify, wd_file) == -1) tst_resm(TWARN, "inotify_rm_watch(%d, %d) [2] failed", fd_notify, wd_file); if (close(fd_notify) == -1) tst_resm(TWARN, "close(%d) [1] failed", fd_notify); if (close(wd_dir) == -1) tst_resm(TWARN, "close(%d) [2] failed", wd_dir); if (close(wd_file) == -1) tst_resm(TWARN, "close(%d) [3] failed", wd_file); TEST_CLEANUP; tst_rmdir(); }
/* * cleanup() - performs all ONE TIME cleanup for this test at * completion or premature exit. */ void cleanup() { if (myinotify_rm_watch(fd_notify, wd) < 0) { tst_resm(TWARN, "inotify_rm_watch (%d, %d) Failed," "errno=%d : %s", fd_notify, wd, errno, strerror(errno)); } if (close(fd_notify) == -1) { tst_resm(TWARN, "close(%d) Failed, errno=%d : %s", fd_notify, errno, strerror(errno)); } /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; /* Remove tmp dir and all files in it */ tst_rmdir(); /* exit with return code appropriate for results */ tst_exit(); } /* End cleanup() */
static void cleanup(void) { if (fd_notify > 0 && myinotify_rm_watch(fd_notify, wd) == -1) { tst_resm(TWARN | TERRNO, "inotify_rm_watch (%d, %d) failed", fd_notify, wd); } if (fd_notify > 0 && close(fd_notify) == -1) tst_resm(TWARN, "close(%d) failed", fd_notify); tst_rmdir(); }
static void cleanup(void) { if (reap_wd && myinotify_rm_watch(fd_notify, wd) < 0) { tst_resm(TWARN, "inotify_rm_watch (%d, %d) failed,", fd_notify, wd); } if (fd_notify > 0 && close(fd_notify)) tst_resm(TWARN, "close(%d) failed", fd_notify); tst_rmdir(); }
static void cleanup(void) { if (myinotify_rm_watch(fd_notify, wd) < 0) { tst_resm(TWARN | TERRNO, "inotify_rm_watch (%d, %d) failed", fd_notify, wd); } if (close(fd_notify) == -1) { tst_resm(TWARN, "close(%d) failed", fd_notify); } TEST_CLEANUP; tst_rmdir(); }
/* * cleanup() - performs all ONE TIME cleanup for this test at * completion or premature exit. */ void cleanup() { if (myinotify_rm_watch(fd_notify, wd) < 0) { tst_resm(TWARN, "inotify_rm_watch (%d, %d) failed,", fd_notify, wd); } if (close(fd_notify) == -1) { tst_resm(TWARN, "close(%d) failed", fd_notify); } /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; tst_rmdir(); }
int main(int argc, char *argv[]) { const char *msg; int ret; int len, i, test_num; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); tst_count = 0; event_set[tst_count] = IN_UNMOUNT; tst_count++; event_set[tst_count] = IN_IGNORED; tst_count++; /*check exit code from inotify_rm_watch */ tst_count++; if (TST_TOTAL != tst_count) { tst_brkm(TBROK, cleanup, "TST_TOTAL and tst_count are not equal"); } tst_count = 0; tst_resm(TINFO, "umount %s", device); TEST(umount(mntpoint)); if (TEST_RETURN != 0) { TEST_ERROR_LOG(TEST_ERRNO); tst_brkm(TBROK, cleanup, "umount(2) Failed " "while unmounting errno = %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } mount_flag = 0; len = read(fd_notify, event_buf, EVENT_BUF_LEN); if (len < 0) { tst_brkm(TBROK | TERRNO, cleanup, "read(%d, buf, %zu) failed", fd_notify, EVENT_BUF_LEN); } /* check events */ test_num = 0; i = 0; while (i < len) { struct inotify_event *event; event = (struct inotify_event *)&event_buf[i]; if (test_num >= (TST_TOTAL - 1)) { tst_resm(TFAIL, "get unnecessary event: wd=%d mask=%x " "cookie=%u len=%u", event->wd, event->mask, event->cookie, event->len); } else if (event_set[test_num] == event->mask) { tst_resm(TPASS, "get event: wd=%d mask=%x" " cookie=%u len=%u", event->wd, event->mask, event->cookie, event->len); } else { tst_resm(TFAIL, "get event: wd=%d mask=%x " "(expected %x) cookie=%u len=%u", event->wd, event->mask, event_set[test_num], event->cookie, event->len); } test_num++; i += EVENT_SIZE + event->len; } for (; test_num < TST_TOTAL - 1; test_num++) { tst_resm(TFAIL, "don't get event: mask=%x ", event_set[test_num]); } ret = myinotify_rm_watch(fd_notify, wd); if (ret != -1 || errno != EINVAL) tst_resm(TFAIL | TERRNO, "inotify_rm_watch (%d, %d) didn't return EINVAL", fd_notify, wd); else tst_resm(TPASS, "inotify_rm_watch (%d, %d) returned EINVAL", fd_notify, wd); cleanup(); tst_exit(); }
void verify_inotify(void) { int ret; int len, i, test_num; int test_cnt = 0; SAFE_MOUNT(tst_device->dev, mntpoint, tst_device->fs_type, 0, NULL); mount_flag = 1; wd = myinotify_add_watch(fd_notify, fname, IN_ALL_EVENTS); if (wd < 0) { tst_brk(TBROK | TERRNO, "inotify_add_watch (%d, %s, IN_ALL_EVENTS) failed.", fd_notify, fname); } event_set[test_cnt] = IN_UNMOUNT; test_cnt++; event_set[test_cnt] = IN_IGNORED; test_cnt++; /*check exit code from inotify_rm_watch */ test_cnt++; tst_res(TINFO, "umount %s", tst_device->dev); TEST(tst_umount(mntpoint)); if (TEST_RETURN != 0) { tst_brk(TBROK, "umount(2) Failed " "while unmounting errno = %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } mount_flag = 0; len = read(fd_notify, event_buf, EVENT_BUF_LEN); if (len < 0) { tst_brk(TBROK | TERRNO, "read(%d, buf, %zu) failed", fd_notify, EVENT_BUF_LEN); } /* check events */ test_num = 0; i = 0; while (i < len) { struct inotify_event *event; event = (struct inotify_event *)&event_buf[i]; if (test_num >= (test_cnt - 1)) { tst_res(TFAIL, "get unnecessary event: wd=%d mask=%x " "cookie=%u len=%u", event->wd, event->mask, event->cookie, event->len); } else if (event_set[test_num] == event->mask) { tst_res(TPASS, "get event: wd=%d mask=%x" " cookie=%u len=%u", event->wd, event->mask, event->cookie, event->len); } else { tst_res(TFAIL, "get event: wd=%d mask=%x " "(expected %x) cookie=%u len=%u", event->wd, event->mask, event_set[test_num], event->cookie, event->len); } test_num++; i += EVENT_SIZE + event->len; } for (; test_num < test_cnt - 1; test_num++) { tst_res(TFAIL, "don't get event: mask=%x ", event_set[test_num]); } ret = myinotify_rm_watch(fd_notify, wd); if (ret != -1 || errno != EINVAL) tst_res(TFAIL | TERRNO, "inotify_rm_watch (%d, %d) didn't return EINVAL", fd_notify, wd); else tst_res(TPASS, "inotify_rm_watch (%d, %d) returned EINVAL", fd_notify, wd); }