4 # Copyright (c) 2008 Peter Holm <pho@FreeBSD.org>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Test EVFILT_VNODE. Found page fault in knlist_add+0x39
32 # Test scenario by kib@
39 sed '1,/^EOF/d' < $odir/$0 > kevent.c
40 cc -o kevent -Wall kevent.c
50 #include <sys/types.h>
53 #include <sys/event.h>
64 static char *file1, *file2;
76 if ((fd = open(file1, O_RDONLY, 0)) == -1)
77 err(1, "open(%s)(2)", file1);
79 if ((kq = kqueue()) < 0)
83 EV_SET(&ev[n], fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
87 if (kevent(kq, ev, n, NULL, 0, NULL) < 0)
90 memset(&ev, 0, sizeof(ev));
91 n = kevent(kq, NULL, 0, ev, 1, NULL);
92 // printf("Event 1\n");
96 /* Once the rendezvous file is gone create a new kevent */
98 if ((fd = open(file2, O_RDONLY, 0)) == -1)
99 err(1, "open(%s)(2)", file2);
101 if ((kq = kqueue()) < 0)
105 EV_SET(&ev[n], fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
109 if (kevent(kq, ev, n, NULL, 0, NULL) < 0)
112 memset(&ev, 0, sizeof(ev));
113 n = kevent(kq, NULL, 0, ev, 1, NULL);
114 // printf("Event 2\n");
120 main(int argc, char **argv) {
126 fprintf(stderr, "Usage: %s <rendezvous file> <tail file>\n", argv[0]);
132 for (j = 0; j < 100; j++) {
133 if ((fd = open(file1, O_CREAT | O_TRUNC | O_RDWR, 0660)) == -1)
134 err(1, "open(%s)", file1);
136 if ((fd = open(file2, O_CREAT | O_TRUNC | O_RDWR, 0660)) == -1)
137 err(1, "open(%s)", file2);
140 for (i = 0; i < N; i++) {
148 if (unlink(file1) == -1)
149 err(1, "unlink(%s). %s:%d\n", file1, __FILE__, __LINE__);
151 if (unlink(file2) == -1)
152 err(1, "unlink(%s). %s:%d\n", file2, __FILE__, __LINE__);
154 for (i = 0; i < N; i++) {
155 if (wait(&status) == -1)
156 err(1, "wait(), %s:%d", __FILE__, __LINE__);