Skip to content

Commit

Permalink
syscalls/fanotify03: Simplify test
Browse files Browse the repository at this point in the history
Re-init fanotify fd on every test iteration instead of storing and
restoring fd_notify from duplicated fd_notify_backup.

Signed-off-by: Amir Goldstein <[email protected]>
Acked-by: Jan Kara <[email protected]>
Acked-by: Cyril Hrubis <[email protected]>
  • Loading branch information
amir73il authored and metan-ucw committed Nov 5, 2018
1 parent 9dcbc6d commit ed71747
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions testcases/kernel/syscalls/fanotify/fanotify03.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,33 @@ static void check_child(void)
tst_res(TFAIL, "child %s", tst_strstatus(child_ret));
}

void test01(void)
static void setup_mark(void)
{
int tst_count, fd_notify_backup = -1;
fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_CONTENT, O_RDONLY);

if (fanotify_mark(fd_notify, FAN_MARK_ADD,
FAN_ACCESS_PERM | FAN_OPEN_PERM,
AT_FDCWD, fname) < 0) {
if (errno == EINVAL) {
tst_brk(TCONF | TERRNO,
"CONFIG_FANOTIFY_ACCESS_PERMISSIONS not "
"configured in kernel?");
} else {
tst_brk(TBROK | TERRNO,
"fanotify_mark (%d, FAN_MARK_ADD, "
"FAN_ACCESS_PERM | FAN_OPEN_PERM, "
"AT_FDCWD, %s) failed.",
fd_notify, fname);
}
}
}

void test01(void)
{
int tst_count;
int ret, len = 0, i = 0, test_num = 0;

if (fd_notify_backup == -1) {
fd_notify_backup = SAFE_DUP(fd_notify);
}
setup_mark();
run_child();

tst_count = 0;
Expand Down Expand Up @@ -229,33 +247,15 @@ void test01(void)

}
check_child();
/* We got SIGCHLD while running, resetup fd_notify */
if (fd_notify == -1) {
fd_notify = fd_notify_backup;
fd_notify_backup = -1;
}

if (fd_notify > 0)
SAFE_CLOSE(fd_notify);
}

static void setup(void)
{
sprintf(fname, "fname_%d", getpid());
SAFE_FILE_PRINTF(fname, "1");

fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_CONTENT, O_RDONLY);

if (fanotify_mark(fd_notify, FAN_MARK_ADD, FAN_ACCESS_PERM |
FAN_OPEN_PERM, AT_FDCWD, fname) < 0) {
if (errno == EINVAL) {
tst_brk(TCONF | TERRNO,
"CONFIG_FANOTIFY_ACCESS_PERMISSIONS not "
"configured in kernel?");
} else {
tst_brk(TBROK | TERRNO,
"fanotify_mark (%d, FAN_MARK_ADD, FAN_ACCESS_PERM | "
"FAN_OPEN_PERM, AT_FDCWD, %s) failed.", fd_notify, fname);
}
}

}

static void cleanup(void)
Expand Down

0 comments on commit ed71747

Please sign in to comment.