10 main(int argc
, char **argv
)
12 struct kevent event
; /* Event we want to monitor */
13 struct kevent tevent
; /* Event triggered */
17 err(EXIT_FAILURE
, "Usage: %s path\n", argv
[0]);
18 fd
= open(argv
[1], O_RDONLY
);
20 err(EXIT_FAILURE
, "Failed to open '%s'", argv
[1]);
23 kq
= kqueuex(KQUEUE_CLOEXEC
);
25 err(EXIT_FAILURE
, "kqueuex(KQUEUE_CLOEXEC) failed");
27 /* Initialize kevent structure. */
28 EV_SET(&event
, fd
, EVFILT_VNODE
, EV_ADD
| EV_CLEAR
, NOTE_WRITE
,
30 /* Attach event to the kqueue. */
31 ret
= kevent(kq
, &event
, 1, NULL
, 0, NULL
);
33 err(EXIT_FAILURE
, "kevent register");
36 /* Sleep until something happens. */
37 ret
= kevent(kq
, NULL
, 0, &tevent
, 1, NULL
);
39 err(EXIT_FAILURE
, "kevent wait");
41 if (tevent
.flags
& EV_ERROR
)
42 errx(EXIT_FAILURE
, "Event error: %s", strerror(event
.data
));
44 printf("Something was written in '%s'\n", argv
[1]);
50 /* kqueues are destroyed upon close() */