View | Details | Raw Unified | Return to bug 196844 | Differences between
and this patch

Collapse All | Expand All

(-)lib/libc/sys/kqueue.2 (+58 lines)
Lines 525-530 Link Here
525
If the time limit expires, then
525
If the time limit expires, then
526
.Fn kevent
526
.Fn kevent
527
returns 0.
527
returns 0.
528
.Sh EXAMPLES
529
.Bd -literal -compact
530
#include <sys/types.h>
531
#include <sys/event.h>
532
#include <sys/time.h>
533
#include <fcntl.h>
534
#include <stdio.h>
535
#include <stdlib.h>
536
#include <string.h>
537
#include <unistd.h>
538
539
int
540
main(int argc, char **argv)
541
{
542
543
	struct kevent event;	/* Event we want to monitor */
544
	struct kevent tevent;	/* Event triggered */
545
	int kq, fd, ret;
546
547
	if (argc != 2) {
548
		printf("Usage: %s dir\n", argv[0]);
549
		exit(EXIT_SUCCESS);
550
	}
551
552
	if ((fd = open(argv[1], O_RDONLY)) == -1) {
553
		perror("open");
554
		exit(EXIT_FAILURE);
555
	}
556
557
	/* Create kqueue */
558
	if ((kq = kqueue()) == -1) {
559
		perror("queue");
560
		exit(EXIT_FAILURE);
561
	}
562
563
	/* Initialize kevent structure */
564
	EV_SET(&event, fd, EVFILT_VNODE , EV_ADD | EV_ONESHOT, NOTE_WRITE, 0, NULL);
565
	
566
	for (;;) {
567
		/* Attach event to the kqueue and block until something happens */
568
		ret = kevent(kq, &event, 1, &tevent, 1, NULL);
569
		if (ret == -1) {
570
			perror("kevent");
571
			exit(EXIT_FAILURE);
572
		} else if (ret > 0) {
573
			if (event.flags & EV_ERROR) {
574
				fprintf(stderr, "Event error: %s\n", strerror(event.data));
575
			}
576
			printf("Something was written in '%s'\n", argv[1]);
577
		}
578
	}
579
580
	/* NOTREACHED */
581
	close(fd);
582
	exit(EXIT_SUCCESS);
583
584
}
585
.Ed
528
.Sh ERRORS
586
.Sh ERRORS
529
The
587
The
530
.Fn kqueue
588
.Fn kqueue

Return to bug 196844