tools/testing/selftests/cgroup/wait_inotify.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/cgroup/wait_inotify.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/cgroup/wait_inotify.c
Extension
.c
Size
1643 bytes
Lines
88
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

switch (c) {
		case 'v':
			verbose++;
			break;
		}
		argv++, argc--;
	}

	if (argc != 2) {
		fprintf(stderr, usage, cmd);
		return -1;
	}
	file = argv[1];
	fd = open(file, O_RDONLY);
	if (fd < 0)
		fail_message("Cgroup file %s not found!\n");
	close(fd);

	fd = inotify_init();
	if (fd < 0)
		fail_message("inotify_init() fails on %s!\n");
	if (inotify_add_watch(fd, file, IN_MODIFY) < 0)
		fail_message("inotify_add_watch() fails on %s!\n");
	fds.fd = fd;

	/*
	 * poll waiting loop
	 */
	for (;;) {
		int ret = poll(&fds, 1, 10000);

		if (ret < 0) {
			if (errno == EINTR)
				continue;
			perror("poll");
			exit(1);
		}
		if ((ret > 0) && (fds.revents & POLLIN))
			break;
	}
	if (verbose) {
		struct inotify_event events[10];
		long len;

		usleep(1000);
		len = read(fd, events, sizeof(events));
		printf("Number of events read = %ld\n",
			len/sizeof(struct inotify_event));
	}
	close(fd);
	return 0;
}

Annotation

Implementation Notes