예제 #1
0
파일: fanotify04.c 프로젝트: sathnaga/ltp
static void setup(void)
{
	int fd;

	sprintf(fname, "fname_%d", getpid());
	fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0644);
	SAFE_CLOSE(fd);

	sprintf(sname, "symlink_%d", getpid());
	SAFE_SYMLINK(fname, sname);

	sprintf(dir, "dir_%d", getpid());
	SAFE_MKDIR(dir, 0755);

	fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | FAN_NONBLOCK,
			O_RDONLY);
}
예제 #2
0
파일: fanotify09.c 프로젝트: kraj/ltp
static void create_fanotify_groups(unsigned int ondir)
{
	unsigned int i, onchild;
	int ret;

	for (i = 0; i < NUM_GROUPS; i++) {
		fd_notify[i] = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF |
						  FAN_NONBLOCK,
						  O_RDONLY);

		/* Add mount mark for each group without MODIFY event */
		onchild = (i == 0) ? FAN_EVENT_ON_CHILD | ondir : 0;
		ret = fanotify_mark(fd_notify[i],
				    FAN_MARK_ADD | FAN_MARK_MOUNT,
				    FAN_CLOSE_NOWRITE | onchild,
				    AT_FDCWD, ".");
		if (ret < 0) {
			tst_brk(TBROK | TERRNO,
				"fanotify_mark(%d, FAN_MARK_ADD | "
				"FAN_MARK_MOUNT, FAN_MODIFY%s, AT_FDCWD,"
				" '.') failed", fd_notify[i],
				ondir ? " | FAN_ONDIR" : "");
		}
		/*
		 * Add inode mark on parent for each group with MODIFY
		 * event, but only one group requests events on child.
		 * The one mark with FAN_EVENT_ON_CHILD is needed for
		 * setting the DCACHE_FSNOTIFY_PARENT_WATCHED dentry
		 * flag.
		 */
		ret = fanotify_mark(fd_notify[i], FAN_MARK_ADD,
				    FAN_MODIFY | ondir | onchild,
				    AT_FDCWD, ".");
		if (ret < 0) {
			tst_brk(TBROK | TERRNO,
				"fanotify_mark(%d, FAN_MARK_ADD, "
				"FAN_MODIFY%s%s, AT_FDCWD, '.') failed",
				fd_notify[i],
				ondir ? " | FAN_ONDIR" : "",
				onchild ? " | FAN_EVENT_ON_CHILD" : "");
		}
	}
}